log.debug("+++ testGetCallerPrincipal()");
Object obj = getInitialContext().lookup("spec.UnsecureStatelessSession2");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
log.debug("Found Unsecure StatelessSessionHome");
StatelessSession bean = home.create();
log.debug("Created spec.UnsecureStatelessSession2");
try
{
// This should fail because echo calls getCallerPrincipal()
bean.echo("Hello from nobody?");
fail("Was able to call StatelessSession.echo");
}
catch (RemoteException e)
{
log.debug("echo failed as expected");
}
bean.remove();
login();
obj = getInitialContext().lookup("spec.StatelessSession2");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
home = (StatelessSessionHome) obj;
log.debug("Found spec.StatelessSession2");
bean = home.create();
log.debug("Created spec.StatelessSession2");
// Test that the Entity bean sees username as its principal
String echo = bean.echo(username);
log.debug("bean.echo(username) = " + echo);
assertTrue("username == echo", echo.equals(username));
bean.remove();
}