Retrieving user name from inside each bean.

Riccardo Bongiovanni

How can I retrive from inside my Bean (Stateless Session and Entity CMP) the user name which I'm serving (the user name of user just logged in my web application)?
I need to know user name because I have a "logger Class" in my enterprise application that automatically generates logs files for tracking transactions for each user that logs in.

Inside an EJB you may retrieve the "Caller" name, that is the login id by invoking:
where sessionContext is the instance of "SessionContext" (setSessionContext) passed to the Session Bean, or the instance of "EntityContext" (setEntityContext) passed to the Entity Bean.