Search in sources :

Example 1 with PartialDDBean

use of org.jboss.as.test.integration.ejb.security.dd.override.PartialDDBean in project wildfly by wildfly.

the class SecurityDDOverrideTestCase method testDDOverride.

/**
     * Tests that the overriden roles allowed, via ejb-jar.xml, on an EJB method are taken into account for EJB method
     * invocations
     *
     * @throws Exception
     */
@Test
public void testDDOverride() throws Exception {
    final Context ctx = new InitialContext();
    final PartialDDBean partialDDBean = (PartialDDBean) ctx.lookup("java:module/" + PartialDDBean.class.getSimpleName() + "!" + PartialDDBean.class.getName());
    try {
        partialDDBean.denyAllMethod();
        Assert.fail("Call to denyAllMethod() was expected to fail");
    } catch (EJBAccessException ejbae) {
    // expected
    }
    // expected to pass
    partialDDBean.permitAllMethod();
    // login as user1 and test
    LoginContext lc = Util.getCLMLoginContext("user1", "password1");
    lc.login();
    try {
        // expected to pass since user1 belongs to Role1
        partialDDBean.toBeInvokedOnlyByRole1();
        // expected to fail since user1 *doesn't* belong to Role2
        try {
            partialDDBean.toBeInvokedByRole2();
            Assert.fail("Call to toBeInvokedByRole2() was expected to fail");
        } catch (EJBAccessException ejbae) {
        // expected
        }
    } finally {
        lc.logout();
    }
    // login as user2 and test
    lc = Util.getCLMLoginContext("user2", "password2");
    lc.login();
    try {
        // expected to pass since user2 belongs to Role2
        partialDDBean.toBeInvokedByRole2();
        // expected to fail since user2 *doesn't* belong to Role1
        try {
            partialDDBean.toBeInvokedOnlyByRole1();
            Assert.fail("Call to toBeInvokedOnlyByRole1() was expected to fail");
        } catch (EJBAccessException ejbae) {
        // expected
        }
    } finally {
        lc.logout();
    }
}
Also used : InitialContext(javax.naming.InitialContext) LoginContext(javax.security.auth.login.LoginContext) Context(javax.naming.Context) LoginContext(javax.security.auth.login.LoginContext) PartialDDBean(org.jboss.as.test.integration.ejb.security.dd.override.PartialDDBean) InitialContext(javax.naming.InitialContext) EJBAccessException(javax.ejb.EJBAccessException) Test(org.junit.Test)

Aggregations

EJBAccessException (javax.ejb.EJBAccessException)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 LoginContext (javax.security.auth.login.LoginContext)1 PartialDDBean (org.jboss.as.test.integration.ejb.security.dd.override.PartialDDBean)1 Test (org.junit.Test)1