use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class ClientConfigProviderBearerTokenTest method testClientWithBearerToken.
/**
* Test that bearer token is loaded from Elytron client config and is used in Authorization header.
* This is done with registered filter that checks Authorization header.
*/
@Test
public void testClientWithBearerToken() {
AuthenticationContext previousAuthContext = AuthenticationContext.getContextManager().getGlobalDefault();
try {
BearerTokenCredential bearerTokenCredential = new BearerTokenCredential("myTestToken");
AuthenticationConfiguration adminConfig = AuthenticationConfiguration.empty().useBearerTokenCredential(bearerTokenCredential);
AuthenticationContext context = AuthenticationContext.empty();
context = context.with(MatchRule.ALL, adminConfig);
AuthenticationContext.getContextManager().setGlobalDefault(context);
context.run(() -> {
ClientBuilder builder = ClientBuilder.newBuilder();
Client client = builder.build();
Response response = client.target(dummyUrl.toString()).register(ClientConfigProviderBearerTokenAbortFilter.class).request().get();
Assert.assertEquals(SC_OK, response.getStatus());
client.close();
});
} finally {
AuthenticationContext.getContextManager().setGlobalDefault(previousAuthContext);
}
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class BasicAuthnTestCase method testClientConfigProviderChooseCredentialsBasedOnDestination2.
/**
* Test that ClientConfigProvider credentials are used when specified for requested URL.
*/
@Test
public void testClientConfigProviderChooseCredentialsBasedOnDestination2(@ArquillianResource URL url) throws MalformedURLException {
final URL servletUrl = new URL(url.toExternalForm() + "role1");
AuthenticationConfiguration adminConfig = AuthenticationConfiguration.empty().useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty();
context = context.with(MatchRule.ALL.matchHost(servletUrl.getHost()), adminConfig);
context.run(() -> {
ClientBuilder builder = ClientBuilder.newBuilder();
Client client = builder.build();
Response response = client.target(servletUrl.toString()).request().get();
// will be authorized because we are calling hostname that credentials are set for
Assert.assertEquals(SC_OK, response.getStatus());
Assert.assertEquals("response was not GOOD", "GOOD", response.readEntity(String.class));
client.close();
});
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class BasicAuthnTestCase method testRESTEasyClientUsesElytronConfigAuthenticatedUser.
/**
* Test that RESTEasy client successfully uses Elytron client configuration to authenticate to the secured server with HTTP BASIC auth.
*/
@Test
public void testRESTEasyClientUsesElytronConfigAuthenticatedUser(@ArquillianResource URL url) throws MalformedURLException {
final URL servletUrl = new URL(url.toExternalForm() + "role1");
AuthenticationConfiguration adminConfig = AuthenticationConfiguration.empty().useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty();
context = context.with(MatchRule.ALL, adminConfig);
context.run(() -> {
ClientBuilder builder = ClientBuilder.newBuilder();
Client client = builder.build();
Response response = client.target(servletUrl.toString()).request().get();
Assert.assertEquals(SC_OK, response.getStatus());
client.close();
});
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class BasicAuthnTestCase method testClientConfigProviderChooseCredentialsBasedOnDestination.
/**
* Test that Elytron config credentials are not used when specified for different destination of the request.
*/
@Test
public void testClientConfigProviderChooseCredentialsBasedOnDestination(@ArquillianResource URL url) throws MalformedURLException {
final URL servletUrl = new URL(url.toExternalForm() + "role1");
AuthenticationConfiguration adminConfig = AuthenticationConfiguration.empty().useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty();
context = context.with(MatchRule.ALL.matchHost("www.some-example.com"), adminConfig);
context.run(() -> {
ClientBuilder builder = ClientBuilder.newBuilder();
Client client = builder.build();
Response response = client.target(servletUrl.toString()).request().get();
// will be unauthorized because credentials were set for different hostname than we are calling
Assert.assertEquals(SC_UNAUTHORIZED, response.getStatus());
client.close();
});
}
use of javax.ws.rs.client.ClientBuilder in project Payara by payara.
the class ProxyImpl method addAuthenticationInfo.
/**
* Use SSL to authenticate
*/
private Client addAuthenticationInfo(Client client, Server server, ServiceLocator habitat) {
SecureAdmin secureAdmin = habitat.getService(SecureAdmin.class);
// TODO need to get hardcoded "TLS" from corresponding ServerRemoteAdminCommand constant);
final SSLContext sslContext = habitat.<SSLUtils>getService(SSLUtils.class).getAdminSSLContext(SecureAdmin.Util.DASAlias(secureAdmin), "TLS");
// Instruct Jersey to use HostNameVerifier and SSLContext provided by us.
final ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(client.getConfiguration()).hostnameVerifier(new BasicHostnameVerifier(server.getAdminHost())).sslContext(sslContext);
return clientBuilder.build();
}
Aggregations