Search in sources :

Example 1 with AuthenticationContextConfigurationClient

use of org.wildfly.security.auth.client.AuthenticationContextConfigurationClient 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());
    });
}
Also used : Response(javax.ws.rs.core.Response) AuthenticationContextConfigurationClient(org.wildfly.security.auth.client.AuthenticationContextConfigurationClient) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) InvalidAuthenticationConfigurationException(org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException) SSLContext(javax.net.ssl.SSLContext) AuthenticationContextConfigurationClient(org.wildfly.security.auth.client.AuthenticationContextConfigurationClient) Client(javax.ws.rs.client.Client) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) HttpClient(org.apache.http.client.HttpClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) URL(java.net.URL) ClientBuilder(javax.ws.rs.client.ClientBuilder) Test(org.junit.Test)

Aggregations

URL (java.net.URL)1 SSLContext (javax.net.ssl.SSLContext)1 Client (javax.ws.rs.client.Client)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Response (javax.ws.rs.core.Response)1 HttpClient (org.apache.http.client.HttpClient)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1 Test (org.junit.Test)1 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)1 AuthenticationContextConfigurationClient (org.wildfly.security.auth.client.AuthenticationContextConfigurationClient)1 InvalidAuthenticationConfigurationException (org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException)1