use of org.apache.http.auth.AuthSchemeProvider in project wildfly by wildfly.
the class SAML2AttributeMappingTestCase method testPassUserPrincipalToAttributeManager.
/**
* Tests IDP attribute mapping when passUserPrincipalToAttributeManager is set to "true". Automatic handling of redirections
* is enabled for HTTP client used.
*
* @throws Exception
*/
@Test
public void testPassUserPrincipalToAttributeManager() throws Exception {
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new JBossNegotiateSchemeFactory(true)).build();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(null, -1, null), new NullHCCredentials());
try (final CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultAuthSchemeRegistry(authSchemeRegistry).setDefaultCredentialsProvider(credentialsProvider).setRedirectStrategy(Utils.REDIRECT_STRATEGY).build()) {
String response = PicketLinkTestBase.makeCallWithKerberosAuthn(spUrl.toURI(), httpClient, "jduke", "theduke", 200);
assertEquals("SP index page was not reached", SP_RESPONSE_BODY, response);
response = PicketLinkTestBase.makeCall(new URL(spUrl.toString() + PrintAttributeServlet.SERVLET_PATH.substring(1)), httpClient, 200);
assertEquals("cn attribute not stored", "Java Duke", response);
}
}
use of org.apache.http.auth.AuthSchemeProvider in project stdlib by petergeneric.
the class ResteasyClientFactoryImpl method createHttpClientCustomiser.
/**
* N.B. This method signature may change in the future to add new parameters
*
* @param fastFail
* @param authScope
* @param credentials
* @param preemptiveAuth
* @param storeCookies
* @param customiser
*
* @return
*/
public Consumer<HttpClientBuilder> createHttpClientCustomiser(final boolean fastFail, final AuthScope authScope, final Credentials credentials, final boolean preemptiveAuth, final boolean storeCookies, Consumer<HttpClientBuilder> customiser) {
// Customise timeouts if fast fail mode is enabled
if (fastFail) {
customiser = concat(customiser, b -> {
RequestConfig.Builder requestBuilder = RequestConfig.custom();
requestBuilder.setConnectTimeout((int) fastFailConnectionTimeout.getMilliseconds()).setSocketTimeout((int) fastFailSocketTimeout.getMilliseconds());
b.setDefaultRequestConfig(requestBuilder.build());
});
}
// If credentials were supplied then we should set them up
if (credentials != null) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (authScope != null)
credentialsProvider.setCredentials(authScope, credentials);
else
credentialsProvider.setCredentials(AuthScope.ANY, credentials);
// Set up bearer auth scheme provider if we're using bearer credentials
if (credentials instanceof BearerCredentials) {
customiser = concat(customiser, b -> {
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register("Bearer", new BearerAuthSchemeProvider()).build();
b.setDefaultAuthSchemeRegistry(authSchemeRegistry);
});
}
// Set up the credentials customisation
customiser = concat(customiser, b -> b.setDefaultCredentialsProvider(credentialsProvider));
if (preemptiveAuth && credentials instanceof BearerCredentials)
customiser = concat(customiser, b -> b.addInterceptorFirst(new PreemptiveBearerAuthInterceptor()));
else
customiser = concat(customiser, b -> b.addInterceptorLast(new PreemptiveBasicAuthInterceptor()));
}
// If cookies are enabled then set up a cookie store
if (storeCookies)
customiser = concat(customiser, b -> b.setDefaultCookieStore(new BasicCookieStore()));
return customiser;
}
use of org.apache.http.auth.AuthSchemeProvider in project epp.mpc by eclipse.
the class WinClientBuilderCustomizer method customizeBuilder.
public HttpClientBuilder customizeBuilder(HttpClientBuilder builder) {
if (!isWinAuthAvailable()) {
return builder;
}
HttpClientBuilder winBuilder = builder == null ? HttpClientBuilder.create() : builder;
Registry<AuthSchemeProvider> authSchemeRegistry = createAuthSchemeRegistry();
return winBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
}
use of org.apache.http.auth.AuthSchemeProvider in project hbase by apache.
the class TestSecureRESTServer method getClient.
private Pair<CloseableHttpClient, HttpClientContext> getClient() {
HttpClientConnectionManager pool = new PoolingHttpClientConnectionManager();
HttpHost host = new HttpHost("localhost", REST_TEST.getServletPort());
Registry<AuthSchemeProvider> authRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)).build();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, EmptyCredentials.INSTANCE);
AuthCache authCache = new BasicAuthCache();
CloseableHttpClient client = HttpClients.custom().setDefaultAuthSchemeRegistry(authRegistry).setConnectionManager(pool).build();
HttpClientContext context = HttpClientContext.create();
context.setTargetHost(host);
context.setCredentialsProvider(credentialsProvider);
context.setAuthSchemeRegistry(authRegistry);
context.setAuthCache(authCache);
return new Pair<>(client, context);
}
use of org.apache.http.auth.AuthSchemeProvider in project zm-mailbox by Zimbra.
the class ExchangeFreeBusyProvider method basicAuth.
private boolean basicAuth(HttpClientBuilder clientBuilder, ServerInfo info) {
Credentials cred = new UsernamePasswordCredentials(info.authUsername, info.authPassword);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, cred);
clientBuilder.setDefaultCredentialsProvider(credsProvider);
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.BASIC, new BasicSchemeFactory(Consts.UTF_8)).build();
clientBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
return true;
}
Aggregations