use of org.apache.http.client.CredentialsProvider 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.client.CredentialsProvider 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.client.CredentialsProvider 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.client.CredentialsProvider in project jersey by jersey.
the class AuthTest method testPreemptiveAuthPost.
@Test
public void testPreemptiveAuthPost() {
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("POST", r.request().post(Entity.text("POST"), String.class));
}
use of org.apache.http.client.CredentialsProvider in project jersey by jersey.
the class AuthTest method testAuthInteractivePost.
@Test
@Ignore("JERSEY-1750: Cannot retry request with a non-repeatable request entity. How to buffer the entity?" + " Allow repeatable write in jersey?")
public void testAuthInteractivePost() {
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("POST", r.request().post(Entity.text("POST"), String.class));
}
Aggregations