1 Reply Latest reply on Apr 13, 2008 5:11 PM by Tim Goodchild

    Can't set properties of Seam component

    Tim Goodchild Newbie

      This seems very strange .. In the authenticate method I create a Seam java bean component of session scope (only if authentication is sucessful).  However, the attributes of loggedInUser are still null after I have just set them!  Watching this in the debugger is quite unsettling.  dbUserAccount.getAccountId() does have a value as do the other values used to populate loggedInUser.


      It seems like I'm doing basic stuff but I can't understand this behaviour.  If you have any ideas please let me know.


      I'm using Seam 2.0.1, jdk 1.5.15 on Jboss 4.2.2


      here is my authenticate class:-



      @Stateless
      @Name("authenticator")
      public class AuthenticatorImpl implements Authenticator, Serializable
      {
          /** serialVersionUID */
          private static final long serialVersionUID = 1L;
      
          @Logger
          Log log;
      
          @In
          Identity identity;
      
          @In(create = true)
          AccountDao accountDao;
      
          @Out(required = false)
          LoggedInUser loggedInUser;
      
          public boolean authenticate()
          {
              log.info("authenticating #0", identity.getUsername());
      
              boolean success = false;
      
              UserAccount dbUserAccount = accountDao.getUserAccount(identity.getUsername(), identity.getPassword());
      
              if (dbUserAccount != null)
              {
                  success = true;
      
                  Set<UserRole> roles = dbUserAccount.getUserRoles();
                  for (UserRole role : roles)
                  {
                      if (role != null)
                      {
                          log.debug("Adding role {0}", role.getRoleName());
                          identity.addRole(role.getRoleName());
                      }
                  }
      
                  loggedInUser = (LoggedInUser) Component.getInstance(LoggedInUser.class);
                  loggedInUser.setAccountId(dbUserAccount.getAccountId());
                  loggedInUser.setProfileId(dbUserAccount.getUserProfile().getProfileId());
                  loggedInUser.setUserName(dbUserAccount.getUserName());
      
                  log.info("Authentication successful");
              }
              else
              {
                  // Clearing the identity object fields on authentication failure
                  // seems to prevent constant silent authentication attempts
                  identity.setUsername(null);
                  identity.setPassword(null);
              }
              return success;
          }
      }
      



      and the loggedInUser component:-



      @Name("loggedInUser")
      @Scope(value = ScopeType.SESSION)
      public class LoggedInUser
      {
          private Integer accountId;
          
          private Integer profileId;
          
          private String userName;
          
          public LoggedInUser() {
              
          }
      
          public Integer getAccountId()
          {
              return accountId;
          }
      
          public void setAccountId(Integer accountId)
          {
              this.accountId = accountId;
          }
      ....
      }