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.temenos.useragent.generic.http.DefaultHttpClientHelper.java

/**
 * Builds and returns the basic authentication provider.
 * //from w w  w  . j  a va 2  s .  c om
 * @return
 */
public static CredentialsProvider getBasicCredentialProvider() {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    ConnectionConfig config = ContextFactory.get().getContext().connectionCongfig();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(
            config.getValue(ConnectionConfig.USER_NAME), config.getValue(ConnectionConfig.PASS_WORD)));
    return credentialsProvider;
}

From source file:org.qucosa.camel.component.sword.SwordConnection.java

private HttpClient prepareHttpClient() {
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));

    HttpClient client = HttpClientBuilder.create().setConnectionManager(connectionManager)
            .setDefaultCredentialsProvider(credentialsProvider).build();
    return client;
}

From source file:org.xwiki.extension.repository.xwiki.internal.httpclient.DefaultHttpClientFactory.java

@Override
public HttpClient createClient(String user, String password) {
    DefaultHttpClient httpClient = new DefaultHttpClient();

    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, this.configuration.getUserAgent());
    httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
    httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);

    // Setup proxy
    ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
            httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault());
    httpClient.setRoutePlanner(routePlanner);

    // Setup authentication
    if (user != null) {
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(user, password));
    }//from ww w  .j  a va  2s  . c  o  m

    return httpClient;
}

From source file:com.google.resting.rest.client.BaseRESTClient.java

protected static DefaultHttpClient buildHttpClient(ServiceContext serviceContext) {
    DefaultHttpClient httpClient = null;
    HttpParams httpParams = null;//from w w w . j a  v  a2  s  .  c  o m
    HttpContext httpContext = serviceContext.getHttpContext();
    Credentials credentials = null;
    if (httpContext != null) {
        httpParams = httpContext.getHttpParams();
        credentials = httpContext.getCredentials();
    }
    if (httpParams != null)
        httpClient = new DefaultHttpClient(httpParams);
    else
        httpClient = new DefaultHttpClient();

    if (credentials != null)
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);

    return httpClient;
}

From source file:com.ibm.watson.app.common.util.http.HttpClientBuilder.java

public static CloseableHttpClient buildDefaultHttpClient(Credentials cred) {

    // Use custom cookie store if necessary.
    CookieStore cookieStore = new BasicCookieStore();
    // Use custom credentials provider if necessary.
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    RequestConfig defaultRequestConfig;/*from   w  ww.ja  v  a 2s.c o m*/

    //private DefaultHttpClient client;
    connManager.setMaxTotal(200);
    connManager.setDefaultMaxPerRoute(50);
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());

        // Create a registry of custom connection socket factories for supported
        // protocol schemes.
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                .<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE)
                .register("https", new SSLConnectionSocketFactory(builder.build())).build();
    } catch (Exception e) {
        logger.warn(MessageKey.AQWEGA02000W_unable_init_ssl_context.getMessage(), e);
    }
    // Create global request configuration
    defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BEST_MATCH)
            .setExpectContinueEnabled(true)
            .setTargetPreferredAuthSchemes(
                    Arrays.asList(AuthSchemes.BASIC, AuthSchemes.NTLM, AuthSchemes.DIGEST))
            .setAuthenticationEnabled(true).build();

    if (cred != null)
        credentialsProvider.setCredentials(AuthScope.ANY, cred);

    return HttpClients.custom().setConnectionManager(connManager).setDefaultCookieStore(cookieStore)
            .setDefaultCredentialsProvider(credentialsProvider).setDefaultRequestConfig(defaultRequestConfig)
            .build();
}

From source file:org.oscarehr.fax.core.FaxStatusUpdater.java

public void updateStatus() {

    List<FaxJob> faxJobList = faxJobDao.getInprogressFaxesByJobId();
    FaxConfig faxConfig;/*from  w ww . ja  v a 2s . c  o  m*/
    DefaultHttpClient client = new DefaultHttpClient();
    FaxJob faxJobUpdated;

    log.info("CHECKING STATUS OF " + faxJobList.size() + " FAXES");

    for (FaxJob faxJob : faxJobList) {
        faxConfig = faxConfigDao.getConfigByNumber(faxJob.getFax_line());

        if (faxConfig == null) {
            log.error("Could not find faxConfig.  Has the fax number changed?");
        } else if (faxConfig.isActive()) {

            client.getCredentialsProvider().setCredentials(AuthScope.ANY,
                    new UsernamePasswordCredentials(faxConfig.getSiteUser(), faxConfig.getPasswd()));

            HttpGet mGet = new HttpGet(faxConfig.getUrl() + "/" + faxJob.getJobId());
            mGet.setHeader("accept", "application/json");
            mGet.setHeader("user", faxConfig.getFaxUser());
            mGet.setHeader("passwd", faxConfig.getFaxPasswd());

            try {
                HttpResponse response = client.execute(mGet);
                log.info("RESPONSE: " + response.getStatusLine().getStatusCode());
                mGet.releaseConnection();

                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

                    HttpEntity httpEntity = response.getEntity();
                    String content = EntityUtils.toString(httpEntity);

                    ObjectMapper mapper = new ObjectMapper();
                    faxJobUpdated = mapper.readValue(content, FaxJob.class);
                    //faxJobUpdated = (FaxJob) JSONObject.toBean(jsonObject, FaxJob.class);

                    faxJob.setStatus(faxJobUpdated.getStatus());
                    faxJob.setStatusString(faxJobUpdated.getStatusString());

                    log.info("UPDATED FAX JOB ID " + faxJob.getJobId() + " WITH STATUS " + faxJob.getStatus());
                    faxJobDao.merge(faxJob);

                } else {
                    log.error("WEB SERVICE RESPONDED WITH " + response.getStatusLine().getStatusCode(),
                            new IOException());
                }

            } catch (ClientProtocolException e) {
                log.error("HTTP WS CLIENT ERROR", e);

            } catch (IOException e) {
                log.error("IO ERROR", e);
            }

        }

    }
}

From source file:com.microsoft.azure.hdinsight.spark.jobs.SparkRestUtil.java

public static HttpEntity getEntity(@NotNull IClusterDetail clusterDetail, @NotNull String restUrl)
        throws HDIException, IOException {
    provider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword()));
    HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(provider).build();
    String url = String.format(SPARK_REST_API_ENDPOINT, clusterDetail.getName(), restUrl);
    HttpGet get = new HttpGet(url);
    HttpResponse response = client.execute(get);
    int code = response.getStatusLine().getStatusCode();
    if (code == HttpStatus.SC_OK || code == HttpStatus.SC_CREATED) {
        return response.getEntity();
    } else {//  w  w  w  .  j  a v a 2  s.c  om
        throw new HDIException(response.getStatusLine().getReasonPhrase(),
                response.getStatusLine().getStatusCode());
    }
}

From source file:org.springframework.xd.shell.security.SecuredShellAccessWithSslTest.java

@Test
public void testSpringXDTemplate() throws Exception {
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "whosThere"));
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
            HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider)
                    .setSSLSocketFactory(new SSLConnectionSocketFactory(new SSLContextBuilder()
                            .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()))
                    .build());/*from  ww w .j av  a  2  s.c o m*/
    SpringXDTemplate template = new SpringXDTemplate(requestFactory, new URI("https://localhost:" + adminPort));
    PagedResources<ModuleDefinitionResource> moduleDefinitions = template.moduleOperations()
            .list(RESTModuleType.sink);
    assertThat(moduleDefinitions.getLinks().size(), greaterThan(0));
}

From source file:com.microsoft.azure.hdinsight.spark.common.SparkInteractiveSessions.java

/**
 * Set http request credential using username and password
 *
 * @param username : username/*from  www  .  j a  va2  s.c om*/
 * @param password : password
 */
public void setCredentialsProvider(String username, String password) {
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
}

From source file:fr.pilato.elasticsearch.crawler.fs.client.ElasticsearchClient.java

private ElasticsearchClient(List<Node> nodes, String username, String password) {
    List<HttpHost> hosts = new ArrayList<>(nodes.size());
    for (Node node : nodes) {
        hosts.add(new HttpHost(node.getHost(), node.getPort(), node.getScheme().toLowerCase()));
    }/*  ww  w.j  a  va  2  s .c  o  m*/
    RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()]));

    if (username != null) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
        builder.setHttpClientConfigCallback(
                httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
    }

    client = builder.build();
}