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

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

Introduction

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

Prototype

String ANY_REALM

To view the source code for org.apache.http.auth AuthScope ANY_REALM.

Click Source Link

Document

The null value represents any realm.

Usage

From source file:org.eclipse.epp.internal.logging.aeri.ui.utils.Proxies.java

public static Executor proxyAuthentication(Executor executor, URI target) throws IOException {
    IProxyData proxy = getProxyData(target).orNull();
    if (proxy != null) {
        HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort());
        if (proxy.getUserId() != null) {
            String userId = getUserName(proxy.getUserId()).orNull();
            String pass = proxy.getPassword();
            String workstation = getWorkstation().orNull();
            String domain = getUserDomain(proxy.getUserId()).orNull();
            return executor
                    .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, "ntlm"),
                            new NTCredentials(userId, pass, workstation, domain))
                    .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME),
                            new UsernamePasswordCredentials(userId, pass));
        } else {//  w  w  w.j ava2  s .  c om
            return executor;
        }
    }
    return executor;
}

From source file:org.apache.maven.wagon.providers.http.BasicAuthScope.java

/**
 * Create an authScope given the /repository/host and /repository/password
 * and the /server/basicAuth or /server/proxyBasicAuth host, port and realm
 * settings. The basicAuth setting should override the repository settings
 * host and/or port if host, port or realm is set to "ANY".
 * <p/>/*w  w w.j a va 2 s . c o m*/
 * Realm can also be set to a specific string and will be set if
 * /server/basicAuthentication/realm is non-null
 *
 * @param host The server setting's /server/host value
 * @param port The server setting's /server/port value
 * @return
 */
public AuthScope getScope(String host, int port) {
    if (getHost() != null //
            && "ANY".compareTo(getHost()) == 0 //
            && getPort() != null //
            && "ANY".compareTo(getPort()) == 0 //
            && getRealm() != null //
            && "ANY".compareTo(getRealm()) == 0) {
        return AuthScope.ANY;
    }
    String scopeHost = host;
    if (getHost() != null) {
        if ("ANY".compareTo(getHost()) == 0) {
            scopeHost = AuthScope.ANY_HOST;
        } else {
            scopeHost = getHost();
        }
    }

    int scopePort = port > -1 ? port : AuthScope.ANY_PORT;
    // -1 for server/port settings does this, but providing an override here
    // in
    // the BasicAuthScope config
    if (getPort() != null) {
        if ("ANY".compareTo(getPort()) == 0) {
            scopePort = AuthScope.ANY_PORT;
        } else {
            scopePort = Integer.parseInt(getPort());
        }
    }

    String scopeRealm = AuthScope.ANY_REALM;
    if (getRealm() != null) {
        if ("ANY".compareTo(getRealm()) != 0) {
            scopeRealm = getRealm();
        } else {
            scopeRealm = getRealm();
        }
    }

    return new AuthScope(scopeHost, scopePort, scopeRealm);
}

From source file:de.escidoc.core.test.common.fedora.TripleStoreTestBase.java

protected DefaultHttpClient getHttpClient() throws Exception {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    URL url = new URL(getFedoraUrl());
    AuthScope m_authScope = new AuthScope(url.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_REALM);
    UsernamePasswordCredentials m_creds = new UsernamePasswordCredentials("fedoraAdmin", "fedoraAdmin");
    httpClient.getCredentialsProvider().setCredentials(m_authScope, m_creds);

    return httpClient;
}

From source file:org.cvasilak.jboss.mobile.admin.net.UploadToJBossServerTask.java

public UploadToJBossServerTask(Context context, Server server, Callback callback) {
    this.context = context;
    this.client = CustomHTTPClient.getHttpClient();
    this.server = server;
    this.callback = callback;

    this.gjson = ((JBossAdminApplication) context.getApplicationContext()).getJSONParser();
    this.parser = new JsonParser();

    // enable digest authentication
    if (server.getUsername() != null && !server.getUsername().equals("")) {
        Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword());

        client.getCredentialsProvider().setCredentials(
                new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials);
    }/*from   w w w.  j a va  2  s  .  c  o m*/
}

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//w w w .  j  a  va  2  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:de.escidoc.core.http.HttpClientBuilderImpl.java

@Override
public HttpClientBuilder withUsernamePasswordCredentials(final String urlString, final String username,
        final String password) {
    final URL url;
    try {/*from   w  ww .  j  av  a  2 s  .c  o m*/
        url = new URL(urlString);
    } catch (final MalformedURLException e) {
        throw new IllegalArgumentException("Invalid url '" + urlString + "'.", e);
    }
    final AuthScope authScope = new AuthScope(url.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_REALM);
    final Credentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password);
    this.httpClient.getCredentialsProvider().setCredentials(authScope, usernamePasswordCredentials);
    return this;
}

From source file:org.eclipse.oomph.setup.internal.sync.SyncUtil.java

public static Executor proxyAuthentication(Executor executor, URI uri) throws IOException {
    IProxyData proxy = getProxyData(uri);
    if (proxy != null) {
        HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort());
        String proxyUserID = proxy.getUserId();
        if (proxyUserID != null) {
            String userID = getUserName(proxyUserID);
            String password = proxy.getPassword();
            String workstation = getWorkstation();
            String domain = getUserDomain(proxyUserID);
            return executor
                    .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, "ntlm"),
                            new NTCredentials(userID, password, workstation, domain))
                    .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME),
                            new UsernamePasswordCredentials(userID, password));
        }// w ww .  ja  va 2s  .co m
    }

    return executor;
}

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

private AuthScope getAuthScope() {
    if (StringUtil.isBlank(getHostname())) {
        return AuthScope.ANY;
    }//from  w w w.jav a2s . com

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

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

private Client getClient(URI uri, TfsClientFactoryImpl.ServiceProvider provider, String username,
        TfsSecret password) {/*from w ww.  j  a  v  a2  s  . co 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);
}