use of org.apache.http.auth.UsernamePasswordCredentials in project apex-core by apache.
the class WebServicesClientTest method checkUserCredentials.
public static void checkUserCredentials(String username, String password, AuthScheme authScheme) throws NoSuchFieldException, IllegalAccessException {
CredentialsProvider provider = getCredentialsProvider();
String httpScheme = AuthScope.ANY_SCHEME;
if (authScheme == AuthScheme.BASIC) {
httpScheme = AuthSchemes.BASIC;
} else if (authScheme == AuthScheme.DIGEST) {
httpScheme = AuthSchemes.DIGEST;
}
AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme);
Credentials credentials = provider.getCredentials(authScope);
Assert.assertNotNull("Credentials", credentials);
Assert.assertTrue("Credentials type is user", UsernamePasswordCredentials.class.isAssignableFrom(credentials.getClass()));
UsernamePasswordCredentials pwdCredentials = (UsernamePasswordCredentials) credentials;
Assert.assertEquals("Username", username, pwdCredentials.getUserName());
Assert.assertEquals("Password", password, pwdCredentials.getPassword());
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jackrabbit by apache.
the class WebDAVTest method setUp.
protected void setUp() throws Exception {
this.uri = URI.create(System.getProperty("webdav.test.url", "http://localhost:8080/repository/default/"));
this.root = this.uri.toASCIIString();
if (!this.root.endsWith("/")) {
this.root += "/";
}
this.username = System.getProperty("webdav.test.username", "admin");
this.password = System.getProperty("webdav.test.password", "admin");
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(this.username, this.password));
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
this.context = HttpClientContext.create();
this.context.setCredentialsProvider(credsProvider);
this.context.setAuthCache(authCache);
this.client = HttpClients.custom().setConnectionManager(cm).build();
super.setUp();
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jena by apache.
the class TestAuth method update_with_auth_11.
@Test
public void update_with_auth_11() {
UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
// Auth credentials for valid user with correct password scoped to correct URI
// Also using pre-emptive auth
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
URI scope = URI.create(authServiceUpdate);
credsProv.setCredentials(new AuthScope(scope.getHost(), scope.getPort()), new UsernamePasswordCredentials("allowed", "password"));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost(scope.getHost()), basicAuth);
// Add AuthCache to the execution context
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProv);
context.setAuthCache(authCache);
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
ue.setClient(client);
ue.setHttpContext(context);
ue.execute();
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jena by apache.
the class TestFusekiTestAuth method testServer_auth_bad_password.
@Test(expected = HttpException.class)
public void testServer_auth_bad_password() {
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, "WRONG"));
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null)) {
} catch (HttpException ex) {
throw assertAuthHttpException(ex);
}
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jena by apache.
the class TestFusekiTestServer method testServer_2.
@Test
public void testServer_2() {
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("USER", "PASSWORD"));
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
// No auth set - should work.
try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestServer.urlDataset(), "*/*")) {
} catch (HttpException ex) {
Assert.assertTrue(ex.getResponseCode() == HttpSC.FORBIDDEN_403 || ex.getResponseCode() == HttpSC.UNAUTHORIZED_401);
throw ex;
}
}
Aggregations