Search in sources :

Example 1 with ClientConfigProviderNoBasicAuthorizationHeaderFilter

use of org.wildfly.test.integration.elytron.util.ClientConfigProviderNoBasicAuthorizationHeaderFilter in project wildfly by wildfly.

the class BasicAuthnTestCase method testClientConfigProviderUsernameWithoutPasswordWillBeIgnored.

/**
 * Test that access credentials from ClientConfigProvider are used only if both username and password are present.
 */
@Test
public void testClientConfigProviderUsernameWithoutPasswordWillBeIgnored(@ArquillianResource URL url) throws MalformedURLException {
    final URL servletUrl = new URL(url.toExternalForm() + "role1");
    AuthenticationConfiguration adminConfig = AuthenticationConfiguration.empty().useName("thisNameWillBeIgnoredBecausePasswordIsMissing");
    AuthenticationContext context = AuthenticationContext.empty();
    context = context.with(MatchRule.ALL, adminConfig);
    context.run(() -> {
        ClientBuilder builder = ClientBuilder.newBuilder();
        Client client = builder.build();
        client.register(new ClientConfigProviderNoBasicAuthorizationHeaderFilter(), Priorities.USER);
        try {
            client.target(servletUrl.toString()).request().get();
        } catch (Exception e) {
            assertTrue(e.getMessage().contains("The request authorization header is not correct expected:<Bearer myTestToken> but was:<null>"));
            client.close();
        }
        Response response = builder.build().target(servletUrl.toString()).request().get();
        Assert.assertEquals(SC_UNAUTHORIZED, response.getStatus());
        client.close();
    });
}
Also used : AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) Response(javax.ws.rs.core.Response) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) ClientConfigProviderNoBasicAuthorizationHeaderFilter(org.wildfly.test.integration.elytron.util.ClientConfigProviderNoBasicAuthorizationHeaderFilter) Client(javax.ws.rs.client.Client) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ClientBuilder(javax.ws.rs.client.ClientBuilder) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Client (javax.ws.rs.client.Client)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Response (javax.ws.rs.core.Response)1 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)1 Test (org.junit.Test)1 AuthenticationConfiguration (org.wildfly.security.auth.client.AuthenticationConfiguration)1 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)1 ClientConfigProviderNoBasicAuthorizationHeaderFilter (org.wildfly.test.integration.elytron.util.ClientConfigProviderNoBasicAuthorizationHeaderFilter)1