use of org.apache.http.auth.AuthScope in project gradle by gradle.
the class HttpClientConfigurer method useCredentials.
private void useCredentials(CredentialsProvider credentialsProvider, String host, int port, Collection<? extends Authentication> authentications) {
Credentials httpCredentials;
for (Authentication authentication : authentications) {
String scheme = getAuthScheme(authentication);
PasswordCredentials credentials = getPasswordCredentials(authentication);
if (authentication instanceof AllSchemesAuthentication) {
NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
httpCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
credentialsProvider.setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthSchemes.NTLM), httpCredentials);
LOGGER.debug("Using {} and {} for authenticating against '{}:{}' using {}", credentials, ntlmCredentials, host, port, AuthSchemes.NTLM);
}
httpCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
credentialsProvider.setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, scheme), httpCredentials);
LOGGER.debug("Using {} for authenticating against '{}:{}' using {}", credentials, host, port, scheme);
}
}
use of org.apache.http.auth.AuthScope in project Lucee by lucee.
the class HTTPEngine4Impl method setCredentials.
public static BasicHttpContext setCredentials(HttpClientBuilder builder, HttpHost httpHost, String username, String password, boolean preAuth) {
// set Username and Password
if (!StringUtil.isEmpty(username, true)) {
if (password == null)
password = "";
CredentialsProvider cp = new BasicCredentialsProvider();
builder.setDefaultCredentialsProvider(cp);
cp.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password));
BasicHttpContext httpContext = new BasicHttpContext();
if (preAuth) {
AuthCache authCache = new BasicAuthCache();
authCache.put(httpHost, new BasicScheme());
httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
}
return httpContext;
}
return null;
}
use of org.apache.http.auth.AuthScope in project Lucee by lucee.
the class HTTPEngine4Impl method setNTCredentials.
public static void setNTCredentials(HttpClientBuilder builder, String username, String password, String workStation, String domain) {
// set Username and Password
if (!StringUtil.isEmpty(username, true)) {
if (password == null)
password = "";
CredentialsProvider cp = new BasicCredentialsProvider();
builder.setDefaultCredentialsProvider(cp);
cp.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new NTCredentials(username, password, workStation, domain));
}
}
use of org.apache.http.auth.AuthScope in project janusgraph by JanusGraph.
the class BasicAuthHttpClientConfigCallbackTest method testSetDefaultCredentialsProviderWithRealm.
@Test
public void testSetDefaultCredentialsProviderWithRealm() throws Exception {
final CredentialsProvider cp = basicAuthTestBase(HTTP_REALM);
// expected: will match any host in that specific realm
final Credentials credentialsForRealm1 = cp.getCredentials(new AuthScope("dummyhost1", 1234, HTTP_REALM));
assertEquals(HTTP_USER, credentialsForRealm1.getUserPrincipal().getName());
assertEquals(HTTP_PASSWORD, credentialsForRealm1.getPassword());
// ...but not in any other realms
final Credentials credentialsForRealm3 = cp.getCredentials(new AuthScope("dummyhost1", 1234, "Not_" + HTTP_REALM));
assertNull(credentialsForRealm3);
}
use of org.apache.http.auth.AuthScope in project androidquery by androidquery.
the class NTLMProxyHandle method applyProxy.
@Override
public void applyProxy(AbstractAjaxCallback<?, ?> cb, HttpRequest request, DefaultHttpClient client) {
if (!isIntranet(cb.getUrl())) {
if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(user)) {
AQUtility.debug("ntlm token");
client.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
client.getCredentialsProvider().setCredentials(new AuthScope(host, port), new NTCredentials(user, password, host, domain));
cb.proxy(host, port);
}
}
}
Aggregations