use of org.apache.http.impl.client.BasicCredentialsProvider in project crawler4j by yasserg.
the class PageFetcher method doNtLogin.
/**
* Do NT auth for Microsoft AD sites.
*/
private void doNtLogin(NtAuthInfo authInfo) {
logger.info("NT authentication for: " + authInfo.getLoginTarget());
HttpHost targetHost = new HttpHost(authInfo.getHost(), authInfo.getPort(), authInfo.getProtocol());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
try {
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new NTCredentials(authInfo.getUsername(), authInfo.getPassword(), InetAddress.getLocalHost().getHostName(), authInfo.getDomain()));
} catch (UnknownHostException e) {
logger.error("Error creating NT credentials", e);
}
httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project crawler4j by yasserg.
the class PageFetcher method doBasicLogin.
/**
* BASIC authentication<br/>
* Official Example: https://hc.apache
* .org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples
* /client/ClientAuthentication.java
* */
private void doBasicLogin(BasicAuthInfo authInfo) {
logger.info("BASIC authentication for: " + authInfo.getLoginTarget());
HttpHost targetHost = new HttpHost(authInfo.getHost(), authInfo.getPort(), authInfo.getProtocol());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(authInfo.getUsername(), authInfo.getPassword()));
httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project opennms by OpenNMS.
the class ScvEnabledRestClientImpl method getResponse.
// Setup a client with pre-emptive authentication
private CloseableHttpResponse getResponse(HttpGet httpget) throws Exception {
CloseableHttpResponse response = null;
HttpHost target = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(target.getHostName(), target.getPort()), getCredentials());
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(target, basicAuth);
HttpClientContext localContext = HttpClientContext.create();
localContext.setAuthCache(authCache);
response = httpclient.execute(target, httpget, localContext);
return response;
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project Xponents by OpenSextant.
the class SharepointClient method getClient.
/**
* Sharepoint requires NTLM. This client requires a non-null user/passwd/domain.
*
*/
@Override
public HttpClient getClient() {
if (currentConn != null) {
return currentConn;
}
HttpClientBuilder clientHelper = HttpClientBuilder.create();
if (proxyHost != null) {
clientHelper.setProxy(proxyHost);
}
RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
CredentialsProvider creds = new BasicCredentialsProvider();
creds.setCredentials(AuthScope.ANY, new NTCredentials(user, passwd, server, domain));
clientHelper.setDefaultCredentialsProvider(creds);
HttpClient httpClient = clientHelper.setDefaultRequestConfig(globalConfig).build();
return httpClient;
}
use of org.apache.http.impl.client.BasicCredentialsProvider 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();
}
}
Aggregations