8 Replies Latest reply on Aug 20, 2010 6:48 PM by ilmar marques

    Extending JpaIdentityStore, causes NPE

    asaf sh Expert

      Hey,


      Im trying to extends JpaIdentityStore but that causes a NPE,
      I also see in the log:


      ERROR [JpaIdentityStore] Error in JpaIdentityStore configuration - userClass must be configured.
      



      I tried to read the code, I couldn't understand what sets the userClass property of the class, but overriding JpaIdentityStore causes the userClass to be null,



      Here's my simple class:



      @Name("org.jboss.seam.security.management.jpaIdentityStore")
      @Install(precedence = Install.APPLICATION)
      @Scope(APPLICATION)
      @BypassInterceptors
      public class ExtJpaIdentityStore extends JpaIdentityStore {
      
      ...
      }
      






      Can someone help ?


      Many thanks,


      Asaf.

        • 1. Re: Extending JpaIdentityStore, causes NPE
          Shane Bryzak Master

          You need to set the user-class property in components.xml.

          • 2. Re: Extending JpaIdentityStore, causes NPE
            Augusto Cesar Lima Newbie

            I'm having the same problem, but as long as I know I have configured the components.xml file.


            My components.xml :


            <?xml version="1.0" encoding="ISO-8859-1"?>
            <components xmlns="http://jboss.com/products/seam/components"
                        xmlns:core="http://jboss.com/products/seam/core"
                        xmlns:persistence="http://jboss.com/products/seam/persistence"
                        xmlns:drools="http://jboss.com/products/seam/drools"
                        xmlns:bpm="http://jboss.com/products/seam/bpm"
                        xmlns:security="http://jboss.com/products/seam/security"
                        xmlns:mail="http://jboss.com/products/seam/mail"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation=
                            "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                             http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                             http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
            
               <core:init debug="true" jndi-pattern="seam21Test-ear/#{ejbName}/local"/>
               
               <core:manager concurrent-request-timeout="500" 
                             conversation-timeout="120000" 
                             conversation-id-parameter="cid"
                             parent-conversation-id-parameter="pid"/>
                
                
                
               <persistence:managed-persistence-context name="entityManager"
                                                 auto-create="true"
                                  persistence-unit-jndi-name="java:/seam21TestEntityManagerFactory"/>                          
            
               <drools:rule-base name="securityRules">
                  <drools:rule-files>
                     <value>/security.drl</value>
                  </drools:rule-files>
               </drools:rule-base>
            
               <security:rule-based-permission-resolver security-rules="#{securityRules}"/> 
               
               <security:permission-manager
                      permission-store="#{org.jboss.seam.security.jpaPermissionStore}" />     
                     
                     <security:identity-manager installed="true" identity-store="#{saltedIdentityStore}" />
                     
               <security:jpa-identity-store 
                         user-class="domain.UserAccount"
                         role-class="domain.Role"
               />
               
               <security:jpa-permission-store             
                         user-permission-class="domain.UserPermission"
                         role-permission-class="domain.RolePermission"             
               />
               
               <event type="org.jboss.seam.security.notLoggedIn">
                  <action execute="#{redirect.captureCurrentView}"/>
               </event>
               <event type="org.jboss.seam.security.loginSuccessful">
                  <action execute="#{redirect.returnToCapturedView}"/>
               </event>
               
               <mail:mail-session host="localhost" port="2525" username="test" password="test" />
               
                  
            </components>



            I extended the JpaIdentityStore to make it simply get the salt from my user entity:



            @Name("saltedIdentityStore")
            public class SaltedIdentityStore extends JpaIdentityStore {
            
                 @Override
                 protected String getUserAccountSalt(Object user) {
            
                      UserAccount userAccount = (UserAccount) user;          
                      
                      return userAccount.getSalt();
                 }
                 
            }



            Unfortunately, the same error :



            10:31:04,942 ERROR [JpaIdentityStore] Error in JpaIdentityStore configuration - userClass must be configured.
            10:31:04,957 ERROR [SeamLoginModule] Error invoking login method
            java.lang.NullPointerException



            Please any help will be fine!
            Thank you

            • 3. Re: Extending JpaIdentityStore, causes NPE
              Shane Bryzak Master

              You changed the name to saltedIdentityStore (instead of jpaIdentityStore), that's why the config that you have in components.xml doesn't work.

              • 4. Re: Extending JpaIdentityStore, causes NPE
                Augusto Cesar Lima Newbie

                Hi shane , thanks for the tip !
                I managed to make the modifications but the problem is still ocurring.



                ERROR [JpaIdentityStore] Error in JpaIdentityStore configuration - userClass must be configured.



                I noticed while debugging that my SaltedIdentityStore class was indeed overriding the JpaIdentityStore but unfortunaly the userClass and roleClass fields on it are being null, causing the NPE at the lookupUser method. I even tried overring the getter methods for these fields making my class like this:


                @Name("jpaIdentityStore")
                @Install(precedence = Install.APPLICATION)
                @Scope(ScopeType.APPLICATION)
                @BypassInterceptors
                @Startup
                public class SaltedJpaIdentityStore extends JpaIdentityStore {  
                        
                        
                        
                        private static final long serialVersionUID = 4480043794776341553L;
                
                        public SaltedJpaIdentityStore() {
                                super();
                        }
                        
                        @Override
                        public Class getUserClass() {           
                                return UserAccount.class;
                        }
                        
                        @Override
                        public Class getRoleClass() {
                                return Role.class;
                        }
                        
                        @Override
                        protected String getUserAccountSalt(Object user) {              
                                return ((UserAccount) user).getSalt();
                        }
                        
                        @Override
                        public Object lookupUser(String arg0) {         
                                return super.lookupUser(arg0);
                        }
                        
                        @Override
                        public boolean authenticate(String username, String password) {
                                
                                return super.authenticate(username, password);
                        }
                
                }



                But ,again, unfortunaly the problem remains, I gess the JpaIdentityStore class acesses the userClass and roleClass fields directly, making overriding the getter methods useless. And since I can't override these fields I see no way to solve the problem.


                The security:jpa-identity-store  tag seems to be ignored when I override the jpaIdentityStore component because once I install my new component it starts complaining about the userClass being null, here is my components.xml again:



                <?xml version="1.0" encoding="ISO-8859-1"?>
                <components xmlns="http://jboss.com/products/seam/components"
                            xmlns:core="http://jboss.com/products/seam/core"
                            xmlns:persistence="http://jboss.com/products/seam/persistence"
                            xmlns:drools="http://jboss.com/products/seam/drools"
                            xmlns:bpm="http://jboss.com/products/seam/bpm"
                            xmlns:security="http://jboss.com/products/seam/security"
                            xmlns:mail="http://jboss.com/products/seam/mail"
                            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xsi:schemaLocation=
                                "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                                 http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                                 http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                                 http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
                
                   <core:init debug="true" jndi-pattern="seam21Test-ear/#{ejbName}/local"/>
                   
                   <core:manager concurrent-request-timeout="500" 
                                 conversation-timeout="120000" 
                                 conversation-id-parameter="cid"
                                 parent-conversation-id-parameter="pid"/>
                    
                    
                    
                   <persistence:managed-persistence-context name="entityManager"
                                                     auto-create="true"
                                      persistence-unit-jndi-name="java:/seam21TestEntityManagerFactory"/>                          
                
                   <drools:rule-base name="securityRules">
                      <drools:rule-files>
                         <value>/security.drl</value>
                      </drools:rule-files>
                   </drools:rule-base>
                
                   <security:rule-based-permission-resolver security-rules="#{securityRules}"/> 
                   
                   <security:permission-manager
                                permission-store="#{org.jboss.seam.security.jpaPermissionStore}" />     
                   
                   <security:identity-manager identity-store="#{jpaIdentityStore}" />
                         
                   <security:jpa-identity-store                              
                                user-class="domain.UserAccount"
                                role-class="domain.Role"                
                   />
                   
                   <security:jpa-permission-store 
                                user-permission-class="domain.UserPermission"
                                role-permission-class="domain.RolePermission"
                   />
                   
                   <event type="org.jboss.seam.security.notLoggedIn">
                      <action execute="#{redirect.captureCurrentView}"/>
                   </event>
                   <event type="org.jboss.seam.security.loginSuccessful">
                      <action execute="#{redirect.returnToCapturedView}"/>
                   </event>
                   
                   <mail:mail-session host="localhost" port="2525" username="test" password="test" />
                        
                   <!-- For use with jBPM pageflow or process management -->
                   <!--  
                   <bpm:jbpm>
                      <bpm:process-definitions></bpm:process-definitions>
                      <bpm:pageflow-definitions></bpm:pageflow-definitions>
                   </bpm:jbpm>
                   -->
                      
                </components>



                Any assistance will be much appreciated,
                Thanks !



                • 5. Re: Extending JpaIdentityStore, causes NPE
                  Augusto Cesar Lima Newbie

                  Sorry guys I'm kinda slow, I just had the idea of using the setUserClass and setRoleClass in my new Store's contructor so set the classes without the components.xml. I don't know if there is a better way (if it does, please tell me)  but it did the trick,
                  Thanks again Shane !

                  • 6. Re: Extending JpaIdentityStore, causes NPE
                    asaf sh Expert

                    The truth is that I'm very confused,
                    I changed the component name to 'org.jboss.seam.security.identityStore' instead of jpaIdentityStore and everything started to work as expected,



                    In components.xml I still have the jpaIdentityStore, how that works?



                    Thanks,



                    Asaf.

                    • 7. Re: Extending JpaIdentityStore, causes NPE
                      Joshua D Novice

                      I did the following to get pass this error related to user-class.


                      In the derived class constructor, I hard-coded the following.


                      public class SaltedJpaIdentityStore  {


                          public SaltedJpaIdentityStore() {
                              this.setUserClass(User.class);
                              this.setRoleClass(Role.class);
                          }


                      }


                      Hope this helps..

                      • 8. Re: Extending JpaIdentityStore, causes NPE
                        ilmar marques Newbie

                        In my case there was something missing in security:jpa-identity-store tag, components.xml, attribute 'entity-manager'.


                        Think would help