Search in sources :

Example 1 with InvalidAuthenticationConfigurationException

use of org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException in project wildfly by wildfly.

the class UndertowSSLv2HelloTestCase method testOneWayElytronClientServerSupportsSSLv2Hello.

/**
 * One way SSL - RESTEasy client sends SSLv2Hello message and server supports the protocol.
 * Handshake should succeed.
 */
@Test
public void testOneWayElytronClientServerSupportsSSLv2Hello() throws Exception {
    configureSSLContext(SSLV2HELLO_CONTEXT_ONE_WAY);
    AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
        try {
            URL config = getClass().getResource("wildfly-config-one-way-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();
}
Also used : Response(javax.ws.rs.core.Response) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) InvalidAuthenticationConfigurationException(org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException) Client(javax.ws.rs.client.Client) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) URL(java.net.URL) ClientBuilder(javax.ws.rs.client.ClientBuilder) Test(org.junit.Test)

Example 2 with InvalidAuthenticationConfigurationException

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

Example 3 with InvalidAuthenticationConfigurationException

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

Example 4 with InvalidAuthenticationConfigurationException

use of org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException 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());
    });
}
Also used : Response(javax.ws.rs.core.Response) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) InvalidAuthenticationConfigurationException(org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException) 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)

Example 5 with InvalidAuthenticationConfigurationException

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