2 Replies Latest reply on Apr 16, 2009 9:48 AM by Stephane Mourgues

    JpaPermissionStore: NPE when using role-permission-class

    Stephane Mourgues Newbie

      Hello


      We are using a JPAPermissionStore in Seam 2.1.1.GA and JBoss 5.0.1.GA


      Here is how we are doing it:


      components.xml:



         <security:jpa-permission-store  entity-manager="#{TPZEntityManager}"
         user-permission-class="com.topaz.business.data.entity.TPZPermissionUserEntityBean"
         role-permission-class="com.topaz.business.data.entity.TPZPermissionRoleEntityBean"/>



      TPZPermissionUserEntityBean.java:


      @Entity
      @DiscriminatorValue( TPZPermissionEntityBean.PERMISSION_RECIPIENT_USER )
      public class TPZPermissionUserEntityBean
          extends TPZPermissionEntityBean



      TPZPermissionUserEntityBean.java:


      @Entity
      @DiscriminatorValue( TPZPermissionEntityBean.PERMISSION_RECIPIENT_USER )
      public class TPZPermissionUserEntityBean
          extends TPZPermissionEntityBean



      The extended class TPZPermissionEntityBean.java:


      @Entity
      @Inheritance ( strategy = InheritanceType.SINGLE_TABLE )
      @DiscriminatorColumn( name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING, length = 30 )
      @Table( name = "systemcommon.SCPERMISSION" )
      public abstract class TPZPermissionEntityBean
          implements TPZIEntityBean




      Now we use it to save permissions for a newly created user:


      private final void savePermission( PermissionStore permissionStore ... )
      {
           (...)
         permissionStore.grantPermission( permission );
      }




      But we end up with the following error:



      17:14:04,843 ERROR [STDERR] java.lang.RuntimeException: Could not grant permission
      17:14:04,843 ERROR [STDERR]      at org.jboss.seam.security.permission.JpaPermissionStore.updatePermissionActions(JpaPermissionStore.java:448)
      17:14:04,843 ERROR [STDERR]      at org.jboss.seam.security.permission.JpaPermissionStore.grantPermission(JpaPermissionStore.java:260)
      17:14:04,843 ERROR [STDERR]      at com.topaz.apps.admin.users.TPZAdminUserEdit.savePermission(TPZAdminUserEdit.java:782)
      (...)
      17:14:04,968 ERROR [STDERR] Caused by: java.lang.NullPointerException
      17:14:04,968 ERROR [STDERR]      at org.jboss.seam.security.permission.JpaPermissionStore.updatePermissionActions(JpaPermissionStore.java:392)
      17:14:04,968 ERROR [STDERR]      ... 88 more




      Looking to the source code of JpaPermissionStore I have noticed in the initProperties method that as rolePermissionClass is not null on line 106 (its value being TPZPermissionRoleEntityBean as defined in components.xml)  the variable discriminatorProperty is never initialized, hence the NullPointerException on the line 392:



      if (discriminatorProperty.isSet())



      Am I doing something wrong or is this a seam bug? I'd say it is a bug because in our case we should not use discriminatorProperty but roleTargetProperty and roleActionProperty which are initialized in the initProperties method when rolePermissionClass is not null.


      To finish I want to add that until now we had no role-permission-class defined in components.xml and permissions were handled by the same entity bean for both user and role. And everything was working as expected.