Friday, March 18, 2011

MDB RunAs

If you get a
"No valid security context for the caller identity"


when your MDB is run, you can either annotate it with:

http://download.oracle.com/javaee/5/api/javax/annotation/security/RunAs.html


or, on JBoss, with

http://docs.jboss.org/ejb3/embedded/api/org/jboss/annotation/security/RunAsPrincipal.html

otherwise you can:

InitialContext ic = new InitialContext();
SessionContext sc = (SessionContext) ic.lookup("java:comp/EJBContext");
Principal p = sc.getCallerPrincipal();


(you can also use @Resource and have the container inject the EJBContext)

but this will not allow you to change principal on the go...

here the Principal javadoc

No comments: