I'm trying to use digest authentication with 3.0rc3 against an IIS 6.0 on
Windows 2003 sp1 server.
IIS responds with a 401 Unauthorized. It works fine with 3.0rc1 or 2.0.2
code:
URL url = null;
try {
url = new URL("http://85.19.64.181/fasadeTest/fasade.aspx");
}
catch (MalformedURLException e) {
e.printStackTrace();
}
HttpClient httpClient = new HttpClient();
List authPrefs = new ArrayList(1);
authPrefs.add(AuthPolicy.DIGEST);
httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
authPrefs);
final String brukernavn = "fasade";
final String passord = "Omb1234";
Credentials credentials = new UsernamePasswordCredentials(brukernavn,
passord);
AuthScope authScope = new AuthScope(url.getHost(), url.getPort());
httpClient.getState().setCredentials(authScope, credentials);
GetMethod getMethod = new GetMethod(url.toExternalForm());
getMethod.setDoAuthentication(true);
try {
int result = httpClient.executeMethod(getMethod);
if (result != 200) {
System.out.println("En feil har oppstått under
dokumentbehandling: " + result + getMethod.getStatusText());
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
getMethod.releaseConnection();
}
wire trace:
2005/08/23 12:38:55:736 CEST [DEBUG] HttpClient - -Java version: 1.4.2_05
2005/08/23 12:38:55:736 CEST [DEBUG] HttpClient - -Java vendor: Sun
Microsystems Inc.
2005/08/23 12:38:55:736 CEST [DEBUG] HttpClient - -Java class path:
C:\commons-codec-1.2\commons-codec-1.2.jar;C:\workspace\Front-2.5.0-b2.4.1\lib\commons-logging.jar;C:\commons-httpclient-3.0-rc3\commons-httpclient-3.0-rc3.jar;C:\workspace\Front-2.5.0-b2.4.1\classes
2005/08/23 12:38:55:736 CEST [DEBUG] HttpClient - -Operating system name:
Windows 2000
2005/08/23 12:38:55:736 CEST [DEBUG] HttpClient - -Operating system
architecture: x86
2005/08/23 12:38:55:736 CEST [DEBUG] HttpClient - -Operating system version: 5.0
2005/08/23 12:38:55:861 CEST [DEBUG] HttpClient - -SUN 1.42: SUN (DSA
key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom; X.509
certificates; JKS keystore; PKIX CertPathValidator; PKIX CertPathBuilder; LDAP,
Collection CertStores)
2005/08/23 12:38:55:861 CEST [DEBUG] HttpClient - -SunJSSE 1.42: Sun JSSE
provider(implements RSA Signatures, PKCS12, SunX509 key/trust factories, SSLv3,
TLSv1)
2005/08/23 12:38:55:861 CEST [DEBUG] HttpClient - -SunRsaSign 1.42: SUN's
provider for RSA signatures
2005/08/23 12:38:55:861 CEST [DEBUG] HttpClient - -SunJCE 1.42: SunJCE Provider
(implements DES, Triple DES, AES, Blowfish, PBE, Diffie-Hellman, HMAC-MD5,
HMAC-SHA1)
2005/08/23 12:38:55:861 CEST [DEBUG] HttpClient - -SunJGSS 1.0: Sun (Kerberos
v5)
2005/08/23 12:38:55:861 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.useragent = Jakarta Commons-HttpClient/3.0-rc3
2005/08/23 12:38:55:876 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.protocol.version = HTTP/1.1
2005/08/23 12:38:55:876 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.connection-manager.class = class
org.apache.commons.httpclient.SimpleHttpConnectionManager
2005/08/23 12:38:55:876 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.protocol.cookie-policy = rfc2109
2005/08/23 12:38:55:876 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.protocol.element-charset = US-ASCII
2005/08/23 12:38:55:876 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.protocol.content-charset = ISO-8859-1
2005/08/23 12:38:55:876 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.method.retry-handler = [EMAIL PROTECTED]
2005/08/23 12:38:55:876 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.dateparser.patterns = [EEE, dd MMM yyyy HH:mm:ss zzz, EEEE, dd-MMM-yy
HH:mm:ss zzz, EEE MMM d HH:mm:ss yyyy, EEE, dd-MMM-yyyy HH:mm:ss z, EEE,
dd-MMM-yyyy HH-mm-ss z, EEE, dd MMM yy HH:mm:ss z, EEE dd-MMM-yyyy HH:mm:ss z,
EEE dd MMM yyyy HH:mm:ss z, EEE dd-MMM-yyyy HH-mm-ss z, EEE dd-MMM-yy HH:mm:ss
z, EEE dd MMM yy HH:mm:ss z, EEE,dd-MMM-yy HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss
z, EEE, dd-MM-yyyy HH:mm:ss z]
2005/08/23 12:38:55:876 CEST [DEBUG] DefaultHttpParams - -Set parameter
http.auth.scheme-priority = [Digest]
2005/08/23 12:38:55:939 CEST [DEBUG] HttpConnection - -Open connection to
85.19.64.181:80
2005/08/23 12:38:55:970 CEST [DEBUG] header - ->> "GET /fasadeTest/fasade.aspx
HTTP/1.1[\r][\n]"
2005/08/23 12:38:55:970 CEST [DEBUG] HttpMethodBase - -Adding Host request
header
2005/08/23 12:38:55:986 CEST [DEBUG] header - ->> "User-Agent: Jakarta
Commons-HttpClient/3.0-rc3[\r][\n]"
2005/08/23 12:38:55:986 CEST [DEBUG] header - ->> "Host: 85.19.64.181[\r][\n]"
2005/08/23 12:38:55:986 CEST [DEBUG] header - ->> "[\r][\n]"
2005/08/23 12:38:56:001 CEST [DEBUG] header - -<< "HTTP/1.1 401
Unauthorized[\r][\n]"
2005/08/23 12:38:56:001 CEST [DEBUG] header - -<< "Content-Length: 1656[\r][\n]"
2005/08/23 12:38:56:001 CEST [DEBUG] header - -<< "Content-Type:
text/html[\r][\n]"
2005/08/23 12:38:56:001 CEST [DEBUG] header - -<< "Server:
Microsoft-IIS/6.0[\r][\n]"
2005/08/23 12:38:56:001 CEST [DEBUG] header - -<< "WWW-Authenticate: Digest
qop="auth",algorithm=MD5-sess,nonce="ff3426aecea7c501db21346e1183eb3211f56694b71ba62722b7a6c841a4f6fd3e4d4c4b4f29963e",charset=utf-8,realm="stonabs01.local"[\r][\n]"
2005/08/23 12:38:56:001 CEST [DEBUG] header - -<< "X-Powered-By:
ASP.NET[\r][\n]"
2005/08/23 12:38:56:001 CEST [DEBUG] header - -<< "Date: Tue, 23 Aug 2005
10:37:37 GMT[\r][\n]"
2005/08/23 12:38:56:017 CEST [DEBUG] HttpMethodDirector - -Authorization
required
2005/08/23 12:38:56:017 CEST [DEBUG] AuthChallengeProcessor - -Supported
authentication schemes in the order of preference: [Digest]
2005/08/23 12:38:56:017 CEST [INFO] AuthChallengeProcessor - -Digest
authentication scheme selected
2005/08/23 12:38:56:017 CEST [DEBUG] AuthChallengeProcessor - -Using
authentication scheme: digest
2005/08/23 12:38:56:033 CEST [DEBUG] AuthChallengeProcessor - -Authorization
challenge processed
2005/08/23 12:38:56:033 CEST [DEBUG] HttpMethodDirector - -Authentication
scope: DIGEST 'stonabs01.local'@85.19.64.181:80
2005/08/23 12:38:56:033 CEST [DEBUG] HttpMethodDirector - -Retry authentication
2005/08/23 12:38:56:033 CEST [DEBUG] HttpMethodBase - -Resorting to protocol
version default close connection policy
2005/08/23 12:38:56:033 CEST [DEBUG] HttpMethodBase - -Should NOT close
connection, using HTTP/1.1
2005/08/23 12:38:56:033 CEST [DEBUG] HttpConnection - -Connection is locked.
Call to releaseConnection() ignored.
2005/08/23 12:38:56:033 CEST [DEBUG] HttpMethodDirector - -Authenticating with
DIGEST 'stonabs01.local'@85.19.64.181:80
2005/08/23 12:38:56:048 CEST [DEBUG] DigestScheme - -Using qop method auth
2005/08/23 12:38:56:064 CEST [DEBUG] header - ->> "GET /fasadeTest/fasade.aspx
HTTP/1.1[\r][\n]"
2005/08/23 12:38:56:064 CEST [DEBUG] HttpMethodBase - -Adding Host request
header
2005/08/23 12:38:56:064 CEST [DEBUG] header - ->> "User-Agent: Jakarta
Commons-HttpClient/3.0-rc3[\r][\n]"
2005/08/23 12:38:56:064 CEST [DEBUG] header - ->> "Authorization: Digest
username="fasade", realm="stonabs01.local",
nonce="ff3426aecea7c501db21346e1183eb3211f56694b71ba62722b7a6c841a4f6fd3e4d4c4b4f29963e",
uri="/fasadeTest/fasade.aspx", response="205bec5a96e994943a16e6b52d3a6bf8",
qop="auth", nc="00000001", cnonce="1c59d158f79183d3b84c2b8bbeea6d8a",
algorithm="MD5-sess"[\r][\n]"
2005/08/23 12:38:56:064 CEST [DEBUG] header - ->> "Host: 85.19.64.181[\r][\n]"
2005/08/23 12:38:56:064 CEST [DEBUG] header - ->> "[\r][\n]"
2005/08/23 12:38:56:080 CEST [DEBUG] header - -<< "HTTP/1.1 401
Unauthorized[\r][\n]"
2005/08/23 12:38:56:080 CEST [DEBUG] header - -<< "Content-Length: 1539[\r][\n]"
2005/08/23 12:38:56:080 CEST [DEBUG] header - -<< "Content-Type:
text/html[\r][\n]"
2005/08/23 12:38:56:080 CEST [DEBUG] header - -<< "Server:
Microsoft-IIS/6.0[\r][\n]"
2005/08/23 12:38:56:095 CEST [DEBUG] header - -<< "WWW-Authenticate: Digest
qop="auth",algorithm=MD5-sess,nonce="a38234aecea7c5016432e63e67459189008baeaf9adf7b7a193642ede695fa7feaa81619eac56da5",charset=utf-8,realm="stonabs01.local"[\r][\n]"
2005/08/23 12:38:56:095 CEST [DEBUG] header - -<< "X-Powered-By:
ASP.NET[\r][\n]"
2005/08/23 12:38:56:095 CEST [DEBUG] header - -<< "Date: Tue, 23 Aug 2005
10:37:37 GMT[\r][\n]"
2005/08/23 12:38:56:095 CEST [DEBUG] HttpMethodDirector - -Authorization
required
2005/08/23 12:38:56:095 CEST [DEBUG] AuthChallengeProcessor - -Using
authentication scheme: digest
2005/08/23 12:38:56:095 CEST [DEBUG] AuthChallengeProcessor - -Authorization
challenge processed
2005/08/23 12:38:56:095 CEST [DEBUG] HttpMethodDirector - -Authentication
scope: DIGEST 'stonabs01.local'@85.19.64.181:80
2005/08/23 12:38:56:095 CEST [DEBUG] HttpMethodDirector - -Credentials required
2005/08/23 12:38:56:095 CEST [DEBUG] HttpMethodDirector - -Credentials provider
not available
2005/08/23 12:38:56:095 CEST [INFO] HttpMethodDirector - -Failure
authenticating with DIGEST 'stonabs01.local'@85.19.64.181:80
En feil har oppstått under dokumentbehandling: 401Unauthorized
2005/08/23 12:38:56:095 CEST [DEBUG] HttpMethodBase - -Resorting to protocol
version default close connection policy
2005/08/23 12:38:56:095 CEST [DEBUG] HttpMethodBase - -Should NOT close
connection, using HTTP/1.1
2005/08/23 12:38:56:095 CEST [DEBUG] HttpConnection - -Releasing connection
back to connection manager.