/**
* @Author: liftsail
* @Date: 2022/9/15 10:03
* @Description: 不积跬步无以至千里
*/
@Component
@Slf4j
@WebFilter(filterName = "urlFilter", urlPatterns = "/*")
public class URlFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
Filter.super.init(filterConfig);
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String requestUrl = ((HttpServletRequest) request).getRequestURL().toString();
String requestUri = ((HttpServletRequest) request).getRequestURI();
String contextPath = ((HttpServletRequest) request).getContextPath();
String servletPath = ((HttpServletRequest) request).getServletPath();
log.info(requestUrl + "\n" +
requestUri + "\n" +
contextPath + "\n" +
servletPath);
chain.doFilter(request, response);
/*if (requestUri.equals("/")) {
requestUri = "/rootDir";
}
boolean allowedPath = requestUri.contains("assets")
|| requestUri.contains("txt")
|| requestUri.contains("js")
|| requestUri.contains("png")
|| requestUri.contains("ico")
|| requestUri.contains("html")
|| requestUri.contains("css")
|| requestUri.contains("/rootDir")
|| requestUri.contains("/user/login");
if (allowedPath) {
chain.doFilter(request, response);
} else {
HttpSession session = ((RequestFacade) request).getSession();
if (ObjectUtil.isEmpty(session.getAttribute("loginUser"))) {
request.getRequestDispatcher("/error/loginExpired").forward(request, response);
} else {
chain.doFilter(request, response);
}
}*/
}
@Override
public void destroy() {
Filter.super.destroy();
}
}