关于每次请求都要执行两个,即经过重写FilterInvocationSecurityMetadataSource的getAttributes()方法
执行两次的方法
@Override
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
String requestUrl = ((FilterInvocation) object).getRequestUrl();
List<TbPermission> permissions = permissionMapper.selectPermissionsByUrl(requestUrl);
if(permissions == null || permissions.size() == 0){
return null;
}
String[] attributes = new String[permissions.size()];
for(int i = 0;i< permissions.size();i++){
attributes[i] = permissions.get(i).getPermissionCode();
}
return SecurityConfig.createList(attributes);
}
原因:
- 自己定义了一个新的拦截器
- 在
extends AbstractSecurityInterceptor implements Filte r,使用了 InterceptorStatusToken token = super.beforeInvocation(filterInvocation);
@Component
public class CustomizeAbstractSecurityInterceptor extends AbstractSecurityInterceptor implements Filter {
private FilterInvocationSecurityMetadataSource securityMetadataSource;
@Autowired
public CustomizeAbstractSecurityInterceptor(FilterInvocationSecurityMetadataSource securityMetadataSource) {
this.securityMetadataSource = securityMetadataSource;
}
@Autowired
public void setMyAccessDecisionManager(CustomizeAccessDecisionManager accessDecisionManager) {
super.setAccessDecisionManager(accessDecisionManager);
}
@Override
public Class<?> getSecureObjectClass() {
return FilterInvocation.class;
}
@Override
public SecurityMetadataSource obtainSecurityMetadataSource() {
return securityMetadataSource;
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
FilterInvocation fi = new FilterInvocation(servletRequest, servletResponse, filterChain);
invoke(fi);
}
private void invoke(FilterInvocation filterInvocation) throws IOException, ServletException {
filterInvocation.getChain().doFilter(filterInvocation.getRequest(), filterInvocation.getResponse());
}
解决方法:
- 不使用新的filter
- 直接注释掉
InterceptorStatusToken token = super.beforeInvocation(filterInvocation); 等影响的代码,然后直接让它执行下一个拦截器
我这里做的是直接执行下一个拦截器
|