I'm trying to learn Java EE 6 and i'm just wondering how to implement authentication mechanism in Java EE 6.
Here is the Java EE 6 authentiction example:
public void login() {
if (account.authenticate(name, password) == null) {
message = "Invalid user name or password!";
} else {
message = " Login successful";
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
try {
request.login(this.name, this.password);
Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
name = principal.getName();
} catch (ServletException e) {
// Handle unknown username/password in request.login().
context.addMessage(null, new FacesMessage("Unknown login"));
}
}
}
I have a following questions:
- How request.login function check name and password? It isn't know user entity?
- If it isn't right way. How to implement standart authentication mechanism
In finally thank you for your advise and i need a very good tutorials or advise.