Search in sources :

Example 16 with BasicCredentialsProvider

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);
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) HttpException(org.apache.jena.atlas.web.HttpException) FusekiTestAuth.assertAuthHttpException(org.apache.jena.fuseki.embedded.FusekiTestAuth.assertAuthHttpException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 17 with BasicCredentialsProvider

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;
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) HttpException(org.apache.jena.atlas.web.HttpException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 18 with BasicCredentialsProvider

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);
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) HttpException(org.apache.jena.atlas.web.HttpException) FusekiTestAuth.assertAuthHttpException(org.apache.jena.fuseki.embedded.FusekiTestAuth.assertAuthHttpException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 19 with BasicCredentialsProvider

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();
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 20 with BasicCredentialsProvider

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();
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) BeforeClass(org.junit.BeforeClass)

Aggregations

BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)75 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)63 CredentialsProvider (org.apache.http.client.CredentialsProvider)48 AuthScope (org.apache.http.auth.AuthScope)41 HttpHost (org.apache.http.HttpHost)22 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)20 HttpResponse (org.apache.http.HttpResponse)16 HttpGet (org.apache.http.client.methods.HttpGet)16 HttpClient (org.apache.http.client.HttpClient)14 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)14 IOException (java.io.IOException)13 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)10 AuthCache (org.apache.http.client.AuthCache)9 RequestConfig (org.apache.http.client.config.RequestConfig)9 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 BasicScheme (org.apache.http.impl.auth.BasicScheme)8 Test (org.junit.Test)8 HttpEntity (org.apache.http.HttpEntity)6 AuthSchemeProvider (org.apache.http.auth.AuthSchemeProvider)6