1 Reply Latest reply on Feb 25, 2008 1:38 PM by npillingcorda

    Hibernate exception when using the JBoss Portal Identity Man

    npillingcorda

      JBoss Portal Version: 2.6.4
      Did you get Portal from CVS? or download it? downloaded jboss-portal-2.6.4-bundled.zip
      OS Platform: Linux Fedora Core 4
      JVM 1.5.0_11

      I'm trying to use the JBoss Portal Identity Management API to get information about the logged-in user from JBoss Portal in a portlet. The API is described on: http://docs.jboss.com/jbportal/v2.6.4/referenceGuide/html/identity.html.

      I'm getting the following stack trace:

      2008-02-25 10:58:11,521 ERROR [org.jboss.portal.identity.db.HibernateUserModuleImpl] Cannot find user by name admin
      org.hibernate.HibernateException: Unable to locate current JTA transaction
       at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61)
       at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
       at org.jboss.portal.identity.db.HibernateUserModuleImpl.getCurrentSession(HibernateUserModuleImpl.java:298)
       at org.jboss.portal.identity.db.HibernateUserModuleImpl.findUserByUserName(HibernateUserModuleImpl.java:90)
       at com.corda.centerview.auth.JBossPortalDirectory.getUser(JBossPortalDirectory.java:59)
       at com.corda.centerview.auth.JBossPortalDirectory.isValidUser(JBossPortalDirectory.java:116)
       at com.corda.centerview.auth.JBossPortalPlugin.isValidUser(JBossPortalPlugin.java:51)
       at com.corda.centerview.auth.JBossPortalPlugin.authenticate(JBossPortalPlugin.java:29)
      


      import java.util.HashSet;
      import java.util.Set;
      import javax.naming.*;
      import org.jboss.portal.identity.*;
      import com.corda.cvserver.AuthPlugin;
      
      public class JBossPortalDirectory
      {
       UserModule userModule;
       RoleModule roleModule;
       MembershipModule membershipModule;
       UserProfileModule userProfileModule;
      
       public JBossPortalDirectory()
       {
       try
       {
       membershipModule = (MembershipModule)new InitialContext().lookup("java:portal/MembershipModule");
       roleModule = (RoleModule)new InitialContext().lookup("java:portal/RoleModule");
       userModule = (UserModule)new InitialContext().lookup("java:portal/UserModule");
       userProfileModule = (UserProfileModule)new InitialContext().lookup("java:portal/UserProfileModule");
      
       AuthPlugin.logError("MembershipModule: " + membershipModule);
       AuthPlugin.logError("RoleModule: " + roleModule);
       AuthPlugin.logError("UserModule: " + userModule);
       AuthPlugin.logError("UserProfileModule: " + userProfileModule);
       }
       catch (NamingException e)
       {
       AuthPlugin.logError("Naming Exception", e);
       }
       /*
       catch (IdentityException e)
       {
       AuthPlugin.logError("Identity Exception", e);
       }
       */
       catch (IllegalArgumentException e)
       {
       AuthPlugin.logError("Illegal Argument Exception", e);
       }
       }
      
       private User getUser(String username)
       {
       User user = null;
       try
       {
       user = userModule.findUserByUserName(username);
       }
       catch(Exception e)
       {
       AuthPlugin.logError("Exception in getUser(" + username + ")", e);
       }
       return user;
       }
      
       public Set<String> getGroups()
       {
       Set<String> groups = new HashSet<String>();
      
       try
       {
       Set<Role> roles = roleModule.findRoles();
       for(Role role : roles)
       {
       groups.add(role.getName());
       }
       }
       catch(Exception e)
       {
       AuthPlugin.logError("Exception in getGroups()", e);
       }
      
       return groups;
       }
      
       public Set<String> getGroups(String username)
       {
       Set<String> groups = new HashSet<String>();
      
       User user = getUser(username);
       if(user != null)
       {
       try
       {
       Set<Role> roles = membershipModule.getRoles(user);
       for(Role role : roles)
       {
       groups.add(role.getName());
       }
       }
       catch(Exception e)
       {
       AuthPlugin.logError("Exception in getGroups(" + username + ")", e);
       }
       }
      
       return groups;
       }
      
       public boolean isValidUser(String username)
       {
       boolean validUser = false;
      
       User user = getUser(username);
       if(user != null)
       {
       validUser = true;
       }
      
       return validUser;
       }
      }
      


      import java.util.Set;
      import javax.servlet.http.HttpServletRequest;
      import com.corda.cvserver.AuthPlugin;
      
      public class JBossPortalPlugin extends AuthPlugin
      {
       JBossPortalDirectory jbossPortalDirectory;
      
       public JBossPortalPlugin()
       {
       jbossPortalDirectory = new JBossPortalDirectory();
       }
      
       public boolean authenticate(HttpServletRequest request)
       {
       setAuthenticated(false);
      
       String username = request.getRemoteUser();
       if(isValidUser(username))
       {
       setAuthenticated(true);
       setUserName(username);
       setGroupList(getGroupList(username));
       }
      
       return isAuthenticated();
       }
      
       public Set<String> getGroupList(String username)
       {
       return jbossPortalDirectory.getGroups(username);
       }
      
       public Set<String> getGroups()
       {
       return jbossPortalDirectory.getGroups();
       }
      
       public boolean isValidUser(String username)
       {
       return jbossPortalDirectory.isValidUser(username);
       }
      }


      Am I doing something wrong or is there a problem I need to work around?

        • 1. Re: Hibernate exception when using the JBoss Portal Identity
          npillingcorda

          Another relevant part of the stack trace.

          Caused by: org.hibernate.HibernateException: Unable to locate current JTA transaction
           at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
           at org.jboss.portal.identity.db.HibernateUserModuleImpl.getCurrentSession(HibernateUserModuleImpl.java:298)
           at org.jboss.portal.identity.db.HibernateUserModuleImpl.findUserByUserName(HibernateUserModuleImpl.java:90)
           ... 255 more