Search in sources :

Example 1 with AuthenticationScheme

use of nl.nn.adapterframework.http.authentication.AuthenticationScheme in project iaf by ibissource.

the class HttpSenderBase method setupAuthentication.

private void setupAuthentication(CredentialFactory user_cf, CredentialFactory proxyCredentials, HttpHost proxy, Builder requestConfigBuilder) {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    if (StringUtils.isNotEmpty(user_cf.getUsername()) || StringUtils.isNotEmpty(getTokenEndpoint())) {
        credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), getCredentials());
        AuthenticationScheme preferredAuthenticationScheme = getPreferredAuthenticationScheme();
        requestConfigBuilder.setTargetPreferredAuthSchemes(Arrays.asList(preferredAuthenticationScheme.getSchemeName()));
        requestConfigBuilder.setAuthenticationEnabled(true);
        if (preferredAuthenticationScheme == AuthenticationScheme.OAUTH) {
            CredentialFactory client_cf = new CredentialFactory(getClientAuthAlias(), getClientId(), getClientSecret());
            OAuthAccessTokenManager accessTokenManager = new OAuthAccessTokenManager(getTokenEndpoint(), getScope(), client_cf, StringUtils.isEmpty(user_cf.getUsername()), this, getTokenExpiry());
            httpClientContext.setAttribute(OAuthAuthenticationScheme.ACCESSTOKEN_MANAGER_KEY, accessTokenManager);
            httpClientBuilder.setTargetAuthenticationStrategy(new OAuthPreferringAuthenticationStrategy());
        }
    }
    if (proxy != null) {
        AuthScope scope = new AuthScope(proxy, proxyRealm, AuthScope.ANY_SCHEME);
        if (StringUtils.isNotEmpty(proxyCredentials.getUsername())) {
            Credentials credentials = new UsernamePasswordCredentials(proxyCredentials.getUsername(), proxyCredentials.getPassword());
            credentialsProvider.setCredentials(scope, credentials);
        }
        if (prefillProxyAuthCache()) {
            requestConfigBuilder.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC));
            AuthCache authCache = httpClientContext.getAuthCache();
            if (authCache == null)
                authCache = new BasicAuthCache();
            authCache.put(proxy, new BasicScheme());
            httpClientContext.setAuthCache(authCache);
        }
    }
    httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
Also used : AuthenticationScheme(nl.nn.adapterframework.http.authentication.AuthenticationScheme) OAuthAuthenticationScheme(nl.nn.adapterframework.http.authentication.OAuthAuthenticationScheme) BasicScheme(org.apache.http.impl.auth.BasicScheme) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) OAuthPreferringAuthenticationStrategy(nl.nn.adapterframework.http.authentication.OAuthPreferringAuthenticationStrategy) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) AuthScope(org.apache.http.auth.AuthScope) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) OAuthAccessTokenManager(nl.nn.adapterframework.http.authentication.OAuthAccessTokenManager) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

AuthenticationScheme (nl.nn.adapterframework.http.authentication.AuthenticationScheme)1 OAuthAccessTokenManager (nl.nn.adapterframework.http.authentication.OAuthAccessTokenManager)1 OAuthAuthenticationScheme (nl.nn.adapterframework.http.authentication.OAuthAuthenticationScheme)1 OAuthPreferringAuthenticationStrategy (nl.nn.adapterframework.http.authentication.OAuthPreferringAuthenticationStrategy)1 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)1 AuthScope (org.apache.http.auth.AuthScope)1 Credentials (org.apache.http.auth.Credentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 AuthCache (org.apache.http.client.AuthCache)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 BasicScheme (org.apache.http.impl.auth.BasicScheme)1 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1