Hashtable env = new Hashtable();
env.put(Context.SECURITY_PRINCIPAL, "scott");
env.put(Context.SECURITY_CREDENTIALS, "invalidpassword");
InitialContext ctx = new InitialContext(env);
Secured secured = (Secured)ctx.lookup("SecuredBean/local");
boolean exceptionThrown = false;
try
{
secured.allowed();
}
catch (EJBAccessException ignored)
{
exceptionThrown = true;
}
assertTrue("Security exception not thrown for invalid password", exceptionThrown);
env.put(Context.SECURITY_CREDENTIALS, "password");
ctx = new InitialContext(env);
secured.allowed();
exceptionThrown = false;
try
{
secured.nobody();
}
catch (EJBAccessException ignored)
{
exceptionThrown = true;
}