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