users@glassfish.java.net

Principals returns empty after custom login using JAAS

From: <glassfish_at_javadesktop.org>
Date: Sat, 05 Dec 2009 06:04:49 PST

Hi ,

We have implemented custom loginmodule and custom realm in Glassfish (GF). There are no issues in the custom realm, loginmodule part. An User object is set in session after successful login in struts action.

The problem is, we are getting empty Principal inside the action. This behavior is inconsistent coz, the same code works fine but when the app is redeployed sometimes we get empty Principal.

Any idea or suggestion will help immensely as we are stuck on this for the past few days...

Please see code snippet below.

Thanks,
Rampi

The following code snippet gives a gist (not the exact code used in the app)

//Struts 2 action:
public LoginAction
{

public execute() {

Subject sub = SecurityContext.getCurrent().getSubject();
if (sub != null) {
Set<Principal> princi = sub.getPrincipals();
if (!princi.isEmpty()){

  //Successful User Login
  //create custom User Object in Session
  User userObj = new User()
 user.setAttrib1(value1);
 user.setAttrib2(value2);
...
...
 request.getSession().set(AppConstants.USER, userObj);
  return "AppPage";
}else {
   // User not Loggedin
   return "loginPage";
 
}
}
[Message sent by forum member 'srrampi' ]

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