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);
}
Aggregations