Search in sources :

Example 1 with InitialContext

use of org.jboss.as.naming.InitialContext in project wildfly by wildfly.

the class RunAsWithElytronEJBContextPropagationTestCase method initContext.

private InitialContext initContext() {
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
    props.put(Context.PROVIDER_URL, "remote+http://" + TestSuiteEnvironment.getServerAddress() + ":8080");
    props.put(Context.SECURITY_PRINCIPAL, USERNAME);
    props.put(Context.SECURITY_CREDENTIALS, PASSWORD);
    try {
        return new InitialContext(props);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
}
Also used : WildFlyInitialContextFactory(org.wildfly.naming.client.WildFlyInitialContextFactory) NamingException(javax.naming.NamingException) Properties(java.util.Properties) InitialContext(org.jboss.as.naming.InitialContext)

Example 2 with InitialContext

use of org.jboss.as.naming.InitialContext in project wildfly by wildfly.

the class ElytronRemoteOutboundConnectionTestCase method callIntermediateWhoAmI.

private String callIntermediateWhoAmI(boolean useRestrictedMethod) {
    AuthenticationConfiguration common = AuthenticationConfiguration.empty().useProviders(() -> new Provider[] { new WildFlyElytronProvider() }).setSaslMechanismSelector(SaslMechanismSelector.ALL);
    AuthenticationContext authCtxEmpty = AuthenticationContext.empty();
    final AuthenticationContext authCtx = authCtxEmpty.with(MatchRule.ALL, common);
    final EJBClientContext.Builder ejbClientBuilder = new EJBClientContext.Builder();
    ejbClientBuilder.addTransportProvider(new RemoteTransportProvider());
    final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
    connBuilder.setDestination(URI.create("remote+http://" + TestSuiteEnvironment.getServerAddressNode1() + ":8180"));
    ejbClientBuilder.addClientConnection(connBuilder.build());
    final EJBClientContext ejbCtx = ejbClientBuilder.build();
    AuthenticationContext.getContextManager().setThreadDefault(authCtx);
    EJBClientContext.getContextManager().setThreadDefault(ejbCtx);
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
    String result;
    try {
        InitialContext ctx = new InitialContext(props);
        String lookupName = "ejb:/outbound-module/IntermediateWhoAmI!org.jboss.as.test.manualmode.ejb.client.outbound.connection.security.WhoAmI";
        WhoAmI intermediate = (WhoAmI) ctx.lookup(lookupName);
        if (useRestrictedMethod) {
            result = intermediate.whoAmIRestricted();
        } else {
            result = intermediate.whoAmI();
        }
        ctx.close();
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    return result;
}
Also used : AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) WildFlyInitialContextFactory(org.wildfly.naming.client.WildFlyInitialContextFactory) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) OperationBuilder(org.jboss.as.controller.client.OperationBuilder) EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) InitialContext(org.jboss.as.naming.InitialContext) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) Provider(java.security.Provider) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider) EJBClientConnection(org.jboss.ejb.client.EJBClientConnection) NamingException(javax.naming.NamingException) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider)

Example 3 with InitialContext

use of org.jboss.as.naming.InitialContext in project wildfly by wildfly.

the class RunAsWithElytronEJBContextPropagationTestCase method testRunAsWithElytronEJBContextPropagation.

/**
 * Test that checks the first EJB is called by admin role, same user is used to call the second EJB were the role does not
 * change.
 *
 * The test uses http-remoting protocol.
 */
@Test
public void testRunAsWithElytronEJBContextPropagation() {
    InitialContext context = initContext();
    IntermediateCallerInRoleRemote intermediate;
    try {
        intermediate = (IntermediateCallerInRoleRemote) context.lookup("ejb:/ejb-security-context-propagation/IntermediateCallerInRole!" + IntermediateCallerInRoleRemote.class.getName());
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    Assert.assertFalse(intermediate.isCallerInRole(ROLE));
    Assert.assertTrue(intermediate.isServerCallerInRole(ROLE));
    closeContext(context);
}
Also used : NamingException(javax.naming.NamingException) InitialContext(org.jboss.as.naming.InitialContext) Test(org.junit.Test)

Aggregations

NamingException (javax.naming.NamingException)3 InitialContext (org.jboss.as.naming.InitialContext)3 Properties (java.util.Properties)2 WildFlyInitialContextFactory (org.wildfly.naming.client.WildFlyInitialContextFactory)2 Provider (java.security.Provider)1 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)1 EJBClientConnection (org.jboss.ejb.client.EJBClientConnection)1 EJBClientContext (org.jboss.ejb.client.EJBClientContext)1 RemoteTransportProvider (org.jboss.ejb.protocol.remote.RemoteTransportProvider)1 Test (org.junit.Test)1 WildFlyElytronProvider (org.wildfly.security.WildFlyElytronProvider)1 AuthenticationConfiguration (org.wildfly.security.auth.client.AuthenticationConfiguration)1 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)1