}
private static void testStateless() throws Exception
{
InitialContext jndiContext = new InitialContext();
StatelessTest stateless = (StatelessTest) jndiContext.lookup("StatelessTest");
SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
securityClient.setSimple("bill2", "invalidpassword");
securityClient.login();
try
{
stateless.testSecurity();
throw new RuntimeException("ERROR - User with incorrect password accessed the bean");
}
catch (javax.ejb.EJBAccessException e)
{
System.out.println("Caught javax.ejb.EJBAccessException, for SLSB, as expected");
}
// logout and login back with correct credentials
System.out.println("Now passing the correct user/password to access the SLSB");
securityClient.logout();
securityClient.setSimple("bill2", "password-default");
securityClient.login();
// call the bean method
stateless.testSecurity();
System.out.println("Successfully accessed SLSB");
}