use of org.apache.http.client.HttpClient 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.client.HttpClient in project jena by apache.
the class RDFParserBuilder method buildHttpClient.
private HttpClient buildHttpClient() {
if (httpClient != null)
return httpClient;
if (httpHeaders.isEmpty())
// For complete compatibility, we have to let null pass through.
return // HttpOp.getDefaultHttpClient();
null;
List<Header> hdrs = new ArrayList<>();
httpHeaders.forEach((k, v) -> {
Header header = new BasicHeader(k, v);
hdrs.add(header);
});
HttpClient hc = CachingHttpClientBuilder.create().setDefaultHeaders(hdrs).build();
return hc;
}
use of org.apache.http.client.HttpClient 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.client.HttpClient 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;
}
}
use of org.apache.http.client.HttpClient in project jena by apache.
the class TestFusekiTestAuth method testServer_auth_bad_user.
@Test(expected = HttpException.class)
public void testServer_auth_bad_user() {
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
Credentials credentials = new UsernamePasswordCredentials("USERUSER", PASSWORD);
credsProvider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null)) {
} catch (HttpException ex) {
throw assertAuthHttpException(ex);
}
}
Aggregations