use of org.apache.http.client.CredentialsProvider in project dropwizard by dropwizard.
the class JerseyClientBuilderTest method usesACustomCredentialsProvider.
@Test
public void usesACustomCredentialsProvider() {
CredentialsProvider customCredentialsProvider = new SystemDefaultCredentialsProvider();
builder.using(customCredentialsProvider);
verify(apacheHttpClientBuilder).using(customCredentialsProvider);
}
use of org.apache.http.client.CredentialsProvider in project frontend-maven-plugin by eirslett.
the class DefaultFileDownloader method makeCredentialsProvider.
private CredentialsProvider makeCredentialsProvider(String host, int port, String username, String password) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(username, password));
return credentialsProvider;
}
use of org.apache.http.client.CredentialsProvider in project frontend-maven-plugin by eirslett.
the class DefaultFileDownloader method execute.
private CloseableHttpResponse execute(String requestUrl, String userName, String password) throws IOException {
CloseableHttpResponse response;
Proxy proxy = proxyConfig.getProxyForUrl(requestUrl);
if (proxy != null) {
LOGGER.info("Downloading via proxy " + proxy.toString());
return executeViaProxy(proxy, requestUrl);
} else {
LOGGER.info("No proxy was configured, downloading directly");
if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) {
LOGGER.info("Using credentials (" + userName + ") from settings.xml");
// Auth target host
URL aURL = new URL(requestUrl);
HttpClientContext localContext = makeLocalContext(aURL);
CredentialsProvider credentialsProvider = makeCredentialsProvider(aURL.getHost(), aURL.getPort(), userName, password);
response = buildHttpClient(credentialsProvider).execute(new HttpGet(requestUrl), localContext);
} else {
response = buildHttpClient(null).execute(new HttpGet(requestUrl));
}
}
return response;
}
use of org.apache.http.client.CredentialsProvider 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();
}
use of org.apache.http.client.CredentialsProvider 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));
}
Aggregations