我已经在这个问题上苦苦挣扎了一段时间,所以如果你们能给我一些关于如何最好地解决这个问题的建议,我将不胜感激。如果用户已经登录,我想在导航到登录页面时进行过滤如果是这样,将他直接重定向到他的角色的主页。问题是这些主页是流范围的,因此还必须输入流。据我所知,这只能通过返回流定义 id 或 by 来完成<p:commandButton ajax="false" action="boss"/>
。因为我没有在 WebFilter 中重定向 ServletRequest,所以我收到了 XML 解析错误。
我的问题是:如何重定向 ServletRequest 使其进入客户/老板流程范围。
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";
}