5 Replies Latest reply on Jun 1, 2011 7:10 PM by ruthlesset

    Extending Identity in SEAM 2.2.1

    ruthlesset

      I am pretty new to SEAM and could use some help with extending Identity. Basically I am trying to save the user id (and later more info related to the user).


      SEAM 2.2.1
      jboss 6.0.0


      This is the code I have under classes/hot/com/mydomain/action/CustomIdentity.class



      package com.mydomain.action;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Install;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.Startup;
      import org.jboss.seam.annotations.intercept.BypassInterceptors;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.security.Identity;
      
      @Name("org.jboss.seam.security.identity")
      @Scope(ScopeType.SESSION)
      @Install(precedence = Install.APPLICATION)
      @BypassInterceptors
      @Startup
      public class CustomIdentity extends Identity {
      
              private int userId;
              @Logger private Log log;
      
              @Override
              public boolean isLoggedIn() {
                      //log.info("---------------------------- is LoggedIn ");
                      return super.isLoggedIn();
              }
      
              public int getUserId() {
                      return userId;
              }
      
              public void setUserId(int userId) {
                      this.userId = userId;
              }
      
      }
      




      Under the authenticate method I try to set the user id using



      identity.setUserId(user.getRecid());
      



      The two errors I see are
      1. @Name(org.jboss.seam.security.identity) - Duplicate component name: org.jboss.seam.security.identity
      2. Under the authenticate method it says setUserId is undefined.


      Can someone kindly tell me what I'm doing wrong?


        • 1. Re: Extending Identity in SEAM 2.2.1
          tausuahmed

          Hi,


          I'd like to answer your second question first.


          1. Make sure you access identity instance from CustomIdentity.


          2. As far as Duplicate component is concerned ant clean your project properly and build it.


          Regards,
          Tauseef

          • 2. Re: Extending Identity in SEAM 2.2.1
            ruthlesset

            Thank you Tauseef.


            When you mean instance of CustomIdentity I assume you meant



            CustomIdentity ccoIdentity = new CustomIdentity();
            ccoIdentity.setUserId(user.getRecid());
            



            Kindly correct me if I'm wrong.

            • 3. Re: Extending Identity in SEAM 2.2.1
              ruthlesset

              The correct way to do it in SEAM would be as below I assume?


              @In CustomIdentity customIdentity;
              ...
              customIdentity.setUserId(user.getRecid());
              



              This is the error I get


              11:17:38,128 WARN  [org.jboss.seam.security.jaas.SeamLoginModule] Error invoking login method: javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: @In attribute requires non-null value: authenticator.customIdentity
              ...
              Caused by: javax.ejb.EJBTransactionRolledbackException: @In attribute requires non-null value: authenticator.customIdentity
              ...
              Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: authenticator.customIdentity
              




              • 4. Re: Extending Identity in SEAM 2.2.1
                tausuahmed

                Try this CustomIdentity customIdentity = (CustomIdentity)Component.getInstance(CustomIdentity.class);


                Tauseef.

                • 5. Re: Extending Identity in SEAM 2.2.1
                  ruthlesset

                  Thank you Tauseef. That works.


                  Do you know why this does not work?



                  @In CustomIdentity customIdentity;