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

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

Introduction

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

Prototype

AuthScope ANY

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

Click Source Link

Document

Default scope matching any host, port, realm and authentication scheme.

Usage

From source file:com.microsoft.exchange.impl.http.PreemptiveAuthInterceptor.java

/**
 * 
 */
public PreemptiveAuthInterceptor() {
    this(AuthScope.ANY);
}

From source file:org.apache.jena.jdbc.remote.results.TestRemoteEndpointResultsWithAuth.java

/**
 * Setup for the tests by allocating a Fuseki instance to work with
 * /*from  w  ww  .j  a v a2  s  . co  m*/
 * @throws SQLException
 * @throws IOException
 */
@BeforeClass
public static void setup() throws SQLException, IOException {
    SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD);
    FusekiTestAuth.setupServer(true, sh);

    BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
    credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, PASSWORD));
    client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();

    connection = new RemoteEndpointConnection(FusekiTestAuth.serviceQuery(), FusekiTestAuth.serviceUpdate(),
            null, null, null, null, client, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null,
            null);
    connection.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
}

From source file:org.opendaylight.alto.manager.AltoManager.java

protected HttpClient initiateHttpClient() {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin:admin"));
    return HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
}

From source file:org.janusgraph.diskstorage.es.rest.util.BasicAuthHttpClientConfigCallback.java

public BasicAuthHttpClientConfigCallback(final String realm, final String username, final String password) {
    Preconditions.checkArgument(StringUtils.isNotEmpty(username),
            "HTTP Basic Authentication: username must be provided");
    Preconditions.checkArgument(StringUtils.isNotEmpty(password),
            "HTTP Basic Authentication: password must be provided");

    credentialsProvider = new BasicCredentialsProvider();

    final AuthScope authScope;
    if (StringUtils.isNotEmpty(realm)) {
        authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME);
    } else {//from   www .j  a v  a  2 s. c o  m
        authScope = AuthScope.ANY;
    }
    credentialsProvider.setCredentials(authScope, new UsernamePasswordCredentials(username, password));
}

From source file:org.apache.camel.component.http4.BasicAuthenticationHttpClientConfigurer.java

public void configureHttpClient(HttpClient client) {
    Credentials defaultcreds;//  w ww . ja  va  2  s . c  om
    if (domain != null) {
        defaultcreds = new NTCredentials(username, password, host, domain);
    } else {
        defaultcreds = new UsernamePasswordCredentials(username, password);
    }
    ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds);
}

From source file:com.mgmtp.jfunk.web.WebDriverModuleTest.java

@Test
public void testHtmlUnitCredentials() {
    Configuration config = new Configuration(Charsets.UTF_8);

    config.put(WebConstants.HTMLUNIT_CREDENTIALS_PREFIX + ".www.testuser.com." + JFunkConstants.USERNAME,
            "testuser1");
    config.put(WebConstants.HTMLUNIT_CREDENTIALS_PREFIX + ".www.testuser.com." + JFunkConstants.PASSWORD,
            "secret");

    config.put(WebConstants.HTMLUNIT_CREDENTIALS_PREFIX + ".www.mgm-tp.com." + JFunkConstants.USERNAME, "mgm");
    config.put(WebConstants.HTMLUNIT_CREDENTIALS_PREFIX + ".www.mgm-tp.com." + JFunkConstants.PASSWORD,
            "mgmmgm");

    WebDriverModule module = new WebDriverModule();
    Map<String, CredentialsProvider> credentialsMap = module.provideHtmlUnitCredentialsProviderMap(config);

    CredentialsProvider cp = credentialsMap.get("www.testuser.com");
    assertEquals(cp.getCredentials(AuthScope.ANY).getUserPrincipal().getName(), "testuser1");
    assertEquals(cp.getCredentials(AuthScope.ANY).getPassword(), "secret");

    cp = credentialsMap.get("www.mgm-tp.com");
    assertEquals(cp.getCredentials(AuthScope.ANY).getUserPrincipal().getName(), "mgm");
    assertEquals(cp.getCredentials(AuthScope.ANY).getPassword(), "mgmmgm");
}

From source file:cf.spring.servicebroker.AbstractServiceBrokerTest.java

protected BasicCredentialsProvider credentials() {
    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USERNAME, PASSWORD));
    return credentialsProvider;
}

From source file:co.aurasphere.botmill.skype.util.network.NetworkUtils.java

/**
 * Send.//from  w ww  . ja va  2 s  .c  o m
 *
 * @param request the request
 * @return the string
 */
private static String send(HttpRequestBase request) {

    CredentialsProvider provider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(null, null);

    provider.setCredentials(AuthScope.ANY, credentials);
    CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();

    logger.debug(request.getRequestLine().toString());
    HttpResponse httpResponse = null;
    String response = null;
    try {
        httpResponse = httpClient.execute(request);
        response = logResponse(httpResponse);
    } catch (Exception e) {
        logger.error("Error during HTTP connection to Kik: ", e);
    } finally {
        try {
            httpClient.close();
        } catch (IOException e) {
            logger.error("Error while closing HTTP connection: ", e);
        }
    }
    return response;
}

From source file:org.springframework.cloud.deployer.admin.shell.command.support.HttpClientUtils.java

/**
 * Ensures that the passed-in {@link RestTemplate} is using the Apache HTTP Client. If the optional {@code username} AND
 * {@code password} are not empty, then a {@link BasicCredentialsProvider} will be added to the {@link CloseableHttpClient}.
 *
 * Furthermore, you can set the underlying {@link SSLContext} of the {@link HttpClient} allowing you to accept self-signed
 * certificates./*ww w .j av  a2  s .c o  m*/
 *
 * @param restTemplate Must not be null
 * @param username Can be null
 * @param password Can be null
 * @param skipSslValidation Use with caution! If true certificate warnings will be ignored.
 */
public static void prepareRestTemplate(RestTemplate restTemplate, String username, String password,
        boolean skipSslValidation) {

    Assert.notNull(restTemplate, "The provided RestTemplate must not be null.");

    final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

    if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
        httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    }

    if (skipSslValidation) {
        httpClientBuilder.setSSLContext(HttpClientUtils.buildCertificateIgnoringSslContext());
        httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
    }

    final CloseableHttpClient httpClient = httpClientBuilder.build();
    final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
            httpClient);
    restTemplate.setRequestFactory(requestFactory);
}