.setMethodName(request.getMethod()) .setUsePreemptiveAuth(true) .parseWWWAuthenticateHeader(digestHeader)
.setMethodName(request.getMethod()) .setUsePreemptiveAuth(true) .parseProxyAuthenticateHeader(digestHeader)
.setMethodName(request.getMethod()) .build(); authorizationHeader = computeDigestAuthentication(realm);
public static String perRequestProxyAuthorizationHeader(Request request, Realm proxyRealm) { String proxyAuthorization = null; if (proxyRealm != null && proxyRealm.isUsePreemptiveAuth()) { switch (proxyRealm.getScheme()) { case BASIC: proxyAuthorization = computeBasicAuthentication(proxyRealm); break; case DIGEST: if (isNonEmpty(proxyRealm.getNonce())) { // update realm with request information proxyRealm = realm(proxyRealm) .setUri(request.getUri()) .setMethodName(request.getMethod()) .build(); proxyAuthorization = computeDigestAuthentication(proxyRealm); } break; case NTLM: case KERBEROS: case SPNEGO: // NTLM, KERBEROS and SPNEGO are only set on the first request with a connection, // see perConnectionProxyAuthorizationHeader break; default: throw new IllegalStateException("Invalid Authentication scheme " + proxyRealm.getScheme()); } } return proxyAuthorization; }
@Test public void testStrongDigest() throws Exception { String user = "user"; String pass = "pass"; String realm = "realm"; String nonce = "nonce"; String method = "GET"; Uri uri = Uri.create("http://ahc.io/foo"); String qop = "auth"; Realm orig = digestAuthRealm(user, pass) .setNonce(nonce) .setUri(uri) .setMethodName(method) .setRealmName(realm) .setQop(qop) .build(); String nc = orig.getNc(); String cnonce = orig.getCnonce(); String ha1 = getMd5(user + ":" + realm + ":" + pass); String ha2 = getMd5(method + ":" + uri.getPath()); String expectedResponse = getMd5(ha1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + ha2); assertEquals(orig.getResponse(), expectedResponse); }
private void testOldDigest(String qop) throws Exception { String user = "user"; String pass = "pass"; String realm = "realm"; String nonce = "nonce"; String method = "GET"; Uri uri = Uri.create("http://ahc.io/foo"); Realm orig = digestAuthRealm(user, pass) .setNonce(nonce) .setUri(uri) .setMethodName(method) .setRealmName(realm) .setQop(qop) .build(); String ha1 = getMd5(user + ":" + realm + ":" + pass); String ha2 = getMd5(method + ":" + uri.getPath()); String expectedResponse = getMd5(ha1 + ":" + nonce + ":" + ha2); assertEquals(orig.getResponse(), expectedResponse); }