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());
}
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();
}
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;
}
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);
}
}
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();
}
}
Aggregations