C
Cameron McCormack
Hi.
I'm trying to work out what URLConnection.setAllowUserInteraction()
actually does. I thought it would have affected whether an
Authenticator would be used to get a username/password if one was
required, but that doesn't seem to be the case.
The test I used was the following:
import java.net.*;
public class AuthTest {
public static void main(String[] args) {
try {
Auth a = new Auth();
Authenticator.setDefault(a);
URL u = new URL("http://mcc.id.au/temp/pw/something");
HttpURLConnection c =
(HttpURLConnection) u.openConnection();
c.setAllowUserInteraction(false);
System.out.println(c.getResponseCode());
} catch (Exception e) {
e.printStackTrace();
}
}
private static class Auth extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
System.out.println("getPasswordAuthentication() called");
return null;
}
}
}
The URL used is one that requires authentication. Even though I called
setAllowUserInteraction(false), my Authentictor is still called.
Is setAllowUserInteraction() actually the way I should be influencing
whether my Authenticator is called? Or is there another way?
Thanks,
Cameron
I'm trying to work out what URLConnection.setAllowUserInteraction()
actually does. I thought it would have affected whether an
Authenticator would be used to get a username/password if one was
required, but that doesn't seem to be the case.
The test I used was the following:
import java.net.*;
public class AuthTest {
public static void main(String[] args) {
try {
Auth a = new Auth();
Authenticator.setDefault(a);
URL u = new URL("http://mcc.id.au/temp/pw/something");
HttpURLConnection c =
(HttpURLConnection) u.openConnection();
c.setAllowUserInteraction(false);
System.out.println(c.getResponseCode());
} catch (Exception e) {
e.printStackTrace();
}
}
private static class Auth extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
System.out.println("getPasswordAuthentication() called");
return null;
}
}
}
The URL used is one that requires authentication. Even though I called
setAllowUserInteraction(false), my Authentictor is still called.
Is setAllowUserInteraction() actually the way I should be influencing
whether my Authenticator is called? Or is there another way?
Thanks,
Cameron