use of javax.ejb.EJBAccessException in project wildfly by wildfly.
the class AnnSBTest method testSingleMethodAnnotationsUser2Template.
/**
* Test objective:
* Check if default, @RolesAllowed, @PermitAll, @DenyAll and @RolesAllowed with multiple roles
* works on method level with user1 logged in as described in EJB 3.1 spec.
* user2 has "Users,Role2" roles.
* The target session bean is given as parameter.
* Expected results:
* Test has to finish without any exception or error.
* <p/>
*
* @throws Exception
*/
public void testSingleMethodAnnotationsUser2Template(final String MODULE, final Logger log, final Class SB_CLASS) throws Exception {
final Context ctx = Util.createNamingContext();
final AuthenticationContext authenticationContext = setupAuthenticationContext("user2", "password2");
authenticationContext.runCallable(() -> {
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).defaultAccess("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (EJBAccessException e) {
Assert.fail("EJBAccessException not expected");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessOne("alohomora");
Assert.fail("Method cannot be successfully called with logged in user2");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was different", e instanceof EJBAccessException);
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessMore("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (EJBAccessException e) {
Assert.fail("EJBAccessException not expected");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).permitAll("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (Exception e) {
Assert.fail("@PermitAll annotation must allow all users and no users to call the method - principal.");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).denyAll("alohomora");
Assert.fail("@DenyAll annotation must allow all users and no users to call the method");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was different", e instanceof EJBAccessException);
}
return null;
});
}
use of javax.ejb.EJBAccessException in project wildfly by wildfly.
the class AnnSBTest method testSingleMethodAnnotationsNoUserTemplate.
/**
* Test objective:
* Check if default, @RolesAllowed, @PermitAll, @DenyAll and @RolesAllowed with multiple roles
* works on method level without user logged in as described in EJB 3.1 spec.
* The target session bean is given as parameter
* Expected results:
* Test has to finish without any exception or error.
*
* @throws Exception
*/
public void testSingleMethodAnnotationsNoUserTemplate(final String MODULE, final Logger log, final Class SB_CLASS) throws Exception {
final Context ctx = Util.createNamingContext();
final AuthenticationContext authenticationContext = setupAuthenticationContext("$local", null);
authenticationContext.runCallable(() -> {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).defaultAccess("alohomora");
Assert.assertEquals(echoValue, "alohomora");
try {
echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessOne("alohomora");
Assert.fail("Method cannot be successfully called without logged in user");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was " + e.getClass().getSimpleName(), e instanceof EJBAccessException);
}
try {
echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessMore("alohomora");
Assert.fail("Method cannot be successfully called without logged in user");
} catch (EJBAccessException e) {
// expected
}
try {
echoValue = getBean(MODULE, log, SB_CLASS, ctx).permitAll("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (Exception e) {
Assert.fail("@PermitAll annotation must allow all users and no users to call the method");
}
try {
echoValue = getBean(MODULE, log, SB_CLASS, ctx).denyAll("alohomora");
Assert.fail("@DenyAll annotation must allow all users and no users to call the method");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was " + e.getClass().getSimpleName(), e instanceof EJBAccessException);
}
return null;
});
}
use of javax.ejb.EJBAccessException in project wildfly by wildfly.
the class AnnSBTest method testSingleMethodAnnotationsUser1Template.
/**
* Test objective:
* Check if default, @RolesAllowed, @PermitAll, @DenyAll and @RolesAllowed with multiple roles
* works on method level with user1 logged in as described in EJB 3.1 spec.
* user1 has "Users,Role1" roles.
* The target session bean is given as parameter.
* Expected results:
* Test has to finish without any exception or error.
* <p/>
*
* @throws Exception
*/
public void testSingleMethodAnnotationsUser1Template(final String MODULE, final Logger log, final Class SB_CLASS) throws Exception {
final Context ctx = Util.createNamingContext();
final AuthenticationContext authenticationContext = setupAuthenticationContext("user1", "password1");
authenticationContext.runCallable(() -> {
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).defaultAccess("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (EJBAccessException e) {
Assert.fail("EJBAccessException not expected");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessOne("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (EJBAccessException e) {
Assert.fail("EJBAccessException not expected");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessMore("alohomora");
Assert.fail("Method cannot be successfully called with logged in principal.");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was different", e instanceof EJBAccessException);
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).permitAll("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (Exception e) {
Assert.fail("@PermitAll annotation must allow all users and no users to call the method - principal.");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).denyAll("alohomora");
Assert.fail("@DenyAll annotation must allow all users and no users to call the method");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was different", e instanceof EJBAccessException);
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).starRoleAllowed("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (Exception e) {
Assert.fail("@RolesAllowed(\"**\") annotation must allow all authenticated users to the method.");
}
return null;
});
}
use of javax.ejb.EJBAccessException in project wildfly by wildfly.
the class AnnotationAuthorizationTestCase method testRolesAllowedOverriden_User2.
@Test
public void testRolesAllowedOverriden_User2() throws Exception {
LoginContext lc = Util.getCLMLoginContext("user2", "password2");
lc.login();
try {
try {
rolesAllowedOverridenBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
try {
rolesAllowedOverridenBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = rolesAllowedOverridenBean.permitAllEcho("3");
assertEquals("3", response);
response = rolesAllowedOverridenBean.role2Echo("4");
assertEquals("4", response);
} finally {
lc.logout();
}
}
use of javax.ejb.EJBAccessException in project wildfly by wildfly.
the class AnnotationAuthorizationTestCase method testRolesAllowedOverriden_User1.
@Test
public void testRolesAllowedOverriden_User1() throws Exception {
LoginContext lc = Util.getCLMLoginContext("user1", "password1");
lc.login();
try {
String response = rolesAllowedOverridenBean.defaultEcho("1");
assertEquals("1", response);
try {
rolesAllowedOverridenBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
response = rolesAllowedOverridenBean.permitAllEcho("3");
assertEquals("3", response);
try {
rolesAllowedOverridenBean.role2Echo("4");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
} finally {
lc.logout();
}
}
Aggregations