users@glassfish.java.net

GWT Development Mode Programmatic Login problem

From: <forums_at_java.net>
Date: Tue, 5 Apr 2011 02:17:50 -0500 (CDT)

I’m quite new to glassfish and EJB but I’m trying to develop application
using EJB3, glassfish v3.1 and GWT. I managed to create EJB bean protected by
@RollesAllowed annotations and when I deploy both beans and GWT client to the
application server everything works just perfect. But when I’m trying to
access remote bean from development(hosted) mode I encounter problems during
authentication.

 

 

Here is some code that will explain what I’m trying to do.

Bean definition:
[php] @Stateless(name = "remoteAuthServiceBean")
@Remote(AuthorizationServiceRemote.class) @DeclareRoles( { "USER", "ADMIN" })
public class RemoteAuthorizationServiceBean implements AuthorizationService {
@RolesAllowed("ADMIN") public String getAdminWelcome() { return
"AuthorizationService: AccessLevel: ADMIN"; }
@PermitAll public String getAnonymousWelcome() { return
"AuthorizationService: AccessLevel: PermitAll"; }
@RolesAllowed( { "ADMIN", "USER" }) public String getUserWelcome() { return
"AuthorizationService: AccessLevel: USER"; } } [/php] Example of standalone
client code. (gf-client.jar (from glassfish lib dir) and auth-ejb-client.jar
included in build path) [php] public class ClientStarter { static {
System.setProperty("java.security.auth.login.config", "login.conf"); }
public static void main(String[] args) { Context ctx = null; try { try {
ProgrammaticLoginInterface loginCtx = new ProgrammaticLogin();
loginCtx.login("admin", "pass"); } catch (Exception e) { e.printStackTrace();
}
ctx = getInitialContext();
try { AuthorizationService authService = (AuthorizationService)
ctx.lookup(AuthorizationServiceRemote.class.getName());
try { System.out.println(authService.getAnonymousWelcome()); } catch
(Exception e) { e.printStackTrace(); }
try { System.out.println(authService.getUserWelcome()); } catch (Exception e)
{ e.printStackTrace(); }
try { System.out.println(authService.getAdminWelcome()); } catch (Exception
e) { e.printStackTrace(); } } catch (NamingException e) { } } catch
(Exception e) { e.printStackTrace(); } }
private static Context getInitialContext() throws NamingException {
Properties props = new Properties(); try { props.load(new
FileInputStream("jndi.properties"));
props.setProperty(Context.SECURITY_PRINCIPAL, "admin");
props.setProperty(Context.SECURITY_CREDENTIALS, "pass"); } catch
(FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) {
e.printStackTrace(); }
return new InitialContext(props); } } [/php] JNDI properties [php]
java.naming.factory.initial =
com.sun.enterprise.naming.impl.SerialInitContextFactory
java.naming.factory.url.pkgs = com.sun.enterprise.naming
java.naming.factory.state =
com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
org.omg.CORBA.ORBInitialHost = 192.168.1.104 org.omg.CORBA.ORBInitialPort =
3700 [/php] login.conf [php] default {
com.sun.enterprise.security.auth.login.LDAPLoginModule required; }; [/php]
When I run code shown in ClientStarter class as a part of servlet code in GWT
client deployed on glassfish v3.1 it works as expected. But when I try to run
it as standalone application or in developement mode I'm receving following
error [php] 2011-04-05 09:06:46
com.sun.appserv.security.AppservPasswordLoginModule extractCredentials
SEVERE: SEC1105: A PasswordCredential was required but not provided.
2011-04-05 09:06:46 com.sun.appserv.security.ProgrammaticLogin login SEVERE:
SEC9050: Programmatic login failed
com.sun.enterprise.security.auth.login.common.LoginException:
javax.security.auth.login.LoginException: No credentials. at
com.sun.enterprise.security.auth.login.LoginContextDriver$9.run(LoginContextDriver.java:889)
at
com.sun.enterprise.security.common.AppservAccessController.doPrivileged(AppservAccessController.java:61)
at
com.sun.enterprise.security.auth.login.LoginContextDriver.doClientLogin(LoginContextDriver.java:881)
at
com.sun.appserv.security.ProgrammaticLogin$1.run(ProgrammaticLogin.java:184)
at java.security.AccessController.doPrivileged(Native Method) at
com.sun.appserv.security.ProgrammaticLogin.login(ProgrammaticLogin.java:168)
at
com.sun.appserv.security.ProgrammaticLogin.login(ProgrammaticLogin.java:239)
at
com.sun.appserv.security.ProgrammaticLogin.login(ProgrammaticLogin.java:211)
at ClientStarter.main(ClientStarter.java:27) Caused by:
javax.security.auth.login.LoginException: No credentials. at
com.sun.appserv.security.AppservPasswordLoginModule.extractCredentials(AppservPasswordLoginModule.java:336)
at
com.sun.appserv.security.AppservPasswordLoginModule.login(AppservPasswordLoginModule.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
javax.security.auth.login.LoginContext.invoke(Unknown Source) at
javax.security.auth.login.LoginContext.access$000(Unknown Source) at
javax.security.auth.login.LoginContext$4.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
javax.security.auth.login.LoginContext.invokePriv(Unknown Source) at
javax.security.auth.login.LoginContext.login(Unknown Source) at
com.sun.enterprise.security.auth.login.LoginContextDriver$9.run(LoginContextDriver.java:887)
... 8 more 2011-04-05 09:06:46
com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
INFO: Cannot find javadb client jar file, derby jdbc driver will not be
available by default. [/php] Am I missing something here? How can I make it
work both web and standalone mode?


--
[Message sent by forum member 'lhanusiak']
View Post: http://forums.java.net/node/788640