use of org.apache.http.auth.Credentials in project sling by apache.
the class PreemptiveAuthInterceptor method process.
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
// If not auth scheme has been initialized yet
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
// Obtain credentials matching the target host
Credentials creds = credsProvider.getCredentials(authScope);
// If found, generate BasicScheme preemptively
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
use of org.apache.http.auth.Credentials in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesCredentialsProvider.
@Test
public void usesCredentialsProvider() throws Exception {
final CredentialsProvider credentialsProvider = new CredentialsProvider() {
@Override
public void setCredentials(AuthScope authscope, Credentials credentials) {
}
@Override
public Credentials getCredentials(AuthScope authscope) {
return null;
}
@Override
public void clear() {
}
};
assertThat(builder.using(configuration).using(credentialsProvider).createClient(apacheBuilder, connectionManager, "test")).isNotNull();
assertThat(spyHttpClientBuilderField("credentialsProvider", apacheBuilder)).isSameAs(credentialsProvider);
}
use of org.apache.http.auth.Credentials in project SmartAndroidSource by jaychou2012.
the class PreemtiveAuthorizationHttpRequestInterceptor method process.
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
use of org.apache.http.auth.Credentials in project camel by apache.
the class ProxyHttpClientConfigurer method configureHttpClient.
public void configureHttpClient(HttpClientBuilder clientBuilder) {
clientBuilder.setProxy(new HttpHost(host, port, scheme));
if (username != null && password != null) {
Credentials defaultcreds;
if (domain != null) {
defaultcreds = new NTCredentials(username, password, ntHost, domain);
} else {
defaultcreds = new UsernamePasswordCredentials(username, password);
}
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, defaultcreds);
clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
}
use of org.apache.http.auth.Credentials in project camel by apache.
the class BasicAuthenticationHttpClientConfigurer method configureHttpClient.
public void configureHttpClient(HttpClientBuilder clientBuilder) {
Credentials defaultcreds;
if (domain != null) {
defaultcreds = new NTCredentials(username, password, host, domain);
} else {
defaultcreds = new UsernamePasswordCredentials(username, password);
}
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, defaultcreds);
clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
Aggregations