What could be the best practice for Excluding a list of URL patterns from below servlet filter?
Use case: Create a whitelist of URLs that could be skipped through the below Http servlet filter.
@WebFilter(urlPatterns = "/*")public class SanitizeReqestParamFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException {} @Override public void destroy() {} @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException { // logic for sanitize the request params. filterChain.doFilter(servletRequest, servletResponse); }}
Note:Currently, I have a list of URLs in an enum and check if the request URL is present in that list or not.
I would like to use some other method something like,
- adding this list on filter registration so that it could exclude those URLs.
- Or have some custom annotation on the servlet that could help to identify skipped URLs.