I have a JSF 2.2 application with login page I need to control users access to the pages so I wrote a web filter but the problem is that it always return null when I try to access the session scoped JSF managed bean. I already logged in and I made sure that the login works fine and the user set correctly but still when I access the bean it returns null
here is my filter code to access the bean
UserLogin loginBean = (UserLogin) ((HttpServletRequest) request).getSession().getAttribute("userLogin");
here is the bean code with the login in method
@Named(value = "userLogin") @SessionScoped @ManagedBean
public class UserLogin implements Serializable {
/**
* Creates a new instance of UserLogin
*/
public UserLogin() {}
private static final long serialVersionUID = 1520318172495977648L;
private User user = null;
String email, password;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void login() {
UserHelper userHelper = new UserHelper();
user = userHelper.Login(email, password);
if (user != null) {
FacesMessage msg = new FacesMessage("Successful", "Welcomesss :" + user.getFirstname());
FacesContext.getCurrentInstance().addMessage(null, msg);
} else {
FacesMessage msg = new FacesMessage("Failed", "Wrong Usernames or password.");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}
I wrote a sample code to retrive all the session attrbuties but I couldn't find userLogin here is the method along with its output
Enumeration attrs = ((HttpServletRequest) request).getSession().getAttributeNames();
while (attrs.hasMoreElements()) {
LOG.log(Logger.Level.FATAL, attrs.nextElement());
}
FATAL: WELD_S #10
FATAL: com.sun.faces.application.view.activeViewMaps
FATAL: org.jboss.weld.context.conversation.ConversationIdGenerator
FATAL: com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap
FATAL: org.jboss.weld.context.ConversationContext.conversations
FATAL: com.sun.faces.application.view.activeViewContexts
FATAL: javax.faces.request.charset
FATAL: org.jboss.weld.context.beanstore.http.LockStore
@SessionScoped
? – Tarik