Search in sources :

Example 21 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project azure-tools-for-java by Microsoft.

the class SparkRestUtil method getEntity.

//    @Nullable
//    public static List<Application> getApplications(@NotNull ClusterDetail clusterDetail) throws HDIException, IOException {
//        HttpEntity entity = getEntity(clusterDetail, "applications");
//        String entityType = entity.getContentType().getValue();
//        if( entityType.equals("application/json")){
//            String json = EntityUtils.toString(entity);
//            List<Application> apps = objectMapper.readValue(json, TypeFactory.defaultInstance().constructType(List.class, Application.class));
//            return apps;
//        }
//        return null;
//    }
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 {
        throw new HDIException(response.getStatusLine().getReasonPhrase(), response.getStatusLine().getStatusCode());
    }
}
Also used : HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 22 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project android_frameworks_base by ResurrectionRemix.

the class DefaultHttpClientTest method authenticateDigestAlgorithm.

private void authenticateDigestAlgorithm(String algorithm) throws Exception {
    String challenge = "Digest realm=\"protected area\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "algorithm=" + algorithm;
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
    HttpGet get = new HttpGet();
    digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 23 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project tdi-studio-se by Talend.

the class DynamicsCRMClient method setHttpclientProxy.

/**
     * Setup proxy for httpClient
     */
private void setHttpclientProxy(DefaultHttpClient httpClient) {
    Proxy proxy = getProxy();
    String proxyUser = System.getProperty("https.proxyUser");
    String proxyPwd = System.getProperty("https.proxyPassword");
    // set by other components like tSetProxy
    if (proxy != null) {
        final HttpHost httpHost = new HttpHost(((InetSocketAddress) proxy.address()).getHostName(), ((InetSocketAddress) proxy.address()).getPort());
        // Sets usage of HTTP proxy
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpHost);
        // TODO Because the proxy of get accesToken can't support authentication. remove this ?
        if (proxyUser != null && proxyPwd != null) {
            httpClient.getCredentialsProvider().setCredentials(new AuthScope(httpHost), new UsernamePasswordCredentials(proxyUser, proxyPwd));
        }
    }
}
Also used : Proxy(java.net.Proxy) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 24 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project api-snippets by TwilioDevEd.

the class Example method main.

public static void main(String[] args) throws Exception {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope("lookups.twilio.com", 80), new UsernamePasswordCredentials("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "your_auth_token"));
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    try {
        HttpGet httpget = new HttpGet("https://lookups.twilio.com/v1/PhoneNumbers/+16502530000/?AddOns=payfone_tcpa_compliance&AddOns.payfone_tcpa_compliance.RightPartyContactedDate=20160101");
        System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpget);
        try {
            System.out.println(response.getStatusLine());
            System.out.println(EntityUtils.toString(response.getEntity()));
        } finally {
            response.close();
        }
    } finally {
        httpclient.close();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpGet(org.apache.http.client.methods.HttpGet) AuthScope(org.apache.http.auth.AuthScope) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 25 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project SeaStar by 13120241790.

the class SyncHttpClient method setBasicAuth.

/**
	 * Sets basic authentication for the request. You should pass in your
	 * AuthScope for security. It should be like this
	 * setBasicAuth("username","password", new
	 * AuthScope("host",port,AuthScope.ANY_REALM))
	 * 
	 * @param username
	 *            Basic Auth username
	 * @param password
	 *            Basic Auth password
	 * @param scope
	 *            - an AuthScope object
	 */
public void setBasicAuth(String username, String password, AuthScope scope) {
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    this.httpClient.getCredentialsProvider().setCredentials(scope, credentials);
}
Also used : UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)122 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)63 AuthScope (org.apache.http.auth.AuthScope)59 CredentialsProvider (org.apache.http.client.CredentialsProvider)48 HttpHost (org.apache.http.HttpHost)25 HttpGet (org.apache.http.client.methods.HttpGet)25 Test (org.junit.Test)21 IOException (java.io.IOException)20 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 HttpResponse (org.apache.http.HttpResponse)18 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)16 Credentials (org.apache.http.auth.Credentials)14 HttpClient (org.apache.http.client.HttpClient)13 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)13 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)10 BasicScheme (org.apache.http.impl.auth.BasicScheme)9 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)9 BasicHeader (org.apache.http.message.BasicHeader)9 DigestScheme (org.apache.http.impl.auth.DigestScheme)8 Client (javax.ws.rs.client.Client)7