You should be able to use JAAS. This is what JBoss 7 should use.
The caller will be stored in a SessionContext , which you can get by telling JBoss about this resource.
@Resource private SessionContext context; public void myAwesomeMethod() { String currentUser = context.getCallerPrincipal().getName(); }
If for some reason Injection does not work on a Stateless bean, you can look for a direct EJBContext.
@Stateless public class HelloBean implements com.foo.ejb.HelloRemote { public void hello() { try { InitialContext ic = new InitialContext(); SessionContext sctxLookup = (SessionContext) ic.lookup("java:comp/EJBContext"); System.out.println("look up EJBContext by standard name: " + sctxLookup); } catch (NamingException ex) { throw new IllegalStateException(ex); } } }
This snippet was obtained from 4 ways to get an EJBContext .
source share