users@glassfish.java.net

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

From: Aleksandras Novikovas <an_at_systemtier.com>
Date: Wed, 28 Jan 2009 19:59:05 +0200

Hi,

Regarding imports: you are right - i did not include imports from java.*
and javax.*

getCurrentUserName() method supposed to work on server - not on client.

BTW: Security manager on server should be ON.


On client (stand alone application) I use JAAS with own
javax.security.auth.spi.LoginModule and
javax.security.auth.callback.CallbackHandler implementations.



-
Aleksandras Novikovas




On Wed, 2009-01-28 at 09:16 -0800, glassfish_at_javadesktop.org wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>