.setUri(request.getUri()) .setMethodName(request.getMethod()) .setUsePreemptiveAuth(true)
.setUri(request.getUri()) .setMethodName(request.getMethod()) .setUsePreemptiveAuth(true)
.setUri(request.getUri()) .setMethodName(request.getMethod()) .build();
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); }
public static Realm.Builder realm(Realm prototype) { return new Realm.Builder(prototype.getPrincipal(), prototype.getPassword()) .setRealmName(prototype.getRealmName()) .setAlgorithm(prototype.getAlgorithm()) .setNc(prototype.getNc()) .setNonce(prototype.getNonce()) .setCharset(prototype.getCharset()) .setOpaque(prototype.getOpaque()) .setQop(prototype.getQop()) .setScheme(prototype.getScheme()) .setUri(prototype.getUri()) .setUsePreemptiveAuth(prototype.isUsePreemptiveAuth()) .setNtlmDomain(prototype.getNtlmDomain()) .setNtlmHost(prototype.getNtlmHost()) .setUseAbsoluteURI(prototype.isUseAbsoluteURI()) .setOmitQuery(prototype.isOmitQuery()) .setServicePrincipalName(prototype.getServicePrincipalName()) .setUseCanonicalHostname(prototype.isUseCanonicalHostname()) .setCustomLoginConfig(prototype.getCustomLoginConfig()) .setLoginContextName(prototype.getLoginContextName()); }
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); }