Search in sources :

Example 1 with AuthOption

use of org.apache.http.auth.AuthOption in project iaf by ibissource.

the class OAuthPreferringAuthenticationStrategy method select.

// private boolean refreshTokenOn401; // retrying unchallenged request/responses might cause endless authentication loops
@Override
public Queue<AuthOption> select(Map<String, Header> challenges, HttpHost authhost, HttpResponse response, HttpContext context) throws MalformedChallengeException {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }
    final AuthScope authScope = new AuthScope(authhost, "", OAuthAuthenticationScheme.SCHEME_NAME);
    final Credentials credentials = credsProvider.getCredentials(authScope);
    if (credentials != null) {
        // always add OAuth as an authentication option, if any challenges are returned by server
        options.add(new AuthOption(new OAuthAuthenticationScheme(), credentials));
    }
    options.addAll(super.select(challenges, authhost, response, clientContext));
    return options;
}
Also used : AuthOption(org.apache.http.auth.AuthOption) AuthScope(org.apache.http.auth.AuthScope) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) CredentialsProvider(org.apache.http.client.CredentialsProvider) LinkedList(java.util.LinkedList) Credentials(org.apache.http.auth.Credentials)

Aggregations

LinkedList (java.util.LinkedList)1 AuthOption (org.apache.http.auth.AuthOption)1 AuthScope (org.apache.http.auth.AuthScope)1 Credentials (org.apache.http.auth.Credentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)1