public static String perConnectionProxyAuthorizationHeader(Request request, Realm proxyRealm) { String proxyAuthorization = null; if (proxyRealm != null && proxyRealm.isUsePreemptiveAuth()) { switch (proxyRealm.getScheme()) { case NTLM: case KERBEROS: case SPNEGO: List<String> auth = request.getHeaders().getAll(PROXY_AUTHORIZATION); if (getHeaderWithPrefix(auth, "NTLM") == null) { String msg = NtlmEngine.INSTANCE.generateType1Msg(); proxyAuthorization = "NTLM " + msg; } break; default: } } return proxyAuthorization; }
@Test public void testClone() { Realm orig = basicAuthRealm("user", "pass").setCharset(UTF_16) .setUsePreemptiveAuth(true) .setRealmName("realm") .setAlgorithm("algo").build(); Realm clone = realm(orig).build(); assertEquals(clone.getPrincipal(), orig.getPrincipal()); assertEquals(clone.getPassword(), orig.getPassword()); assertEquals(clone.getCharset(), orig.getCharset()); assertEquals(clone.isUsePreemptiveAuth(), orig.isUsePreemptiveAuth()); assertEquals(clone.getRealmName(), orig.getRealmName()); assertEquals(clone.getAlgorithm(), orig.getAlgorithm()); assertEquals(clone.getScheme(), orig.getScheme()); }
if (realm != null && realm.isUsePreemptiveAuth()) {
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; }
requestFactory.setProxyAuthorizationHeader(headers, perConnectionProxyAuthorizationHeader(request, proxyRealm)); future.setInAuth(realm != null && realm.isUsePreemptiveAuth() && realm.getScheme() != AuthScheme.NTLM); future.setInProxyAuth( proxyRealm != null && proxyRealm.isUsePreemptiveAuth() && proxyRealm.getScheme() != AuthScheme.NTLM);
public static String perConnectionAuthorizationHeader(Request request, ProxyServer proxyServer, Realm realm) { String authorizationHeader = null; if (realm != null && realm.isUsePreemptiveAuth()) { switch (realm.getScheme()) { case NTLM:
if (realm.isUsePreemptiveAuth()) {
if (proxyRealm.isUsePreemptiveAuth()) {
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()); }