Search in sources :

Example 96 with UsernamePasswordCredentials

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)));
    }
}
Also used : AuthScope(org.apache.http.auth.AuthScope) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 97 with UsernamePasswordCredentials

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);
}
Also used : UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 98 with UsernamePasswordCredentials

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;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Proxy(org.apache.maven.settings.Proxy) HttpHost(org.apache.http.HttpHost) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 99 with UsernamePasswordCredentials

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);
}
Also used : UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 100 with UsernamePasswordCredentials

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);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)337 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)212 CredentialsProvider (org.apache.http.client.CredentialsProvider)189 AuthScope (org.apache.http.auth.AuthScope)163 HttpHost (org.apache.http.HttpHost)95 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)78 HttpGet (org.apache.http.client.methods.HttpGet)73 IOException (java.io.IOException)54 BasicScheme (org.apache.http.impl.auth.BasicScheme)53 Test (org.junit.Test)53 HttpResponse (org.apache.http.HttpResponse)52 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)46 Credentials (org.apache.http.auth.Credentials)44 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)43 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)37 URI (java.net.URI)34 AuthCache (org.apache.http.client.AuthCache)32 HttpClient (org.apache.http.client.HttpClient)31 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)31 HttpPost (org.apache.http.client.methods.HttpPost)29