use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class UndertowSSLv2HelloTestCase method testTwoWayElytronClientNoSSLv2HelloSupport.
/**
* Two way SSL - Server supports SSLv2Hello, but client does not support SSLv2Hello.
* Handshake should succeed as they still share protocol TLSv1 in common.
*/
@Test
public void testTwoWayElytronClientNoSSLv2HelloSupport() throws Exception {
configureSSLContext(SSLV2HELLO_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 org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class UndertowTwoWaySslNeedClientAuthTestCase method testClientConfigProviderSSLContextIsSuccessfulWhenBasicSetOnRESTEasy.
/**
* Test situation when credentials are set on RESTEeasy client, but truststore is part of SSLContext configured for Elytron client.
* Test that Elytron SSLContext will be used successfully.
*/
@Test
public void testClientConfigProviderSSLContextIsSuccessfulWhenBasicSetOnRESTEasy() {
AuthenticationContext context = 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);
}
});
context.run(() -> {
ClientBuilder resteasyClientBuilder = ClientBuilder.newBuilder();
resteasyClientBuilder.hostnameVerifier((s, sslSession) -> true);
Client client = resteasyClientBuilder.build();
client.register(HttpAuthorization.basic("randomName", "randomPass"));
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
}
use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class UndertowTwoWaySslNeedClientAuthTestCase method testClientConfigProviderSSLContextForDifferentHostWillNotWork.
/**
* Test that RESTEasy client does choose SSLContext from Elytron client based on destination of the request.
* In this case the truststore is set for different endpoint/server and so SSL handshake will fail.
*/
@Test(expected = ProcessingException.class)
public void testClientConfigProviderSSLContextForDifferentHostWillNotWork() {
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-correct-truststore-different-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 org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class UndertowTwoWaySslNeedClientAuthTestCase method testResteasyElytronClientMissingTruststore.
/**
* RESTEasy client loads SSL Context from Elytron client config.
* This SSL Context does not have truststore configured, so exception is expected.
*/
@Test(expected = ProcessingException.class)
public void testResteasyElytronClientMissingTruststore() {
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);
}
});
context.run(() -> {
ClientBuilder resteasyClientBuilder = ClientBuilder.newBuilder();
Client client = resteasyClientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals("Hello World!", response.readEntity(String.class));
Assert.assertEquals(200, response.getStatus());
});
}
use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class UndertowTwoWaySslNeedClientAuthTestCase method testResteasyElytronClientTrustedServer.
/**
* RESTEasy client loads truststore from Elytron client configuration. This truststore contains correct server certificate.
*/
@Test
public void testResteasyElytronClientTrustedServer() {
AuthenticationContext context = 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);
}
});
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());
});
}
Aggregations