Search in sources :

Example 11 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project OpenMEAP by OpenMEAP.

the class HttpRequestExecuterImpl method setProxy.

protected void setProxy(DefaultHttpClient httpclient, String proxyHost, Integer proxyPort, String proxyUser, String proxyPassword) {
    if (proxyUser != null) {
        httpclient.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword));
    }
    HttpHost proxy = new HttpHost(proxyHost, proxyPort);
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
Also used : HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 12 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project Signal-Android by WhisperSystems.

the class LegacyMmsConnection method constructHttpClient.

protected CloseableHttpClient constructHttpClient() throws IOException {
    RequestConfig config = RequestConfig.custom().setConnectTimeout(20 * 1000).setConnectionRequestTimeout(20 * 1000).setSocketTimeout(20 * 1000).setMaxRedirects(20).build();
    URL mmsc = new URL(apn.getMmsc());
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    if (apn.hasAuthentication()) {
        credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()), new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
    }
    return HttpClients.custom().setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4()).setRedirectStrategy(new LaxRedirectStrategy()).setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT)).setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(config).setDefaultCredentialsProvider(credsProvider).build();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) NoConnectionReuseStrategyHC4(org.apache.http.impl.NoConnectionReuseStrategyHC4) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) URL(java.net.URL) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 13 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project SmartAndroidSource by jaychou2012.

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
	 * @param preemtive
	 *            sets authorization in preemtive manner
	 */
public void setBasicAuth(String username, String password, AuthScope scope, boolean preemtive) {
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    this.httpClient.getCredentialsProvider().setCredentials(scope == null ? AuthScope.ANY : scope, credentials);
    setAuthenticationPreemptive(preemtive);
}
Also used : UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 14 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project jersey by jersey.

the class AuthTest method testPreemptiveAuth.

@Test
public void testPreemptiveAuth() {
    CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
    ClientConfig cc = new ClientConfig();
    cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider).property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri());
    assertEquals("GET", r.request().get(String.class));
}
Also used : CredentialsProvider(org.apache.http.client.CredentialsProvider) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 15 with UsernamePasswordCredentials

use of org.apache.http.auth.UsernamePasswordCredentials in project jersey by jersey.

the class AuthTest method testAuthInteractiveGet.

@Test
public void testAuthInteractiveGet() {
    CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
    ClientConfig cc = new ClientConfig();
    cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri()).path("test");
    assertEquals("GET", r.request().get(String.class));
}
Also used : CredentialsProvider(org.apache.http.client.CredentialsProvider) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

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