use of nl.nn.adapterframework.http.authentication.OAuthAccessTokenManager in project iaf by ibissource.
the class OAuthAccessTokenManagerTest method testRetrieveAccessTokenNoScope.
@Test
public void testRetrieveAccessTokenNoScope() throws Exception {
String tokenEndpoint = TOKENENDPOINT;
String scope = null;
String clientId = clientClientId;
String clientSecret = clientClientSecret;
CredentialFactory client_cf = new CredentialFactory(null, clientId, clientSecret);
OAuthAccessTokenManager accessTokenManager = new OAuthAccessTokenManager(tokenEndpoint, scope, client_cf, true, httpSender);
String accessToken = accessTokenManager.getAccessToken(null);
assertThat(accessToken, startsWith("Bearer"));
}
use of nl.nn.adapterframework.http.authentication.OAuthAccessTokenManager in project iaf by ibissource.
the class OAuthAccessTokenManagerTest method testRetrieveAccessTokenWrongCredentials.
@Test
public void testRetrieveAccessTokenWrongCredentials() throws Exception {
String tokenEndpoint = TOKENENDPOINT;
String scope = "email";
String clientId = clientClientId;
String clientSecret = "xxx";
CredentialFactory client_cf = new CredentialFactory(null, clientId, clientSecret);
OAuthAccessTokenManager accessTokenManager = new OAuthAccessTokenManager(tokenEndpoint, scope, client_cf, true, httpSender);
HttpAuthenticationException exception = assertThrows(HttpAuthenticationException.class, () -> accessTokenManager.getAccessToken(null));
assertThat(exception.getMessage(), containsString("unauthorized_client"));
}
use of nl.nn.adapterframework.http.authentication.OAuthAccessTokenManager in project iaf by ibissource.
the class OAuthAccessTokenManagerTest method testRetrieveAccessTokenWrongTokenEndpoint.
@Test
public void testRetrieveAccessTokenWrongTokenEndpoint() throws Exception {
String tokenEndpoint = TOKENENDPOINT + "x";
String scope = "email";
String clientId = clientClientId;
String clientSecret = clientClientSecret;
CredentialFactory client_cf = new CredentialFactory(null, clientId, clientSecret);
OAuthAccessTokenManager accessTokenManager = new OAuthAccessTokenManager(tokenEndpoint, scope, client_cf, true, httpSender);
HttpAuthenticationException exception = assertThrows(HttpAuthenticationException.class, () -> accessTokenManager.getAccessToken(null));
assertThat(exception.getMessage(), containsString("404"));
}
use of nl.nn.adapterframework.http.authentication.OAuthAccessTokenManager 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);
}
use of nl.nn.adapterframework.http.authentication.OAuthAccessTokenManager in project iaf by ibissource.
the class OAuthAccessTokenManagerTest method testRetrieveAccessToken.
@Test
public void testRetrieveAccessToken() throws Exception {
String tokenEndpoint = TOKENENDPOINT;
String scope = "email";
String clientId = clientClientId;
String clientSecret = clientClientSecret;
CredentialFactory client_cf = new CredentialFactory(null, clientId, clientSecret);
OAuthAccessTokenManager accessTokenManager = new OAuthAccessTokenManager(tokenEndpoint, scope, client_cf, true, httpSender);
String accessToken = accessTokenManager.getAccessToken(null);
assertThat(accessToken, startsWith("Bearer"));
}
Aggregations