4 Replies Latest reply on Jan 5, 2009 1:32 PM by Susanne Jarl

    seam user session authentication

    safa said Newbie

      I'm naw in seam and i want to manage the user session authentication.
      I'm wondring if there is some plugin for seam to do this.
      Or should implement this by my self and create the table in the database????
      I'm using seam 2.0.3 GA, postgrsql database and eclipse europa
      I'm really frustrated and I don't know how to do this!!!

        • 1. Re: seam user session authentication
          Dylan Janeke Newbie

          Hi, this is what I did :

          Created the user entity :

          @Table(name = "usr")
          public class User_E implements Serializable{
              @Column(name = "uid")
              private int uid;
              @Column(name = "usrname")
              @Length(min = 5, max = 15)
              private String username;
              @Length(min = 5, max = 15)
              @Column(name = "passwd")
              private String password;
              @Column(name = "last_login")
              private Date lastLogin;
              @Length(min = 3, max = 15)
              @Column(name = "full_name")
              private String fullname;
              @Column(name = "email_address")
              private String email;
              @Column(name = "notify_stats")
              private Boolean notifyStats;

          That will create the table for you.
          and use this session bean

          public class Authenticator implements AuthenticatorLocal
              @Logger Log log;
              @In Credentials credentials;
              EntityManager em;
              public boolean authenticate()
                  log.info("authenticating {0}", credentials.getUsername());
                  User_E user = fetchUser();
                  if (user == null){
                      log.info("No user like {0}", credentials.getUsername());
                      return false;
                  if (user.getPassword().equals(credentials.getPassword())){
                      log.info("successfully authenticated {0}", credentials.getUsername());
                      log.info("setting last login date...");
                      user.setLastLogin(new Date());
                      return true;
                  return false;
              public User_E fetchUser() {
                  Query query = em.createQuery("from User_E ue where ue.username = :username");
                  query.setParameter("username", credentials.getUsername());
                  List<User_E> lst = query.getResultList();
                  if(lst != null ||
                          lst.size() >= 1){
                      return lst.get(0);
                  return null;

          Then in your view use this for login screen :

              <h:form id="login">
                      <f:facet name="header">Login</f:facet>
                      <p>Please login here</p>
                      <div class="dialog">
                          <h:panelGrid columns="2" rowClasses="prop" columnClasses="name,value">
                              <h:outputLabel for="username">Username</h:outputLabel>
                              <h:inputText id="username"
                              <h:outputLabel for="password">Password</h:outputLabel>
                              <h:inputSecret id="password"
                              <h:outputLabel for="rememberMe">Remember me</h:outputLabel>
                              <h:selectBooleanCheckbox id="rememberMe"
                  <div class="actionButtons">
                      <h:commandButton value="Login" action="#{identity.login}"/>

          Hope that helps...

          • 2. Re: seam user session authentication
            safa said Newbie

            Thx Dylan for your help,
            So there is no plugin to help me to implementthe session authenticator,!!!
            I tried your suggession but it didn't work.
            I'll try some others things,
            Thx for your help

            • 3. Re: seam user session authentication
              Dylan Janeke Newbie

              No problems, by u saying it doens't work what errors are u getting etc. Please give more info and I will try to assist, I am not sure of any plugins though..

              • 4. Re: seam user session authentication
                Susanne Jarl Newbie

                If you install the JBoss Tools plugin to eclipse the Seam Gen will create the authenticator for you.

                Also look at the examples that comes with the seam download, seamspace for example.