6 Replies Latest reply on Aug 5, 2009 11:20 PM by lcurros

    Extending Identity

      Hi!!


      I'm working with jboss 4.2.2 and seam 2.0.1GA.
      I started creating a Seam Web Project using Jboss Tools 2.0.0, and now I'm trying to extend Identity.
      So I am following this guide  from Jboss docs.


      I've created my custom Identity, but when I start my app I'm getting this error:


      java.lang.IllegalArgumentException: no such setter method: CustomIdentity.securityRules


      My CustomIdentity.java is something like this



      @Name("org.jboss.seam.security.identity")
      @Scope(SESSION)
      @Install(precedence = APPLICATION)
      @BypassInterceptors
      @Startup
      public class CustomIdentity extends Identity {
           
           private Long userId;     
           @Logger private Log log;
           
           @Override
           public boolean isLoggedIn() {
                log.info("---------------------------- is LoggedIn ");
                return super.isLoggedIn() && isCustomLoggedIn();
           }
           public Long getUserId() {
                return userId;
           }
           public void setUserId(Long userId) {
                this.userId = userId;
           }     
              private boolean isCustomLoggedIn(){
                       return userId!=null;
               
              }
      }




      Any idea?


      Thanks in advance.

        • 1. Re: Extending Identity
          braga

          Hi Leo,


               Try this:



          ...
          private RuleBase securityRules;
          
          public void setSecurityRules(RuleBase securityRules) {
            this.securityRules = securityRules;
          }
          ...
          
          


          • 2. Re: Extending Identity
            shane.bryzak

            If you still want to use rule-based permissions, you need to extend RuleBasedIdentity instead of Identity.

            • 3. Re: Extending Identity

              Thanks for your answers.
              Both work correctly.


              But I would like to know what are the benefits of rule-based permissions?

              • 4. Re: Extending Identity
                shane.bryzak

                The benefit is that you can have complex permissions based on business logic.  Rule based-security uses Drools under the covers which gives you a great deal of control over how permissions are granted.

                • 5. Re: Extending Identity
                  alceu

                  Hi, Leo C.


                  I'm trying to set userId in a CustomIdentity too, but any class that I try to inject in my CustomIdentity to retrive for me the userId by the principal name is coming null. Can you show with code how did you set the userId of the logged user? I'm using JpaIdentityStore.


                  Thanks in advance.

                  • 6. Re: Extending Identity

                    yes, as I remember, you cant inject it because of @bypassinterceptors
                    I just call setter (setUserId) from authenticator method to set it


                    Hope this helps!