问题
我在学习springboot整合security+jwt中当SecurityConfig使用addFilterBefore加入jwtAuthenticationTokenFilter后antMatchers失效了,也不知道是什么原因,查阅资料后,解决了此问题
步骤
1.application.yml文件中加入自定义过滤路径
filter:
path:
includes: /fuck,/test,/mm
2.在SecurityConfig中引入配置,并在原http位置配置
@Value("${filter.path.includes}")
private String[] paths;
.antMatchers(paths).anonymous()
3.在引入的JwtAuthenticationTokenFilter中引入配置,并在shouldNotFilter添加忽略路径
@Value("${filter.path.includes}")
private String[] paths;
@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
return addIgnorePaths(paths, request);
}
protected Boolean addIgnorePaths(String[] paths, HttpServletRequest request) {
Boolean result = false;
if (paths != null && paths.length > 0) {
for (String path : paths) {
if (result || new AntPathMatcher().match(path, request.getServletPath())) {
return true;
}
}
}
return false;
}
测试

至此,可添加忽略过滤路径。
本文介绍了解决SpringBoot整合Security+JWT时遇到的问题:在使用addFilterBefore加入jwtAuthenticationTokenFilter后,antMatchers功能失效。通过配置自定义过滤路径,成功解决了这一问题。
1533

被折叠的 条评论
为什么被折叠?



