4 Replies Latest reply on Aug 24, 2012 12:52 PM by nancho313

    Security Module: Identity Management doesn't work

    felipezf

      Hi!
      I'm using seam 3 security module with identity management with JpaIdentityStore, postgres and Jboss 6 to create users on my database, but it's not working. I'm following the example provided (http://docs.jboss.org/seam/3/security/latest/reference/en-US/html/security-identitymanagement.html).


      I just wrote this simple code to create an user:


      @Model
      public class MemberRegistration {
      
          @Inject 
          Identity identity;
           
          @Inject 
          IdentitySession identitySession;
        
          
          public void register() throws Exception {         
      
               PersistenceManager pm = identitySession.getPersistenceManager();
               pm.createUser("testuser");
      
          }
      }



      with this JSF fragment:


      <h:commandButton value="#{bundle.defaultHeader_createAccount}" action="#{memberRegistration.register}"/>




      .. and get this is the exception:


      13:03:17,765 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] org.picketlink.idm.common.exception.IdentityException: Error creating identity object: javax.faces.el.EvaluationException: org.picketlink.idm.common.exception.IdentityException: Error creating identity object
           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98) [:2.0.3-]
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) [:2.0.3-]
           at javax.faces.component.UICommand.broadcast(UICommand.java:311) [:2.0.3-]
           at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) [:2.0.3-]
           at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) [:2.0.3-]
           at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) [:2.0.3-]
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) [:2.0.3-]
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) [:2.0.3-]
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) [:2.0.3-]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.jboss.seam.security.external.dialogues.DialogueFilter.doFilter(DialogueFilter.java:48) [:3.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.jboss.seam.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) [:3.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.jboss.seam.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:72) [:3.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
           at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
           at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
           at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
           at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]
      Caused by: org.picketlink.idm.common.exception.IdentityException: Error creating identity object
           at org.jboss.seam.security.management.picketlink.JpaIdentityStore.createIdentityObject(JpaIdentityStore.java:1171) [:3.0.0.Final]
           at org.jboss.seam.security.management.picketlink.JpaIdentityStore.createIdentityObject(JpaIdentityStore.java:1096) [:3.0.0.Final]
           at org.picketlink.idm.impl.repository.WrapperIdentityStoreRepository.createIdentityObject(WrapperIdentityStoreRepository.java:144) [:1.5.0.Alpha02]
           at org.picketlink.idm.impl.api.session.managers.PersistenceManagerImpl.createUser(PersistenceManagerImpl.java:132) [:1.5.0.Alpha02]
           at com.manzana.bommenu.controller.MemberRegistration.register(MemberRegistration.java:27) [:]
           at com.manzana.bommenu.controller.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$home$fzaffari$workspace$3manzana$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1302099615051$deploy$bommenu$war"-ManagedBean-class_com$manzana$bommenu$controller$MemberRegistration_$$_WeldClientProxy.register(org$jboss$weld$bean-jboss$classloader:id="vfs:$$$home$fzaffari$workspace$3manzana$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1302099615051$deploy$bommenu$war"-ManagedBean-class_com$manzana$bommenu$controller$MemberRegistration_$$_WeldClientProxy.java)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_24]
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_24]
           at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_24]
           at org.apache.el.parser.AstValue.invoke(AstValue.java:196) [:6.0.0.Final]
           at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) [:6.0.0.Final]
           at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43) [:6.0.0.Final]
           at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56) [:6.0.0.Final]
           at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43) [:6.0.0.Final]
           at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56) [:6.0.0.Final]
           at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102) [:2.0.3-]
           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84) [:2.0.3-]
           ... 39 more
      Caused by: java.lang.NullPointerException
           at org.jboss.seam.security.management.picketlink.JpaIdentityStore.lookupIdentityType(JpaIdentityStore.java:1108) [:3.0.0.Final]
           at org.jboss.seam.security.management.picketlink.JpaIdentityStore.createIdentityObject(JpaIdentityStore.java:1140) [:3.0.0.Final]
           ... 56 more
      
      13:03:17,781 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] #{memberRegistration.register}: org.picketlink.idm.common.exception.IdentityException: Error creating identity object: javax.faces.FacesException: #{memberRegistration.register}: org.picketlink.idm.common.exception.IdentityException: Error creating identity object
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:114) [:2.0.3-]
           at javax.faces.component.UICommand.broadcast(UICommand.java:311) [:2.0.3-]
           at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) [:2.0.3-]
           at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) [:2.0.3-]
           at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) [:2.0.3-]
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) [:2.0.3-]
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) [:2.0.3-]
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) [:2.0.3-]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.jboss.seam.security.external.dialogues.DialogueFilter.doFilter(DialogueFilter.java:48) [:3.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.jboss.seam.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) [:3.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.jboss.seam.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:72) [:3.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
           at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
           at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
           at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
           at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]
      Caused by: javax.faces.el.EvaluationException: org.picketlink.idm.common.exception.IdentityException: Error creating identity object
           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98) [:2.0.3-]
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) [:2.0.3-]
           ... 38 more
      Caused by: org.picketlink.idm.common.exception.IdentityException: Error creating identity object
           at org.jboss.seam.security.management.picketlink.JpaIdentityStore.createIdentityObject(JpaIdentityStore.java:1171) [:3.0.0.Final]
           at org.jboss.seam.security.management.picketlink.JpaIdentityStore.createIdentityObject(JpaIdentityStore.java:1096) [:3.0.0.Final]
           at org.picketlink.idm.impl.repository.WrapperIdentityStoreRepository.createIdentityObject(WrapperIdentityStoreRepository.java:144) [:1.5.0.Alpha02]
           at org.picketlink.idm.impl.api.session.managers.PersistenceManagerImpl.createUser(PersistenceManagerImpl.java:132) [:1.5.0.Alpha02]
           at com.manzana.bommenu.controller.MemberRegistration.register(MemberRegistration.java:27) [:]
           at com.manzana.bommenu.controller.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$home$fzaffari$workspace$3manzana$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1302099615051$deploy$bommenu$war"-ManagedBean-class_com$manzana$bommenu$controller$MemberRegistration_$$_WeldClientProxy.register(org$jboss$weld$bean-jboss$classloader:id="vfs:$$$home$fzaffari$workspace$3manzana$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1302099615051$deploy$bommenu$war"-ManagedBean-class_com$manzana$bommenu$controller$MemberRegistration_$$_WeldClientProxy.java)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_24]
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_24]
           at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_24]
           at org.apache.el.parser.AstValue.invoke(AstValue.java:196) [:6.0.0.Final]
           at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) [:6.0.0.Final]
           at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43) [:6.0.0.Final]
           at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56) [:6.0.0.Final]
           at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43) [:6.0.0.Final]
           at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56) [:6.0.0.Final]
           at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102) [:2.0.3-]
           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84) [:2.0.3-]
           ... 39 more
      Caused by: java.lang.NullPointerException
           at org.jboss.seam.security.management.picketlink.JpaIdentityStore.lookupIdentityType(JpaIdentityStore.java:1108) [:3.0.0.Final]
           at org.jboss.seam.security.management.picketlink.JpaIdentityStore.createIdentityObject(JpaIdentityStore.java:1140) [:3.0.0.Final]
           ... 56 more
      



      Debugging the seam's source file, i've noticed that in this method bellow, on JpaIdentityStore class, the EntityManager em is null and this is what throws the first exception.



       protected Object lookupIdentityType(String identityType, EntityManager em)
         {      
            try
            {
               Property<Object> typeNameProp = modelProperties.get(PROPERTY_IDENTITY_TYPE_NAME);
               
               // If there is no identity type table, just return the name
               if (typeNameProp == null) return identityType;
               
               Object val = em.createQuery(
                     "select t from " + typeNameProp.getDeclaringClass().getName() + 
                     " t where t." + typeNameProp.getName() +
                      " = :identityType")
                     .setParameter("identityType", identityType)
                     .getSingleResult();
               return val;
            }
            catch (NoResultException ex)
            {
               return null;
            }      
         }





      My config files:


      persistence.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      
      <persistence version="2.0"
           xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
      
           <persistence-unit name="bommenuDatabase" transaction-type="JTA">
                
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:/bommenuDatasource</jta-data-source>
      
                <properties>
                
                    <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                    <property name="hibernate.hbm2ddl.auto" value="update"/>              
                    <property name="hibernate.show_sql" value="true" />
                      <property name="hibernate.format_sql" value="true" />
                    
                </properties>
           
           </persistence-unit>
      
      </persistence>



      seam-beans.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:s="urn:java:ee" 
         xmlns:security="urn:java:org.jboss.seam.security"
         xmlns:plidm="urn:java:org.jboss.seam.security.management.picketlink"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">     
         
         <interceptors>
            <class>org.jboss.seam.transaction.TransactionInterceptor</class>
         </interceptors>
              
            
           <plidm:JpaIdentityStoreConfiguration>
            <s:replaces/>
            <plidm:identityClass>com.manzana.bommenu.domain.IdentityObject</plidm:identityClass>
            <plidm:credentialClass>com.manzana.bommenu.domain.IdentityObjectCredential</plidm:credentialClass>
            <plidm:relationshipClass>com.manzana.bommenu.domain.IdentityObjectRelationship</plidm:relationshipClass>
            <plidm:roleTypeClass>com.manzana.bommenu.domain.IdentityRoleName</plidm:roleTypeClass>
            <plidm:attributeClass>com.manzana.bommenu.domain.IdentityObjectAttribute</plidm:attributeClass>
         </plidm:JpaIdentityStoreConfiguration>
            
      </beans>
      


      I aprecciate any suggestion beacuse a really dont'know what do.


      Best regards