Omnifaces httpfilter重定向问题

时间:2014-07-21 22:29:54

标签: jsf omnifaces

嗨,我有这个常规的javax.servlet.Filter

  @WebFilter(filterName = "UserFilter", urlPatterns = {"*.xhtml"})
public class UserFilter implements Filter {

    private static final String EXPIRED_PAGE = "loginPage";

    @Inject
    private transient Logger log;

    @Override
    public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {

        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        HttpSession session = request.getSession(false);
        HashMap<String, Object> user = (session != null) ? (HashMap<String, Object>)     session.getAttribute("sessionParameters") : null;
        Integer userSession = (user != null ? (Integer) user.get("usuarioSesion") : null);
        boolean isLoginPage = (request.getRequestURI().lastIndexOf("login.xhtml") > -1);
        if (userSession != null || isLoginPage) {
            chain.doFilter(request, response);
        } else {
            response.sendRedirect(EXPIRED_PAGE);
        }
    }
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {  }
    @Override
    public void destroy() {    }
}

找到OmniFaces HttpFilter后我试图实现它

@WebFilter(filterName = "UserFilter", urlPatterns = {"*.xhtml"})
public class UserFilter extends HttpFilter {
    private static final String EXPIRED_PAGE = "loginPage";
    @Inject
    private transient Logger log;

    @Override
    public void doFilter(HttpServletRequest request, HttpServletResponse response, HttpSession session, FilterChain fc) throws ServletException, IOException {
        HashMap<String, Object> user = (session != null) ? (HashMap<String, Object>) session.getAttribute("sessionParameters") : null;
        Integer userSession = (user != null ? (Integer) user.get("usuarioSesion") : null);
        boolean isLoginPage = (request.getRequestURI().lastIndexOf("login.xhtml") > -1);
        if (userSession != null || isLoginPage) {
            fc.doFilter(request, response);
        } else {
            response.sendRedirect(EXPIRED_PAGE);
        }
    }

}
清洁代码:),我得到的问题是不重定向到我放在我的faces-config navigation xml上的登录页面。在调试模式,我可以看到它进入重定向,但它不会重定向任何帮助将不胜感激(对不起,这个过滤器世界的一点新谢谢!)哦,它使用常规过滤器

response.sendRedirect(request.getContextPath() + "/login.xhtml");

0 个答案:

没有答案