繁体   English   中英

使用AntPathRequestMatcher的Spring安全过滤器

[英]Spring Security Filters with AntPathRequestMatcher

我有一个扩展弹簧安全性的身份验证过滤器AbstractAuthenticationProcessingFilter 因此,在这种情况下,我可以如下设置请求匹配器,

MyAuthenticationFilter authFilter = new MyAuthenticationFilter();
authFilter.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher("/api/**"));

我创建另一个没有必要具有身份验证功能的筛选器。 因此,我使用GenericFilterBean对其进行了扩展。 在这种情况下,如何添加上述的AntPathRequestMatcher?

您需要调用RequestMatcher.matches(HttpServletRequest request)

RequestMatcher myMatcher = AntPathRequestMatcher("/api/**");
...


@Override
void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) {

   if (myMatcher.matches(request)) {
       ...
   } else {
       ... 
   }

   chain.doFilter(request, response);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM