-
1. Re: write a string to variable
lvdberg Aug 28, 2009 12:13 PM (in response to kmali)Hi Kmali,
If you're a Seam AND a Java newbie I think you're probably overeating a bit.
Try with some simple java classes and html-pages first and see how that works.
To give you some hints: Your class lacks getters and setters for the two attrbutes and they're defined as static, which makes it very complex to use in a multi-user environment (web).
-
2. Re: write a string to variable
kmali Aug 28, 2009 4:42 PM (in response to kmali)I just need a login funktion for a application I haven't written myself.
I tried the to implemnt it via the autheticator class, but it didn't work. (Obviously because of my seam knowledge)So I want to try to implement a simple way to authenticate a user.
I doesn't need to be very secure, because it will only run in a local Network.I have a
User class
from a example Application with getters and setters:import static org.jboss.seam.ScopeType.SESSION; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.validator.Length; import org.hibernate.validator.NotNull; import org.hibernate.validator.Pattern; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; @Entity @Name("user") @Scope(SESSION) @Table(name="Customer") public class User implements Serializable { private String username; private String password; public User( String username, String password) { this.username = username; this.password = password; } public User() {} @NotNull @Length(min=5, max=15) public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Id @Length(min=5, max=15) @Pattern(regex="^\\w*$", message="not a valid username") public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Override public String toString() { return "User(" + username + ")"; } }
I just want to check a hardcoded Username and Password and redirect the user to the home.xhtml
I would appriciate if somebody could explain to me how to realize this... :( -
3. Re: write a string to variable
asookazian Aug 28, 2009 10:26 PM (in response to kmali)look at the booking example in the distro:
@Stateless @Name("authenticator") public class AuthenticatorAction implements Authenticator { @PersistenceContext private EntityManager em; @In(required=false) @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; } } }