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

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

Introduction

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

Prototype

public UsernamePasswordCredentials(final String userName, final String password) 

Source Link

Document

The constructor with the username and password arguments.

Usage

From source file:com.imagesleuth.imagesleuthclient2.Poster.java

public Poster(String url, String user, String password) {
    Test.testNull(url);/*from   ww w.j  a v  a 2s . c  om*/
    Test.testNull(user);
    Test.testNull(password);

    //System.out.println("user: " + user + " password: " + password);

    harray.add(new BasicHeader("Authorization",
            "Basic " + Base64.encodeBase64String((user + ":" + password).getBytes())));

    urlval = (!url.startsWith("http")) ? "http://" + url + "/api/v1/job" : url + "/api/v1/job";
    System.out.println("Poster: post url " + urlval);

    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password);
    credsProvider.setCredentials(AuthScope.ANY, credentials);
    requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(30000).build();
}

From source file:org.appenders.log4j2.elasticsearch.jest.BasicCredentials.java

@Override
public void applyTo(HttpClientConfig.Builder builder) {

    BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
    basicCredentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

    builder.credentialsProvider(basicCredentialsProvider);

}

From source file:org.commonjava.indy.httprox.AbstractHttproxFunctionalTest.java

protected HttpClientContext proxyContext(final String user, final String pass) {
    final CredentialsProvider creds = new BasicCredentialsProvider();
    creds.setCredentials(new AuthScope(HOST, proxyPort), new UsernamePasswordCredentials(user, pass));
    final HttpClientContext ctx = HttpClientContext.create();
    ctx.setCredentialsProvider(creds);/* w  w w.  j  a va 2 s .com*/

    return ctx;
}

From source file:com.microsoft.azure.hdinsight.common.task.MultiRestTask.java

public MultiRestTask(@NotNull IClusterDetail clusterDetail, @NotNull List<String> paths,
        @NotNull FutureCallback<List<String>> callback) {
    super(callback);
    this.clusterDetail = clusterDetail;
    this.paths = paths;
    try {/* ww  w . j a  va  2 s  . c o m*/
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(
                clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword()));
    } catch (HDIException e) {
        e.printStackTrace();
    }
}

From source file:org.openhab.binding.insteonplm.internal.driver.hub.HubIOStream.java

@Override
public boolean open() {
    m_client = new DefaultHttpClient();
    if (m_user != null && m_pass != null) {
        m_client.getCredentialsProvider().setCredentials(new AuthScope(m_host, m_port),
                new UsernamePasswordCredentials(m_user, m_pass));
    }//from  www  . j  a  va 2 s.c  o m
    HttpConnectionParams.setConnectionTimeout(m_client.getParams(), 5000);

    m_in = new HubInputStream();

    m_pollThread = new Thread(this);
    m_pollThread.start();

    m_out = new HubOutputStream();
    return true;
}

From source file:com.arcbees.vcs.github.GitHubApi.java

public GitHubApi(HttpClientWrapper httpClient, GitHubApiPaths apiPaths, String userName, String password,
        String repositoryOwner, String repositoryName) {
    this.httpClient = httpClient;
    this.apiPaths = apiPaths;
    this.repositoryOwner = repositoryOwner;
    this.repositoryName = repositoryName;
    this.credentials = new UsernamePasswordCredentials(userName, password);
    this.gson = new GsonBuilder().registerTypeAdapter(Date.class, new GsonDateTypeAdapter())
            .registerTypeAdapter(GitHubPullRequests.class, new GitHubPullRequestsTypeAdapter())
            .registerTypeAdapter(CommitStatus.class, new CommitStatusTypeAdapter()).create();
}

From source file:com.smartling.api.sdk.util.HttpProxyUtils.java

/**
 * Get an HttpClient given a proxy config if any
 * @param proxyConfiguration configuration of proxy to use
 * @return org.apache.http.impl.client.CloseableHttpClient
 *///w  w  w.j av a  2  s  .  co  m
public CloseableHttpClient getHttpClient(final ProxyConfiguration proxyConfiguration) {
    HttpClientBuilder httpClientBuilder = getHttpClientBuilder();

    if (proxyAuthenticationRequired(proxyConfiguration)) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(
                new AuthScope(proxyConfiguration.getHost(), proxyConfiguration.getPort()),
                new UsernamePasswordCredentials(proxyConfiguration.getUsername(),
                        proxyConfiguration.getPassword()));

        httpClientBuilder = httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    }

    return httpClientBuilder.build();
}

From source file:org.trustedanalytics.servicebroker.hdfs.config.hgm.HgmHttpsConfiguration.java

@Bean
@Qualifier("hgmRestTemplate")
public RestTemplate getHgmHttpsRestTemplate()
        throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
    SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS()
            .build();/*from   w  w  w .  j a  va 2 s .  co  m*/
    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext,
            new AllowAllHostnameVerifier());
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword()));

    HttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(connectionFactory)
            .setDefaultCredentialsProvider(credentialsProvider).build();

    ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    return new RestTemplate(requestFactory);
}

From source file:org.openlmis.UiUtils.HttpClient.java

public ResponseEntity SendJSON(String json, String url, String commMethod, String username, String password) {

    HttpHost targetHost = new HttpHost(HOST, PORT, PROTOCOL);
    AuthScope localhost = new AuthScope(HOST, PORT);

    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    httpClient.getCredentialsProvider().setCredentials(localhost, credentials);

    AuthCache authCache = new BasicAuthCache();
    authCache.put(targetHost, new BasicScheme());

    httpContext.setAttribute(AUTH_CACHE, authCache);

    try {/*from ww w .  j  a  v  a 2  s. c om*/
        return handleRequest(commMethod, json, url, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.jasig.portlet.proxy.service.web.interceptor.PortletPreferencesBasicAuthenticationPreInterceptor.java

@Override
protected UsernamePasswordCredentials getCredentials(PortletRequest portletRequest) {

    // get the username and password attribute names configured for this
    // portlet instance
    final PortletPreferences preferences = portletRequest.getPreferences();
    final String username = preferences.getValue(USERNAME_PREFERENCE, null);
    final String password = preferences.getValue(PASSWORD_PREFERENCE, null);

    // Sanity check...
    if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
        final String msg = "Both username and password are required for PortletPreferencesBasicAuthenticationPreInterceptor";
        throw new IllegalStateException(msg);
    }/*from  ww w .  j  av  a  2 s  .c  om*/

    // construct a credentials object using hte attributes
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    return credentials;
}