users@glassfish.java.net

Re: EJB, Realms and Remote Clients

From: <glassfish_at_javadesktop.org>
Date: Thu, 24 Dec 2009 09:01:10 PST

Hi,

I think Glassfish v3 ignores "security" properties for InitialContext, and still doesn't support client authentication to remote EJBs with the usual LoginContext class (JAAS API).

But you can still authenticate standalone Java applications to Glassfish v3 server with its propietary "com.sun.appserv.security.ProgrammaticLogin" class (provided in "GF_HOME/glassfish/modules/security.jar" library). For example:

[code]
...
import com.sun.appserv.security.ProgrammaticLogin;
...
// System.setProperty("java.security.auth.login.config", "./auth.conf");
ProgrammaticLogin programmaticLogin = new ProgrammaticLogin();
programmaticLogin.login("Dave", "password");

InitialContext ctx = new InitialContext();
BusinessInterfaceRemote bean = (BusinessInterfaceRemote) ctx.lookup("java:global/StDavidEEA/StDavidEJB-ejb/BusinessInterface'");

bean.methodCall1();
bean.methodCall2();

programmaticLogin.logout();
...
[/code]


The ProgrammaticLogin class requires a "JAAS login configuration file" in the client application, with a "default" login module for user/password authentication (independently of the realm name of the remote EJB). For example, create a file with the name "auth.conf" with the content:

[code]
default {
        com.sun.enterprise.security.auth.login.ClientPasswordLoginModule required debug=false;
};
[/code]

And finally, set the "java.security.auth.login.config" system property with the correct "auth.conf" file path. For example, in the application code (as commented before), or in the java command line:

[code]
$ java -Djava.security.auth.login.config=./auth.conf -cp $GF_HOME/glassfish/modules/gf-client.jar:TheApplication.jar TheApplicationMainClassName
[/code]

Good luck.
[Message sent by forum member 'jmarine' (jmarine_at_tinet.org)]

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