users@glassfish.java.net

Re: Retrieving "logged in" username inside a session bean

From: <glassfish_at_javadesktop.org>
Date: Wed, 28 Jan 2009 09:16:47 PST

Aleksandras,

Thanks for the reply. When I add your code to my EJB, I include:

import com.sun.enterprise.security.auth.login.PasswordCredential;
import java.security.AccessController;
import java.security.AccessControlContext;
import javax.security.auth.Subject;
...

AccessControlContext ctx = AccessController.getContext();
System.out.println("Access Controller Context = " + ctx);

Subject subject = Subject.getSubject(ctx);
System.out.println("Subject = " + subject);

I created a user in the file realm - testuser/1testuser2

In my standalone/external java client, I "log into" the server using:

Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.enterprise.naming.SerialInitContextFactory");
env.put("org.omg.CORBA.ORBInitialPort", "3700");
env.put("org.omg.CORBA.ORBInitialHost", "localhost");
env.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
env.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

env.put(Context.SECURITY_PRINCIPAL, "testuser");
env.put(Context.SECURITY_CREDENTIALS, "1testuser2");

Context ic = new InitialContext(env);

When I call the getCurrentUserName() function from my client, the Access Controller Context exists, but the call to getSubject returns null.

Any thoughts???

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

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