我有一个登录过滤器,如下所示:
@WebFilter("*.xhtml")
public class LoginFiltre implements Filter {
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) arg0;
HttpServletResponse res = (HttpServletResponse) arg1;
System.out.println(req.getRequestURI());
System.out.println(req.getContextPath());
Credentials credentials = (Credentials) req.getSession().getAttribute(
"credentials");
if (req.getRequestURI().contains("login")) {
System.out
.println("login olmak istiyor faces servlet e yönlendirilecek");
chain.doFilter(arg0, arg1);
} else if (credentials != null
&& credentials.getUsername().length() != 0
&& credentials.isIsloggedin()) {
System.out.println("login olmus faces servlet e yönlendiriliyor");
chain.doFilter(arg0, arg1);
} else {
System.out.println("login olmamis yönlendirilecek");
res.sendRedirect(req.getContextPath() + "/login.xhtml");
}
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
我希望这个过滤器检查除登录页面之外的所有请求的身份验证,如何将所有页面放在一个名为secure(login.xhtml 除外)的文件夹中并为此过滤器使用/secure/* 之类的前缀映射?