Java Reference
In-Depth Information
In the following managed bean, a stateless session bean uses the user credentials passed
to the login method to authenticate the user and resets the caller identity of the request
when the logout method is called.
Click here to view code image
@Stateless
@Named
public class LoginBean {
private String username;
private String password;
public String getUsername() {
return this.username;
}
public void setUserName(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword() {
this.password = password;
}
...
public String login () {
FacesContext context = FacesContext.getCurrentInstance();
HttpServetRequest request = (HttpServletRequest)
context.getExternalContext().getRequest();
try {
request.login(this.username, this.password);
} catch (ServletException e) {
...
context.addMessage(null, new FacesMessage("Login failed."));
return "error";
}
return "admin/index";
}
public void logout() {
FacesContext context = FacesContext.getCurrentInstance();
Search WWH ::




Custom Search