Search in sources :

Example 1 with CredentialsStore

use of org.apache.hc.client5.http.auth.CredentialsStore in project geo-platform by geosdi.

the class AbstractSecurityConnector method bindCredentials.

/**
 * Bind Credentials for {@link CredentialsStore} class
 *
 * @param credentialsStore
 * @param targetURI
 */
protected void bindCredentials(@Nonnull(when = NEVER) CredentialsStore credentialsStore, @Nonnull(when = NEVER) URI targetURI) {
    checkArgument(credentialsStore != null, "The Parameter credentialsProvider must not be null.");
    checkArgument(targetURI != null, "The Parameter targetURI must not be null.");
    if (this.authScope == null) {
        this.authScope = new AuthScope(targetURI.getHost(), targetURI.getPort());
    }
    credentialsStore.setCredentials(authScope, this.usernamePasswordCredentials);
}
Also used : AuthScope(org.apache.hc.client5.http.auth.AuthScope)

Example 2 with CredentialsStore

use of org.apache.hc.client5.http.auth.CredentialsStore in project gradle-download-task by michel-kraemer.

the class DownloadAction method addAuthentication.

/**
 * Add authentication information for the given host
 * @param host the host
 * @param credentials the credentials
 * @param context the context in which the authentication information
 * should be saved
 */
private void addAuthentication(HttpHost host, Credentials credentials, HttpClientContext context) {
    AuthCache authCache = context.getAuthCache();
    if (authCache == null) {
        authCache = new BasicAuthCache();
        context.setAuthCache(authCache);
    }
    CredentialsProvider credsProvider = context.getCredentialsProvider();
    if (credsProvider == null) {
        credsProvider = new BasicCredentialsProvider();
        context.setCredentialsProvider(credsProvider);
    }
    ((CredentialsStore) credsProvider).setCredentials(new AuthScope(host), credentials);
}
Also used : BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) AuthCache(org.apache.hc.client5.http.auth.AuthCache) BasicAuthCache(org.apache.hc.client5.http.impl.auth.BasicAuthCache) CredentialsStore(org.apache.hc.client5.http.auth.CredentialsStore) AuthScope(org.apache.hc.client5.http.auth.AuthScope) BasicAuthCache(org.apache.hc.client5.http.impl.auth.BasicAuthCache) BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) CredentialsProvider(org.apache.hc.client5.http.auth.CredentialsProvider)

Example 3 with CredentialsStore

use of org.apache.hc.client5.http.auth.CredentialsStore in project wildfly-clustering-spring-session by wildfly-clustering.

the class AuthSmokeITCase method createClient.

private static CloseableHttpClient createClient(URL url1, URL url2) {
    CredentialsStore provider = new BasicCredentialsProvider();
    Credentials credentials = new UsernamePasswordCredentials("admin", "password".toCharArray());
    provider.setCredentials(new AuthScope(url1.getHost(), url1.getPort()), credentials);
    provider.setCredentials(new AuthScope(url2.getHost(), url2.getPort()), credentials);
    return HttpClients.custom().setDefaultCredentialsProvider(provider).build();
}
Also used : BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) CredentialsStore(org.apache.hc.client5.http.auth.CredentialsStore) AuthScope(org.apache.hc.client5.http.auth.AuthScope) Credentials(org.apache.hc.client5.http.auth.Credentials) UsernamePasswordCredentials(org.apache.hc.client5.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.hc.client5.http.auth.UsernamePasswordCredentials)

Example 4 with CredentialsStore

use of org.apache.hc.client5.http.auth.CredentialsStore in project wildfly-clustering-spring-session by wildfly-clustering.

the class AuthSmokeITCase method createClient.

private static CloseableHttpClient createClient(URL url1, URL url2) {
    CredentialsStore provider = new BasicCredentialsProvider();
    Credentials credentials = new UsernamePasswordCredentials("admin", "password".toCharArray());
    provider.setCredentials(new AuthScope(url1.getHost(), url1.getPort()), credentials);
    provider.setCredentials(new AuthScope(url2.getHost(), url2.getPort()), credentials);
    return HttpClients.custom().setDefaultCredentialsProvider(provider).build();
}
Also used : BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) CredentialsStore(org.apache.hc.client5.http.auth.CredentialsStore) AuthScope(org.apache.hc.client5.http.auth.AuthScope) Credentials(org.apache.hc.client5.http.auth.Credentials) UsernamePasswordCredentials(org.apache.hc.client5.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.hc.client5.http.auth.UsernamePasswordCredentials)

Aggregations

AuthScope (org.apache.hc.client5.http.auth.AuthScope)4 CredentialsStore (org.apache.hc.client5.http.auth.CredentialsStore)3 BasicCredentialsProvider (org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider)3 Credentials (org.apache.hc.client5.http.auth.Credentials)2 UsernamePasswordCredentials (org.apache.hc.client5.http.auth.UsernamePasswordCredentials)2 AuthCache (org.apache.hc.client5.http.auth.AuthCache)1 CredentialsProvider (org.apache.hc.client5.http.auth.CredentialsProvider)1 BasicAuthCache (org.apache.hc.client5.http.impl.auth.BasicAuthCache)1