I've been struggling on this problem for a while so I would really appreciate if you guys can give me some advice on how to best tackle this problem.I would like to filter when navigating to the login page if the user is already logged in and if so redirect him straight to the homepage of his role. The problem is that these homepages are flowscoped and so the flow must also be entered. As far as I know this can only be done by returning the flow-definition id or by <p:commandButton ajax="false" action="boss"/>
. Because i am not redirecting the ServletRequest in the WebFilter I get a XML parsing error.
My question to you: how can I redirect the ServletRequest so it enters the customer/boss flowscope.
LoginFilter.java
:
@WebFilter("/Login.*")
public class LoginFilter implements Filter {
@Inject
private UserManagedBean userManagedBean;
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (userManagedBean.isLoggedIn()) {
// the user is already logged in and he's trying to login again
// then forwards to the admin's homepage
userManagedBean.attemptLogin();
} else {
// continues the filter chain
// allows the request to reach the destination
chain.doFilter(request, response);
}
}
public void destroy() {
}
public void init(FilterConfig fConfig) throws ServletException {
}
}
UserManagedBean.java
:
public String attemptLogin()
{
try {
User login_user = userBean.authenticateUser(username, password);
user = login_user;
loginStatus = "logged in as " + login_user.getUsername();
System.out.println("Yeeeeeet");
if(isUserCustomer()) return "customer";
if(isUserBoss()) return "boss";
}
catch (EJBException e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Login failed", e.getMessage()));
return "login";
}
return "login";
}