@Override public Queue<AuthOption> select(final Map<String, Header> challengeHeaders, final HttpHost authhost, final HttpResponse response, final HttpContext context) { final HttpClientContext httpClientContext = HttpClientContext.adapt(context); final AuthState state = httpClientContext.getTargetAuthState(); final Queue<AuthOption> queue = new ArrayDeque<>(); if (state == null || !state.getState().equals(AuthProtocolState.CHALLENGED)) { queue.add(authOption); } else { System.out.println("does this happen?"); } return queue; }
CloseableHttpClient httpclient = HttpClients.createDefault(); try { HttpClientContext localContext = HttpClientContext.create(); HttpGet httpget = new HttpGet("http://localhost/"); CloseableHttpResponse response = httpclient.execute(httpget, localContext); try { System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); AuthState targetAuthState = localContext.getTargetAuthState(); if (targetAuthState.getAuthScheme() != null) { System.out.println("Target auth scheme: " + targetAuthState.getAuthScheme().getSchemeName()); } AuthState proxyAuthState = localContext.getProxyAuthState(); if (proxyAuthState.getAuthScheme() != null) { System.out.println("Proxy auth scheme: " + proxyAuthState.getAuthScheme().getSchemeName()); } } finally { response.close(); } } finally { httpclient.close(); }
@Override public void process(final HttpRequest request, final HttpContext context) throws IOException { if (context instanceof HttpClientContext) { final HttpClientContext clientContext = (HttpClientContext)context; final AuthState authState = clientContext.getTargetAuthState(); final CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); final HttpHost targetHost = clientContext.getTargetHost(); // If not authentication scheme has been initialized yet if (authState.getAuthScheme() == null) { final AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); // Obtain credentials matching the target host final Credentials creds = credsProvider.getCredentials(authScope); // If found, generate BasicScheme preemptively if (creds != null) { authState.update(new BasicScheme(), creds); } } } else { throw new IllegalArgumentException("Not sure how to handle a non-HttpClientContext context."); } }
/** * Determines if the given HTTP response response represents * an authentication challenge that was sent back as a result * of authentication failure. * * @param authHost authentication host. * @param response HTTP response. * @param context HTTP context. * @return {@code true} if user authentication is required, * {@code false} otherwise. */ @Override public boolean isAuthenticationRequested(final HttpHost authHost, final HttpResponse response, final HttpContext context) { final StatusLine line = response.getStatusLine(); final int code = line.getStatusCode(); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthState authState = clientContext.getTargetAuthState(); final AuthProtocolState authProtocolState = authState.getState(); if (code == HttpStatus.SC_UNAUTHORIZED) { if (authProtocolState.equals(AuthProtocolState.CHALLENGED)) { clientContext.getTargetAuthState().setState(AuthProtocolState.FAILURE); authFailed(authHost, authState.getAuthScheme(), context); } return true; } return clientContext.getTargetAuthState() == null; }
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { HttpClientContext clientContext = HttpClientContext.adapt(context); AuthState authState = clientContext.getTargetAuthState(); if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); HttpHost targetHost = clientContext.getTargetHost(); Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds != null) { authState.update(new BasicScheme(), creds); } } } }
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { HttpClientContext clientContext = HttpClientContext.adapt(context); AuthState authState = clientContext.getTargetAuthState(); if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); HttpHost targetHost = clientContext.getTargetHost(); Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds != null) { authState.update(new BasicScheme(), creds); } } } }
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { HttpClientContext clientContext = HttpClientContext.adapt(context); AuthState authState = clientContext.getTargetAuthState(); // If there's no auth scheme available yet, try to initialize it preemptively if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); HttpHost targetHost = clientContext.getTargetHost(); Credentials creds = credsProvider.getCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds != null) { authState.update(new BasicScheme(), creds); } } } }
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { HttpClientContext clientContext = HttpClientContext.adapt(context); AuthState authState = clientContext.getTargetAuthState(); // If there's no auth scheme available yet, try to initialize it preemptively if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); HttpHost targetHost = clientContext.getTargetHost(); Credentials creds = credsProvider.getCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds != null) { authState.update(new BasicScheme(), creds); } } } }
final AuthStateHC4 targetState = clientContext.getTargetAuthState(); if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(target);
final AuthState targetState = clientContext.getTargetAuthState(); if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(target);
final AuthState targetState = clientContext.getTargetAuthState(); if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(target);
final AuthState targetState = clientContext.getTargetAuthState(); if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(target);
final AuthState targetState = clientContext.getTargetAuthState(); if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(target);
@Override public Object getUserToken(final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); Principal userPrincipal = null; final AuthState targetAuthState = clientContext.getTargetAuthState(); if (targetAuthState != null) { userPrincipal = getAuthPrincipal(targetAuthState); if (userPrincipal == null) { final AuthState proxyAuthState = clientContext.getProxyAuthState(); userPrincipal = getAuthPrincipal(proxyAuthState); } } if (userPrincipal == null) { final HttpConnection conn = clientContext.getConnection(); if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) { final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession(); if (sslsession != null) { userPrincipal = sslsession.getLocalPrincipal(); } } } return userPrincipal; }
@Override public Object getUserToken(final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); Principal userPrincipal = null; final AuthState targetAuthState = clientContext.getTargetAuthState(); if (targetAuthState != null) { userPrincipal = getAuthPrincipal(targetAuthState); if (userPrincipal == null) { final AuthState proxyAuthState = clientContext.getProxyAuthState(); userPrincipal = getAuthPrincipal(proxyAuthState); } } if (userPrincipal == null) { final HttpConnection conn = clientContext.getConnection(); if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) { final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession(); if (sslsession != null) { userPrincipal = sslsession.getLocalPrincipal(); } } } return userPrincipal; }
public Object getUserToken(final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); Principal userPrincipal = null; final AuthStateHC4 targetAuthState = clientContext.getTargetAuthState(); if (targetAuthState != null) { userPrincipal = getAuthPrincipal(targetAuthState); if (userPrincipal == null) { final AuthStateHC4 proxyAuthState = clientContext.getProxyAuthState(); userPrincipal = getAuthPrincipal(proxyAuthState); } } if (userPrincipal == null) { final HttpConnection conn = clientContext.getConnection(); if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) { final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession(); if (sslsession != null) { userPrincipal = sslsession.getLocalPrincipal(); } } } return userPrincipal; }
@Override public Object getUserToken(final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); Principal userPrincipal = null; final AuthState targetAuthState = clientContext.getTargetAuthState(); if (targetAuthState != null) { userPrincipal = getAuthPrincipal(targetAuthState); if (userPrincipal == null) { final AuthState proxyAuthState = clientContext.getProxyAuthState(); userPrincipal = getAuthPrincipal(proxyAuthState); } } if (userPrincipal == null) { final HttpConnection conn = clientContext.getConnection(); if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) { final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession(); if (sslsession != null) { userPrincipal = sslsession.getLocalPrincipal(); } } } return userPrincipal; }
public Object getUserToken(final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); Principal userPrincipal = null; final AuthState targetAuthState = clientContext.getTargetAuthState(); if (targetAuthState != null) { userPrincipal = getAuthPrincipal(targetAuthState); if (userPrincipal == null) { final AuthState proxyAuthState = clientContext.getProxyAuthState(); userPrincipal = getAuthPrincipal(proxyAuthState); } } if (userPrincipal == null) { final HttpConnection conn = clientContext.getConnection(); if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) { final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession(); if (sslsession != null) { userPrincipal = sslsession.getLocalPrincipal(); } } } return userPrincipal; }
@Override public Object getUserToken(final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); Principal userPrincipal = null; final AuthState targetAuthState = clientContext.getTargetAuthState(); if (targetAuthState != null) { userPrincipal = getAuthPrincipal(targetAuthState); if (userPrincipal == null) { final AuthState proxyAuthState = clientContext.getProxyAuthState(); userPrincipal = getAuthPrincipal(proxyAuthState); } } if (userPrincipal == null) { final HttpConnection conn = clientContext.getConnection(); if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) { final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession(); if (sslsession != null) { userPrincipal = sslsession.getLocalPrincipal(); } } } return userPrincipal; }
@Override public Object getUserToken(final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); Principal userPrincipal = null; final AuthState targetAuthState = clientContext.getTargetAuthState(); if (targetAuthState != null) { userPrincipal = getAuthPrincipal(targetAuthState); if (userPrincipal == null) { final AuthState proxyAuthState = clientContext.getProxyAuthState(); userPrincipal = getAuthPrincipal(proxyAuthState); } } if (userPrincipal == null) { final HttpConnection conn = clientContext.getConnection(); if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) { final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession(); if (sslsession != null) { userPrincipal = sslsession.getLocalPrincipal(); } } } return userPrincipal; }