Mais.... eu tenho uma classe
@WebFilter(urlPatterns = {"/*"}, description = "Session checker filter")
public class LoginFilter implements Filter, Serializable {
@Inject
private TokenUtil tokenUtil;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if (!req.getRequestURI().endsWith("login.xhtml") && !isTokenValid(req)) {
res.sendRedirect(req.getContextPath() + "/login.xhtml");
return;
}
chain.doFilter(req, res);
}
private boolean isTokenValid(HttpServletRequest request) {
System.out.println("LoginFilter() - isTokenValid()");
return tokenUtil.isExpirationTimeFromCookieValid(request) &&
!tokenUtil.getTokenFromCookies(request).isEmpty();
}
}