users@glassfish.java.net

Retrieving "logged in" username inside a session bean

From: <glassfish_at_javadesktop.org>
Date: Mon, 26 Jan 2009 06:42:49 PST

I have a long history with BEA WebLogic but am I relative newcomer to Glassfish. One Weblogic capability I used extensively was to retrieve the username from the system and use it to provide access control as well as data marking (createor/updater/etc). This prevented me from having to pass around "username" to all my EJB methods.

import weblogic.security.Security;
import weblogic.security.SubjectUtils;
import javax.security.auth.Subject;

public String whoAmI() {
      Subject s = new Security().getCurrentSubject();
      return SubjectUtils.getUsername(s);
}

As ypu can see, the example utilizes 2 weblogic specific packages.

Does Glassfish provide this capability?

Thanks,

Joe
[Message sent by forum member 'janchj' (janchj)]

http://forums.java.net/jive/thread.jspa?messageID=328170