3 Replies Latest reply on Feb 4, 2010 9:47 AM by gamba

    User not found with UserModule

    gamba

      Hi,

       

      I want to read the current users email adress out of the UserProfileModule.

      I placed the following code in a portlet, o jsf-managed-bean and an ejb with transaction-attribute required:

       

       

              try {
                  UserModule userModule = (UserModule) new InitialContext().lookup("java:portal/UserModule");
                  User user = userModule.findUserByUserName(this.getCurrentUser());
                  
                  System.out.println("USER = " +user.getUserName());
                  System.out.println("USER = " +user.toString());        
                  
                  UserProfileModule userProfile = (UserProfileModule) new InitialContext().lookup("java:portal/UserProfileModule");
                  String email = (String) userProfile.getProperty(user, User.INFO_USER_EMAIL_REAL);
                  
                  System.out.println("EMAIL = " +email);        
      
              }
              catch (NamingException ne) {
                  ne.printStackTrace();
              }
              catch (IdentityException ie) {
                  ie.printStackTrace();
              }
      
      

       

      In everey situation I get the following error:

       

      14:34:20,468 ERROR [JDBCExceptionReporter] Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:6b7:4b62e241:905 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:6b7:4b62e241:905 status: ActionStatus.ABORT_ONLY >))
      14:34:20,468 ERROR [HibernateUserModuleImpl] Cannot find user by name admin
      org.hibernate.exception.GenericJDBCException: Cannot open connection
          at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
          at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
          at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
          at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
          at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
          at org.hibernate.loader.Loader.doQuery(Loader.java:673)
          at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
          at org.hibernate.loader.Loader.doList(Loader.java:2220)
      

       

      It seems that something with the transaction is not ok .....

       

      Thx,

      Holger

        • 1. Re: User not found with UserModule
          gamba

          Ok, some new information. When debugging the search for UserModule is successful, but I want to find the user by

           

          userModule.findUserByUserName(this.ctx.getCallerPrincipal().getName());
          

           

          the follwoing exception occurs:

           

          org.jboss.portal.identity.IdentityException: Cannot find user by name admin
          

           

          But I logged in with user admin .... hm ....

          • 2. Re: User not found with UserModule
            gamba

            I'm using the standard IdentityLoginModule and the security-domain associated in my session bean is portal

             

                     <login-module code="org.jboss.portal.identity.auth.IdentityLoginModule" flag="sufficient">
                        <module-option name="unauthenticatedIdentity">guest</module-option>
                        <module-option name="userModuleJNDIName">java:/portal/UserModule</module-option>
                        <module-option name="roleModuleJNDIName">java:/portal/RoleModule</module-option>
                        <module-option name="userProfileModuleJNDIName">java:/portal/UserProfileModule</module-option>
                        <module-option name="membershipModuleJNDIName">java:/portal/MembershipModule</module-option>
                        <module-option name="validateUserNameCase">true</module-option>
                        <module-option name="additionalRole">Authenticated</module-option>
                     </login-module>
            

             

            So I don't understand why the user is not found.

             

            To go a little deeper. Every call to UserModule is restriced ... the lookup is ok ...

             

                UserModule userModule = (UserModule) new InitialContext().lookup("java:portal/UserModule");
                    
            

             

            ... but after everey method call some errors with the transaction enlistes stuff occurs ... for example the call for user count:

             

            userModule.getUserCount()
            

             

            2010-02-01 16:07:18,281 WARN  [com.arjuna.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.disallow] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.disallow] Adding multiple last resources is disallowed. Current resource is org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@1202871
            2010-02-01 16:07:18,343 ERROR [org.hibernate.util.JDBCExceptionReporter] Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:1140:4b66ec15:732 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:1140:4b66ec15:732 status: ActionStatus.ABORT_ONLY >))
            2010-02-01 16:07:18,343 ERROR [org.hibernate.util.JDBCExceptionReporter] Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:1140:4b66ec15:732 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:1140:4b66ec15:732 status: ActionStatus.ABORT_ONLY >))
            2010-02-01 16:07:18,359 ERROR [org.jboss.portal.identity.db.HibernateUserModuleImpl] Cannot count users
            org.hibernate.exception.GenericJDBCException: Cannot open connection
                 at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
                 at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
                 at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
                 at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
                 at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
                 at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
                 at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
                 at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
                 at org.hibernate.loader.Loader.doQuery(Loader.java:673)
                 at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
                 at org.hibernate.loader.Loader.doList(Loader.java:2220)
                 at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
                    ....
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                 at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                 at java.lang.Thread.run(Thread.java:595)
            Caused by: org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:1140:4b66ec15:732 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:1140:4b66ec15:732 status: ActionStatus.ABORT_ONLY >))
                 at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:95)
                 at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)
                 at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
                 ... 345 more
            Caused by: org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:1140:4b66ec15:732 status: ActionStatus.ABORT_ONLY >)
                 at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:358)
                 at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnectManagedConnection(BaseConnectionManager2.java:524)
                 at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:405)
                 at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:849)
                 at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
                 ... 347 more
            Caused by: javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a1135a1:1140:4b66ec15:732 status: ActionStatus.ABORT_ONLY >
                 at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TransactionSynchronization.checkEnlisted(TxConnectionManager.java:759)
                 at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConnectionManager.java:592)
                 at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:352)
                 ... 351 more
            2010-02-01 16:07:19,468 WARN  [com.arjuna.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.transaction.arjunacore.enliststarterror] [com.arjuna.ats.internal.jta.transaction.arjunacore.enliststarterror] TransactionImple.enlistResource - XAResource.start returned: XAException.XAER_PROTO for < 131075, 27, 25, 1-a1135a1:1140:4b66ec15:73ca1135a1:1140:4b66ec15:740                                                                             >
            2010-02-01 16:07:19,468 ERROR [STDERR] org.jboss.resource.connectionmanager.JBossLocalXAException: Trying to start a new tx when old is not complete! old: < 131075, 27, 25, 1-a1135a1:1140:4b66ec15:732a1135a1:1140:4b66ec15:73b                                                                             >, new < 131075, 27, 25, 1-a1135a1:1140:4b66ec15:73ca1135a1:1140:4b66ec15:740                                                                             >, flags 0
            2010-02-01 16:07:19,468 ERROR [STDERR]      at org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource.start(TxConnectionManager.java:901)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.java:776)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.java:499)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TransactionSynchronization.enlist(TxConnectionManager.java:788)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConnectionManager.java:579)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:352)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnectManagedConnection(BaseConnectionManager2.java:524)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:405)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:849)
            2010-02-01 16:07:19,468 ERROR [STDERR]      at org.jboss.resource.adapter.jdbc.WrapperDataSource.
            .....
            
            • 3. Re: User not found with UserModule
              gamba

              Found a solution that works.

               

              Only with TransactionAttribute.BEAN and UserTransactions the exceptions are not thrown.

              I've implemented another Bean (MailService) and coded this workaround.

               

              I did not understand each detail of this issue, but so far it works for me. Maybe

              the hibernate-jars of our jboss version (3.2.1) have some old bugs or something like

              that. I found some bug-entries ...


              https://jira.jboss.org/jira/browse/HIBERNATE-25

              http://opensource.atlassian.com/projects/hibernate/browse/HHH-1979