use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowSSLv2HelloTestCase method testTwoWayElytronServerClientDefaultConfig.
/**
* Two Way SSL - Client and Server don't support SSLv2Hello as it has not been explicitly configured.
* They each have their default configuration. Handshake should succeed.
*/
@Test
public void testTwoWayElytronServerClientDefaultConfig() throws Exception {
configureSSLContext(DEFAULT_CONTEXT);
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-no-sslv2hello.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder clientBuilder = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true);
Client client = clientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
restoreConfiguration();
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowSSLv2HelloTestCase method testTwoWayElytronServerNoSSLv2HelloSupport.
/**
* Two way SSL - Server does not support SSLv2Hello, but client sends SSLv2Hello message.
* Handshake should fail.
*/
@Test(expected = ProcessingException.class)
public void testTwoWayElytronServerNoSSLv2HelloSupport() throws Exception {
configureSSLContext(DEFAULT_CONTEXT);
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-sslv2hello.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder clientBuilder = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true);
Client client = clientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
restoreConfiguration();
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowTwoWaySslNeedClientAuthTestCase method testClientConfigProviderSSLContextForCorrectHostWillWork.
/**
* Test that RESTEasy client does choose SSLContext from Elytron client based on destination of the request.
* In this case the truststore is set for correct endpoint/server and so SSL handshake will succeed.
*/
@Test
public void testClientConfigProviderSSLContextForCorrectHostWillWork() {
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-correct-truststore-correct-host.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder resteasyClientBuilder = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true);
Client client = resteasyClientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowTwoWaySslNeedClientAuthTestCase method testClientConfigProviderSSLContextIgnoredIfDifferentIsSet.
/**
* Elytron client has configured truststore that does not contain server's certificate.
* Test will pass because Elytron config is ignored since different ssl context is specified on RESTEasy client builder specifically.
*/
@Test
public void testClientConfigProviderSSLContextIgnoredIfDifferentIsSet() throws URISyntaxException, GeneralSecurityException {
AuthenticationContextConfigurationClient AUTH_CONTEXT_CLIENT = AccessController.doPrivileged((PrivilegedAction<AuthenticationContextConfigurationClient>) AuthenticationContextConfigurationClient::new);
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-correct-truststore-missing.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
AuthenticationContext contextWithTruststore = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-correct-truststore.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
SSLContext sslContext = AUTH_CONTEXT_CLIENT.getSSLContext(securedRootUrl.toURI(), contextWithTruststore);
context.run(() -> {
ClientBuilder resteasyClientBuilder = ClientBuilder.newBuilder();
resteasyClientBuilder.sslContext(sslContext).hostnameVerifier((s, sslSession) -> true);
Client client = resteasyClientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class ClientConfigProviderBearerTokenTest method testClientChooseCorrectBearerToken2.
/**
* Test that request does choose credentials based on destination of the request.
* Test will succeed since Bearer token was set on requested URL.
*/
@Test
public void testClientChooseCorrectBearerToken2() {
BearerTokenCredential bearerTokenCredential = new BearerTokenCredential("myTestToken");
AuthenticationConfiguration authenticationConfiguration = AuthenticationConfiguration.empty().useBearerTokenCredential(bearerTokenCredential);
AuthenticationContext context = AuthenticationContext.empty();
context = context.with(MatchRule.ALL.matchHost("127.0.0.1"), authenticationConfiguration);
context.run(() -> {
ClientBuilder builder = ClientBuilder.newBuilder();
Client client = builder.build();
Response response = client.target("http://127.0.0.1").register(ClientConfigProviderBearerTokenAbortFilter.class).request().get();
Assert.assertEquals(SC_OK, response.getStatus());
client.close();
});
}
Aggregations