use of org.apache.http.impl.client.BasicCredentialsProvider 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.impl.client.BasicCredentialsProvider 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.impl.client.BasicCredentialsProvider 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);
}
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project jena by apache.
the class TestAuth method withBasicAuth.
private static HttpClient withBasicAuth(AuthScope scope, String user, String passwd) {
BasicCredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, passwd);
provider.setCredentials(scope, credentials);
return HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project jena by apache.
the class TestRemoteEndpointConnectionWithAuth method setup.
/**
* Setup for the tests by allocating a Fuseki instance to work with
* @throws IOException
*/
@BeforeClass
public static void setup() throws IOException {
SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD);
FusekiTestAuth.setupServer(true, sh);
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, PASSWORD));
client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
}
Aggregations