Search in sources :

Example 1 with SimplePrincipal

use of org.jboss.resteasy.plugins.server.embedded.SimplePrincipal in project wildfly by wildfly.

the class SwitchIdentityTestCase method callUsingSecurityContextAssociation.

/**
     * Perform the tests using the SecurityContextAssociation API to set the desired Principal.
     */
private void callUsingSecurityContextAssociation(String userName, boolean hasRole1, boolean hasRole2) throws Exception {
    try {
        final Properties ejbClientConfiguration = EJBUtil.createEjbClientConfiguration(Utils.getHost(mgmtClient), userName);
        // register the client side interceptor
        final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new org.jboss.as.test.integration.ejb.container.interceptor.security.ClientSecurityInterceptor());
        SecurityContextAssociation.setPrincipal(new SimplePrincipal(userName));
        ejbClientContext.runCallable(() -> {
            final Manage targetBean = EJBUtil.lookupEJB(ejbClientConfiguration, TargetBean.class, Manage.class);
            final Manage bridgeBean = EJBUtil.lookupEJB(ejbClientConfiguration, 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;
        });
    } finally {
        SecurityContextAssociation.clearSecurityContext();
    }
}
Also used : EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) SimplePrincipal(org.jboss.resteasy.plugins.server.embedded.SimplePrincipal)

Example 2 with SimplePrincipal

use of org.jboss.resteasy.plugins.server.embedded.SimplePrincipal in project wildfly by wildfly.

the class SwitchIdentityTestCase method callUsingSecurityContextAssociation.

/**
     * Perform the tests using the SecurityContextAssociation API to set the desired Principal.
     */
private void callUsingSecurityContextAssociation(String userName, boolean hasRole1, boolean hasRole2) throws Exception {
    try {
        final Properties ejbClientConfiguration = EJBUtil.createEjbClientConfiguration(Utils.getHost(mgmtClient), userName);
        // register the client side interceptor
        final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new ClientSecurityInterceptor());
        SecurityContextAssociation.setPrincipal(new SimplePrincipal(userName));
        ejbClientContext.runCallable(() -> {
            final Manage targetBean = EJBUtil.lookupEJB(ejbClientConfiguration, TargetBean.class, Manage.class);
            final Manage bridgeBean = EJBUtil.lookupEJB(ejbClientConfiguration, 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;
        });
    } finally {
        SecurityContextAssociation.clearSecurityContext();
    }
}
Also used : EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) SimplePrincipal(org.jboss.resteasy.plugins.server.embedded.SimplePrincipal)

Aggregations

Properties (java.util.Properties)2 EJBClientContext (org.jboss.ejb.client.EJBClientContext)2 SimplePrincipal (org.jboss.resteasy.plugins.server.embedded.SimplePrincipal)2