Howto disable HTTP integrated windows authentication
Hello,
I've tried to use URL/HTTPURLConnection on Windows 2003 with java5, and for my suprise it performs integrated windows authentication!
This is neat! I wanted it so many times in the past, but for this specific project I need to forward my own credentials...
How can I disable the integrated authentication, so that I may specify my own credentials?
The authenticator is not event called if integrated windows authentication is set on the IIS side.
If I leave only Basic authentication it works as expected, and as it used to work with older JVMs... :)
But I must allow users to login to IIS using integrate windows authentication...
So how can I instruct the JVM to always use the authenticator?
Best Regards,
Alon Bar-Lev.
Code:
public static class MyAuthenticator extends java.net.Authenticator {
String user;
String password;
MyAuthenticator (String user, String password) {
this.user = user;
this.password = password;
}
protected java.net.PasswordAuthentication getPasswordAuthentication () {
return new java.net.PasswordAuthentication (user, password.toCharArray ());
}
}
public
static
byte[]
getBytesToEndOfStream (
java.io.InputStream is
) throws java.io.IOException {
final int chunkSize = 2048; byte[] buf = new byte[chunkSize];int count;
java.io.ByteArrayOutputStream byteStream = new java.io.ByteArrayOutputStream (chunkSize);
while ((count=is.read (buf)) != -1) {
byteStream.write (buf, 0, count);
}
return byteStream.toByteArray ();
}
public static java.lang.String do (
String strURL,
String user,
String password
) throws
java.net.MalformedURLException,
java.io.IOException
{
if (user != null) java.net.Authenticator.setDefault (new MyAuthenticator (user, password));
java.net.URL url = new java.net.URL (strURL);
return new String (getBytesToEndOfStream (url.openConnection ().getInputStream ()));
}

