Search in sources :

Example 26 with AuthenticationContext

use of org.wildfly.security.auth.client.AuthenticationContext in project quickstart by wildfly.

the class RemoteClient method main.

public static void main(String[] args) throws Exception {
    AuthenticationConfiguration common = AuthenticationConfiguration.empty().setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("DIGEST-MD5"));
    AuthenticationConfiguration quickstartUser = common.useName("quickstartUser").usePassword("quickstartPwd1!");
    final AuthenticationContext authCtx1 = AuthenticationContext.empty().with(MatchRule.ALL, quickstartUser);
    System.out.println(authCtx1.runCallable(callable));
    AuthenticationConfiguration superUser = common.useName("quickstartAdmin").usePassword("adminPwd1!");
    final AuthenticationContext authCtx2 = AuthenticationContext.empty().with(MatchRule.ALL, superUser);
    System.out.println(authCtx2.runCallable(callable));
}
Also used : AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext)

Example 27 with AuthenticationContext

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

the class SwitchIdentityTestCase method setupAuthenticationContext.

private AuthenticationContext setupAuthenticationContext(final String username) {
    OptionMap.Builder builder = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, true);
    builder.set(Options.SASL_POLICY_NOPLAINTEXT, false);
    builder.set(Options.SASL_DISALLOWED_MECHANISMS, Sequence.of("JBOSS-LOCAL-USER"));
    final AuthenticationContext authenticationContext = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.EMPTY.useName(username == null ? "$local" : username).useRealm(null).allowSaslMechanisms("DIGEST-MD5").useMechanismProperties(getSaslProperties(builder.getMap())).useProvidersFromClassLoader(SwitchIdentityTestCase.class.getClassLoader()));
    return authenticationContext;
}
Also used : AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) OptionMap(org.xnio.OptionMap)

Example 28 with AuthenticationContext

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

the class SwitchIdentityTestCase method callUsingClientLoginModule.

// Private methods -------------------------------------------------------
/**
     * Perform the tests using the ClientLoginModule and LoginContext API to set the desired Principal.
     */
private void callUsingClientLoginModule(String userName, boolean hasRole1, boolean hasRole2) throws Exception {
    AuthenticationContext authenticationContext = setupAuthenticationContext(userName);
    authenticationContext.runCallable(() -> {
        // register the client side interceptor
        final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new ClientSecurityInterceptor());
        ejbClientContext.runCallable(() -> {
            final Manage targetBean = EJBUtil.lookupEJB(TargetBean.class, Manage.class);
            final Manage bridgeBean = EJBUtil.lookupEJB(BridgeBean.class, Manage.class);
            //test direct access
            testMethodAccess(targetBean, ManageMethodEnum.ALLROLES, true);
            testMethodAccess(targetBean, ManageMethodEnum.ROLE1, hasRole1);
            testMethodAccess(targetBean, ManageMethodEnum.ROLE2, hasRole2);
            //test security context propagation
            testMethodAccess(bridgeBean, ManageMethodEnum.ALLROLES, true);
            testMethodAccess(bridgeBean, ManageMethodEnum.ROLE1, hasRole1);
            testMethodAccess(bridgeBean, ManageMethodEnum.ROLE2, hasRole2);
            return null;
        });
        return null;
    });
}
Also used : AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) EJBClientContext(org.jboss.ejb.client.EJBClientContext)

Example 29 with AuthenticationContext

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

the class SwitchIdentityTestCase method setupAuthenticationContext.

private AuthenticationContext setupAuthenticationContext(final String username) {
    OptionMap.Builder builder = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, true);
    builder.set(Options.SASL_POLICY_NOPLAINTEXT, false);
    builder.set(Options.SASL_DISALLOWED_MECHANISMS, Sequence.of("JBOSS-LOCAL-USER"));
    final AuthenticationContext authenticationContext = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.EMPTY.useName(username == null ? "$local" : username).useRealm(null).allowSaslMechanisms("DIGEST-MD5").useMechanismProperties(getSaslProperties(builder.getMap())).useProvidersFromClassLoader(org.jboss.as.test.integration.ejb.container.interceptor.security.SwitchIdentityTestCase.class.getClassLoader()));
    return authenticationContext;
}
Also used : AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) OptionMap(org.xnio.OptionMap)

Example 30 with AuthenticationContext

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

the class UndertowSSLv2HelloTestCase method testTwoWayElytronClientServerSupportsSSLv2Hello.

/**
 * Two way SSL - RESTEasy client sends SSLv2Hello message and server supports the protocol.
 * Handshake should succeed.
 */
@Test
public void testTwoWayElytronClientServerSupportsSSLv2Hello() throws Exception {
    configureSSLContext(SSLV2HELLO_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)

Aggregations

AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)48 AuthenticationConfiguration (org.wildfly.security.auth.client.AuthenticationConfiguration)28 Client (javax.ws.rs.client.Client)24 ClientBuilder (javax.ws.rs.client.ClientBuilder)24 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)24 Test (org.junit.Test)24 Response (javax.ws.rs.core.Response)21 URL (java.net.URL)19 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)11 InvalidAuthenticationConfigurationException (org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException)11 HttpClient (org.apache.http.client.HttpClient)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 BeforeClass (org.junit.BeforeClass)6 AuthenticationContextConfigurationClient (org.wildfly.security.auth.client.AuthenticationContextConfigurationClient)6 BearerTokenCredential (org.wildfly.security.credential.BearerTokenCredential)5 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 NamingException (javax.naming.NamingException)4 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)4 OptionMap (org.xnio.OptionMap)4