0 Replies Latest reply on Sep 6, 2009 11:04 AM by Derk Dukker

    Multiple identity stores

    Derk Dukker Novice

      Hi all,

      I have defined 2 identity stores because I have 2 different implementations of user who should login on my site.
      I defined the stores in


      like this:

      <security:identity authenticate-method="#{authenticationManager.authenticate}"/>
         <security:jpa-identity-store name="jobSeekerIdentityStore"
         <security:jpa-identity-store name="employerIdentityStore"

      I also made an login method, it looks like this:

           public boolean authenticate() {
                log.info("authenticating {0}", credentials.getUsername());
                try {
      //               currentAccount = jobSeekerAccountHome.getJobSeekerAccountByUserName(credentials.getUsername());
                     log.debug("try to do a lookup with username: " + credentials.getUsername());
                     currentAccount = (JobSeekerAccount) jobSeekerIdentityStore.lookupUser(credentials.getUsername());
                     if(currentAccount == null) {
                          log.debug("We didn't found the user in the jobseekers table, now try employer with username: " + credentials.getUsername());
                          currentAccount = (EmployerAccount) employerIdentityStore.lookupUser(credentials.getUsername());
                     if(currentAccount == null){
                          log.debug("could not find currentAccount");
                          throw new NoResultException();
                     if (currentAccount.getUserRoles() != null) {
                          Set<Role> roles = (Set<Role>)currentAccount.getUserRoles();
                          for (Role role : roles) {
                               log.debug("try to add the role " + role.getName() + " to identity");
                               if(identity != null){
                                    log.debug("identity == null");
                                    return false;
                     if (!validatePassword(credentials.getUsername(), credentials.getPassword(), currentAccount)) {
                          return false;
                     return true;
                } catch (NoResultException e) {
                     return false;

      But now I need to know what kind of user is trying to login in. I now search both identity stores to find a match but if both implementations have the samen username than this method won't work anymore. I hoped a hidden field would do the trick but can't find an example. How can I a hidden field to the backing bean? Or does someone knows a better solution?

      ps. my registration thing is based on thelabdude.blogspot.com/2009/05/updates-to-seam-user-registration.html