4 Replies Latest reply on Dec 27, 2010 9:16 AM by Shawn Zimmerman

    extending JpaPermissionStore

    Shawn Zimmerman Newbie

      I have been trying to extend the JpaPermissionStore per this link without success.


      By adding those additional methods, I am not able to access them by permissionManager.getPermissionStore().listPermissions(recipient) since getPermissionStore() returns a permission store implementing the PermissionStore interface, thus I would only have access to the methods of the PermissionStore interface.


      How can I access these additional methods from a Seam component?


      I tried @In JpaPermissionStore jpaPermissionStore and a few other variations to access the overriding JpaPermissionStore class to access the additional methods.


      Thanks

        • 1. Re: extending JpaPermissionStore
          Shawn Zimmerman Newbie

          This is what I have at the top of my overriding JpaPermissionStore class, same as the example:


          JpaPermissionStore.java


          @SuppressWarnings("serial")
          @Name("org.jboss.seam.security.jpaPermissionStore")
          @Install(precedence = Install.APPLICATION, value = false)
          @Scope(APPLICATION)
          @BypassInterceptors
          public class JpaPermissionStore extends org.jboss.seam.security.permission.JpaPermissionStore {
               ...
          
               public List<Permission> listPermissions(final Principal recipient) {
                    ...
               }
               
               ...
          }



          TestAction.java


          @Name("testAction")
          @Scope(ScopeType.CONVERSATION)
          public class Test implements Serializable {
               @In
               private org.jboss.seam.security.JpaPermissionStore jpaPermissionStore;
          
               private void testFunction() {
                    if (jpaPermissionStore != null) {
                         for (Permission per : jpaPermissionStore.listPermissions(new SimplePrincipal(recipient))) {
                              System.out.println("List: " + per.getAction());
                         }
                    } else {
                         System.out.println("jpaPermissionStore is NULL");
                    }
               }
          }



          I can not access the additional methods provided by the extended class.  Can someone point me in the right direction?  I can't figure out what I am overlooking.


          Thanks.


          • 2. Re: extending JpaPermissionStore
            Craig Bensemann Novice

            Hi


            I'm the author of the site you referenced in your first post. I'm sorry the instructions aren't always clear - I originally started keeping notes on the site for myself (and my colleagues) but then decided to make it public in case anyone else found it useful. I dont have a lot of time just now as I'm finishing up some of our applications but when I do I would like to go back and add in more details.


            Anyway on to your problem.....



            There are a couple of ways you can access the class:


            You could inject it as you mentioned in your first post. Something like


            import nz.co.softwarefactory.esafensound.seam.JpaPermissionStore;
            
            public class myBean {
            
            @In JpaPermissionStore jpaPermissionStore;
            
            }



            That would inject in the extended instance (note the class to import here is the extended one not the seam one)


            Alternatively you can get it from the permissionManager but you will need to cast it.


            (JpaPermissionStore) permissionManager.getPermissionStore()



            Again you will need to cast it to your extended class.


            I've used both and they both work.



            Also I assume you have declared your extended class in your components.xml so that Seam knows to use your implementation. Something like:


                <security:jpa-permission-store entity-manager="#{unrestrictedEntityManager}"
                    class="nz.co.softwarefactory.esafensound.seam.JpaPermissionStore" />




            Hope that helps.


            Craig

            • 3. Re: extending JpaPermissionStore
              Craig Bensemann Novice

              Also note that the listPermissions method was not added to the core seam implementation due to concerns over performance (and possibly other reasons). The method could potentially return a large number of results. In my application I know that it will only ever be a small list and its not called very often so I'm not too worried but just bare that in mind.

              • 4. Re: extending JpaPermissionStore
                Shawn Zimmerman Newbie

                Your suggestions did the trick!  I knew it would be something simple but I couldn't put my finger on it.


                I had the injection correctly, however I had the components.xml incorrect.


                I was using:


                <component name="jpaPermissionStore"
                class="com.example.security.JpaPermissionStore"
                startup="true" scope="APPLICATION" />



                I now changed it to:


                <security:jpa-permission-store entity-manager="#{entityManager}"
                user-permission-class="com.example.security.UserPermission"
                class="com.example.security.JpaPermissionStore" />



                and it works like a charm.


                I am still figuring out how security works in Seam, trying to stick with best practices.  I am sure by the time I am proficient, I'll be moving over to Seam 3 with PicketLink.


                Thank you again.  I hope this helps someone else too.