Search in sources :

Example 36 with AuthScope

use of org.apache.http.auth.AuthScope in project jena by apache.

the class TestAuth method query_with_auth_14.

@Test
public void query_with_auth_14() throws URISyntaxException {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // Auth credentials for valid user with correct password and scoped to
    // base URI of the actual service URL
    qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
    Assert.assertTrue(qe.execAsk());
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) AuthScope(org.apache.http.auth.AuthScope) Test(org.junit.Test)

Example 37 with AuthScope

use of org.apache.http.auth.AuthScope in project jena by apache.

the class TestAuth method update_with_auth_09.

@Test(expected = HttpException.class)
public void update_with_auth_09() throws URISyntaxException {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
    // Auth credentials for valid user with correct password but scoped to
    // wrong URI
    ue.setClient(withBasicAuth(new AuthScope("example", authPort), "allowed", "password"));
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) AuthScope(org.apache.http.auth.AuthScope) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 38 with AuthScope

use of org.apache.http.auth.AuthScope in project wildfly by wildfly.

the class JASPIHttpSchemeServerAuthModelTestCase method createHttpClient.

private DefaultHttpClient createHttpClient(final URL webAppURL, final String userName, final String userPassword) {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, userPassword);
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(webAppURL.getHost(), webAppURL.getPort(), DEPLOYMENT_REALM_NAME), credentials);
    return httpClient;
}
Also used : AuthScope(org.apache.http.auth.AuthScope) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 39 with AuthScope

use of org.apache.http.auth.AuthScope in project wildfly by wildfly.

the class SAML2AttributeMappingTestCase method testPassUserPrincipalToAttributeManager.

/**
     * Tests IDP attribute mapping when passUserPrincipalToAttributeManager is set to "true". Automatic handling of redirections
     * is enabled for HTTP client used.
     *
     * @throws Exception
     */
@Test
public void testPassUserPrincipalToAttributeManager() throws Exception {
    Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new JBossNegotiateSchemeFactory(true)).build();
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(null, -1, null), new NullHCCredentials());
    try (final CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultAuthSchemeRegistry(authSchemeRegistry).setDefaultCredentialsProvider(credentialsProvider).setRedirectStrategy(Utils.REDIRECT_STRATEGY).build()) {
        String response = PicketLinkTestBase.makeCallWithKerberosAuthn(spUrl.toURI(), httpClient, "jduke", "theduke", 200);
        assertEquals("SP index page was not reached", SP_RESPONSE_BODY, response);
        response = PicketLinkTestBase.makeCall(new URL(spUrl.toString() + PrintAttributeServlet.SERVLET_PATH.substring(1)), httpClient, 200);
        assertEquals("cn attribute not stored", "Java Duke", response);
    }
}
Also used : JBossNegotiateSchemeFactory(org.jboss.as.test.integration.security.common.negotiation.JBossNegotiateSchemeFactory) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) NullHCCredentials(org.jboss.as.test.integration.security.common.NullHCCredentials) AuthScope(org.apache.http.auth.AuthScope) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) URL(java.net.URL) Test(org.junit.Test)

Example 40 with AuthScope

use of org.apache.http.auth.AuthScope in project wildfly by wildfly.

the class SAML2BasicAuthenticationTestCase method testRedirectSP.

/**
     * Tests access to protected service provider with manual handling of
     * redirections
     *
     * @throws Exception
     */
@Test
public void testRedirectSP() throws Exception {
    final DefaultHttpClient httpClient = new DefaultHttpClient();
    try {
        final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(PicketLinkTestBase.ANIL, PicketLinkTestBase.ANIL);
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(null, idpUrl.getPort()), credentials);
        // login to IdP
        String response = PicketLinkTestBase.makeCall(idpUrl, httpClient, 200);
        assertTrue("IdP index page was not reached", response.contains("Welcome to IdP"));
        // request SP2
        URL redirectLocation = PicketLinkTestBase.makeCallWithoutRedirect(sp2Url, httpClient);
        // redirected to IdP
        redirectLocation = PicketLinkTestBase.makeCallWithoutRedirect(redirectLocation, httpClient);
        // redirected back to SP2
        redirectLocation = PicketLinkTestBase.makeCallWithoutRedirect(redirectLocation, httpClient);
        // successfully authorized in SP2
        response = PicketLinkTestBase.makeCall(redirectLocation, httpClient, 200);
        assertTrue("SP2 index page was not reached", response.contains("Welcome to SP2"));
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}
Also used : AuthScope(org.apache.http.auth.AuthScope) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) URL(java.net.URL) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Aggregations

AuthScope (org.apache.http.auth.AuthScope)103 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)64 CredentialsProvider (org.apache.http.client.CredentialsProvider)50 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)49 HttpHost (org.apache.http.HttpHost)30 Credentials (org.apache.http.auth.Credentials)25 Test (org.junit.Test)22 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 HttpResponse (org.apache.http.HttpResponse)17 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)15 HttpGet (org.apache.http.client.methods.HttpGet)14 BasicScheme (org.apache.http.impl.auth.BasicScheme)14 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)12 IOException (java.io.IOException)11 HttpEntity (org.apache.http.HttpEntity)10 AuthCache (org.apache.http.client.AuthCache)10 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)10 AuthScheme (org.apache.http.auth.AuthScheme)8 NTCredentials (org.apache.http.auth.NTCredentials)8 URL (java.net.URL)6