use of org.apache.http.auth.UsernamePasswordCredentials in project azure-tools-for-java by Microsoft.
the class SparkBatchSubmission method setUsernamePasswordCredential.
/**
* Set http request credential using username and password
* @param username : username
* @param password : password
*/
public void setUsernamePasswordCredential(String username, String password) {
credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(username, password));
if (username != null && password != null) {
String auth = username + ":" + password;
authCode = "Basic " + new String(Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)));
}
}
use of org.apache.http.auth.UsernamePasswordCredentials in project Libraries-for-Android-Developers by eoecn.
the class AsyncHttpClient 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);
}
use of org.apache.http.auth.UsernamePasswordCredentials in project maven-plugins by apache.
the class JavadocUtil method createHttpClient.
/**
* Creates a new {@code HttpClient} instance.
*
* @param settings The settings to use for setting up the client or {@code null}.
* @param url The {@code URL} to use for setting up the client or {@code null}.
*
* @return A new {@code HttpClient} instance.
*
* @see #DEFAULT_TIMEOUT
* @since 2.8
*/
private static HttpClient createHttpClient(Settings settings, URL url) {
DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMEOUT);
httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT);
httpClient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
// Some web servers don't allow the default user-agent sent by httpClient
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
if (settings != null && settings.getActiveProxy() != null) {
Proxy activeProxy = settings.getActiveProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts());
if (StringUtils.isNotEmpty(activeProxy.getHost()) && (url == null || !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost()))) {
HttpHost proxy = new HttpHost(activeProxy.getHost(), activeProxy.getPort());
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) {
Credentials credentials = new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword());
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
}
}
}
return httpClient;
}
use of org.apache.http.auth.UsernamePasswordCredentials in project SeaStar by 13120241790.
the class AsyncHttpClient 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);
}
use of org.apache.http.auth.UsernamePasswordCredentials in project SeaStar by 13120241790.
the class SyncHttpClient method setProxy.
/**
* Sets the Proxy by it's hostname,port,username and password
*
* @param hostname
* the hostname (IP or DNS name)
* @param port
* the port number. -1 indicates the scheme default port.
* @param username
* the username
* @param password
* the password
*/
public void setProxy(String hostname, int port, String username, String password) {
httpClient.getCredentialsProvider().setCredentials(new AuthScope(hostname, port), new UsernamePasswordCredentials(username, password));
final HttpHost proxy = new HttpHost(hostname, port);
final HttpParams httpParams = this.httpClient.getParams();
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
Aggregations