This content has been marked as final.
Show 4 replies
-
1. Re: seam user session authentication
fpsdyl Jan 1, 2009 5:49 PM (in response to safa)Hi, this is what I did :
Created the user entity :
@Entity @Name("user") @Table(name = "usr") @Scope(ScopeType.EVENT) public class User_E implements Serializable{ @Id @GeneratedValue @Column(name = "uid") private int uid; @NotNull @Column(name = "usrname") @Length(min = 5, max = 15) private String username; @NotNull @Length(min = 5, max = 15) @Column(name = "passwd") private String password; @Temporal(TemporalType.DATE) @Column(name = "last_login") private Date lastLogin; @NotNull @Length(min = 3, max = 15) @Column(name = "full_name") private String fullname; @NotNull @Column(name = "email_address") @Email private String email; @NotNull @Column(name = "notify_stats") private Boolean notifyStats;
That will create the table for you.
and use this session bean@Stateful @Scope(ScopeType.EVENT) @Name("authenticator") public class Authenticator implements AuthenticatorLocal { @Logger Log log; @In Credentials credentials; @PersistenceContext 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()); em.persist(user); 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"> <rich:panel> <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" value="#{credentials.username}"/> <h:outputLabel for="password">Password</h:outputLabel> <h:inputSecret id="password" value="#{credentials.password}"/> <h:outputLabel for="rememberMe">Remember me</h:outputLabel> <h:selectBooleanCheckbox id="rememberMe" value="#{identity.rememberMe}"/> </h:panelGrid> </div> </rich:panel> <div class="actionButtons"> <h:commandButton value="Login" action="#{identity.login}"/> </div> </h:form>
Hope that helps...
-
2. Re: seam user session authentication
safa Jan 2, 2009 9:43 AM (in response to safa)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
fpsdyl Jan 5, 2009 8:38 AM (in response to safa)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
susnet.susanne.susnet.se Jan 5, 2009 1:32 PM (in response to safa)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.