Example usage for org.apache.http.auth AuthScope AuthScope

List of usage examples for org.apache.http.auth AuthScope AuthScope

Introduction

In this page you can find the example usage for org.apache.http.auth AuthScope AuthScope.

Prototype

public AuthScope(final String host, final int port, final String realm, final String scheme) 

Source Link

Document

Creates a new credentials scope for the given host, port, realm, and authentication scheme.

Usage

From source file:nl.esciencecenter.octopus.webservice.mac.MacCredentialTest.java

@Test
public void testGetAuthScope() {
    AuthScope expected = new AuthScope("localhost", 80, "", "MAC");
    assertThat(cred.getAuthScope()).isEqualTo(expected);
}

From source file:nl.esciencecenter.octopus.webservice.mac.MacCredential.java

/**
 * Id/Key pair belong to a certain URI.//from ww w  . j  a  v a 2 s .  c o  m
 *
 * @return AuthScope
 */
public AuthScope getAuthScope() {
    return new AuthScope(scope.getHost(), MacScheme.getPort(scope), "", MacScheme.SCHEME_NAME);
}

From source file:org.apache.cloudstack.storage.datastore.util.NexentaNmsClient.java

protected DefaultHttpClient getClient() {
    if (httpClient == null) {
        if (nmsUrl.getSchema().equalsIgnoreCase("http")) {
            httpClient = getHttpClient();
        } else {/*ww  w . jav  a 2  s  . c om*/
            httpClient = getHttpsClient();
        }
        AuthScope authScope = new AuthScope(nmsUrl.getHost(), nmsUrl.getPort(), AuthScope.ANY_SCHEME, "basic");
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(nmsUrl.getUsername(),
                nmsUrl.getPassword());
        httpClient.getCredentialsProvider().setCredentials(authScope, credentials);
    }
    return httpClient;
}

From source file:org.graylog2.bindings.providers.JestClientProvider.java

@Inject
public JestClientProvider(@Named("elasticsearch_hosts") List<URI> elasticsearchHosts,
        @Named("elasticsearch_connect_timeout") Duration elasticsearchConnectTimeout,
        @Named("elasticsearch_socket_timeout") Duration elasticsearchSocketTimeout,
        @Named("elasticsearch_idle_timeout") Duration elasticsearchIdleTimeout,
        @Named("elasticsearch_max_total_connections") int elasticsearchMaxTotalConnections,
        @Named("elasticsearch_max_total_connections_per_route") int elasticsearchMaxTotalConnectionsPerRoute,
        @Named("elasticsearch_discovery_enabled") boolean discoveryEnabled,
        @Named("elasticsearch_discovery_filter") @Nullable String discoveryFilter,
        @Named("elasticsearch_discovery_frequency") Duration discoveryFrequency, Gson gson) {
    this.factory = new JestClientFactory();
    this.credentialsProvider = new BasicCredentialsProvider();
    final List<String> hosts = elasticsearchHosts.stream().map(hostUri -> {
        if (!Strings.isNullOrEmpty(hostUri.getUserInfo())) {
            final Iterator<String> splittedUserInfo = Splitter.on(":").split(hostUri.getUserInfo()).iterator();
            if (splittedUserInfo.hasNext()) {
                final String username = splittedUserInfo.next();
                final String password = splittedUserInfo.hasNext() ? splittedUserInfo.next() : null;
                credentialsProvider//from  ww w. ja  v  a2  s  .  c  o m
                        .setCredentials(
                                new AuthScope(hostUri.getHost(), hostUri.getPort(), AuthScope.ANY_REALM,
                                        hostUri.getScheme()),
                                new UsernamePasswordCredentials(username, password));
            }
        }
        return hostUri.toString();
    }).collect(Collectors.toList());

    final HttpClientConfig.Builder httpClientConfigBuilder = new HttpClientConfig.Builder(hosts)
            .credentialsProvider(credentialsProvider)
            .connTimeout(Math.toIntExact(elasticsearchConnectTimeout.toMillis()))
            .readTimeout(Math.toIntExact(elasticsearchSocketTimeout.toMillis()))
            .maxConnectionIdleTime(elasticsearchIdleTimeout.getSeconds(), TimeUnit.SECONDS)
            .maxTotalConnection(elasticsearchMaxTotalConnections)
            .defaultMaxTotalConnectionPerRoute(elasticsearchMaxTotalConnectionsPerRoute).multiThreaded(true)
            .discoveryEnabled(discoveryEnabled).discoveryFilter(discoveryFilter)
            .discoveryFrequency(discoveryFrequency.getSeconds(), TimeUnit.SECONDS).gson(gson);

    factory.setHttpClientConfig(httpClientConfigBuilder.build());
}

From source file:glaze.oauth.PreemptiveAuthorizer.java

/**
 * If no auth scheme has been selected for the given context, consider each
 * of the preferred auth schemes and select the first one for which an
 * AuthScheme and matching Credentials are available.
 *//*from w  w w .  j a  va 2  s. co  m*/
@SuppressWarnings("unchecked")
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);

    if (authState != null && authState.getAuthScheme() != null) {
        return;
    }

    HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    CredentialsProvider provider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
    AuthSchemeRegistry schemes = (AuthSchemeRegistry) context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY);
    HttpParams params = request.getParams();

    for (String schemeName : (Iterable<String>) params.getParameter(AuthPNames.PROXY_AUTH_PREF)) {
        AuthScheme scheme = schemes.getAuthScheme(schemeName, params);
        if (scheme != null) {
            AuthScope targetScope = new AuthScope(target.getHostName(), target.getPort(), scheme.getRealm(),
                    scheme.getSchemeName());
            Credentials creds = provider.getCredentials(targetScope);

            if (creds != null) {
                authState.update(scheme, creds);
                return;
            }
        }
    }
}

From source file:com.microsoft.teamfoundation.plugin.impl.TfsClient.java

private Client getClient(URI uri, TfsClientFactoryImpl.ServiceProvider provider, String username,
        TfsSecret password) {//from w  w  w .j ava 2  s . c o  m
    ClientConfig clientConfig = new ClientConfig();

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

    if (TfsClientFactoryImpl.ServiceProvider.TFS == provider) {
        /* NTLM auth for on premise installation */
        credentialsProvider.setCredentials(
                new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM, AuthSchemes.NTLM),
                new NTCredentials(username, password.getSecret(), uri.getHost(), ""));

        logger.info("Using NTLM authentication for on premise TeamFoundationServer");

    } else if (TfsClientFactoryImpl.ServiceProvider.VSO == provider) {
        // Basic Auth for VSO services
        credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                new UsernamePasswordCredentials(username, password.getSecret()));

        logger.info("Using user/pass authentication for Visual Studio Online services");

        // Preemptive send basic auth header, or we will be redirected for oauth login
        clientConfig.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
    }

    clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);

    if (System.getProperty(PROXY_URL_PROPERTY) != null) {
        clientConfig.property(ClientProperties.PROXY_URI, System.getProperty(PROXY_URL_PROPERTY));
        clientConfig.property(ApacheClientProperties.SSL_CONFIG, getSslConfigurator());
    }

    clientConfig.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
    clientConfig.connectorProvider(new ApacheConnectorProvider());

    return ClientBuilder.newClient(clientConfig);
}

From source file:com.mpower.mintel.android.utilities.WebUtils.java

public static final AuthScope buildAuthScopes(String host) {

    AuthScope a;//  w w w  .  j a  v a2s.  com
    // allow digest auth on any port...
    a = new AuthScope(host, -1, null, AuthPolicy.DIGEST);

    return a;
}

From source file:org.olat.core.commons.services.webdav.WebDAVConnection.java

public void setCredentials(String username, String password) {
    provider.setCredentials(new AuthScope(host, port, "OLAT WebDAV Access", "Basic"),
            new UsernamePasswordCredentials(username, password));
}

From source file:org.codelibs.fess.es.config.exentity.WebAuthentication.java

private AuthScope getAuthScope() {
    if (StringUtil.isBlank(getHostname())) {
        return AuthScope.ANY;
    }/*from   ww w.  j a  va2  s .c  om*/

    int p;
    if (getPort() == null) {
        p = AuthScope.ANY_PORT;
    } else {
        p = getPort().intValue();
    }

    String r = getAuthRealm();
    if (StringUtil.isBlank(r)) {
        r = AuthScope.ANY_REALM;
    }

    String s = getProtocolScheme();
    if (StringUtil.isBlank(s) || Constants.NTLM.equals(s)) {
        s = AuthScope.ANY_SCHEME;
    }

    return new AuthScope(getHostname(), p, r, s);
}