8 Replies Latest reply on Apr 23, 2008 5:18 PM by Kevin T.

    how get user roles from database und use it in seam

    Kevin T. Newbie

      Hello,


      im a new user of the seam framework and it works fine.


      Now I wonna add different sites for different roles. But i dont know how i read out this roles from my database.


      I ve a table with id, username, password and role.
      I ve 4 different roles: admin, lender, borrower and caretaker.


      The aim is to get out the role for each member of my site and set restrictions p e.


      I use the AthenticatorAction class from the seam booking example. Its possible to compare username and pasword from login and password.


      code:


      package test.session;
      
      import static org.jboss.seam.ScopeType.SESSION;
      
      import java.util.List;
      
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      
      import de.uni_leipzig.wifa.iwi.handapparat.entity.User;
      
      @Stateless
      @Name("authenticator")
      public class AuthenticatorAction implements Authenticator
      {
         @PersistenceContext 
         private EntityManager em;
         
         @Out(required=false, scope = SESSION)
         private User user;
         
         public boolean authenticate()
         {
            List results = em.createQuery("select u from User u where u.username=#{identity.username} and u.password=#{identity.password}")
                  .getResultList();
            
            if ( results.size()==0 )
            {
               return false;
            }
            else
            {
               user = (User) results.get(0);
               return true;
            }
         }
      }



      If there were help, i would be happy.
      THX
      Kevin