赞
踩
我在学习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; }
至此,可添加忽略过滤路径。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。