https://edu.csdn.net/course/detail/36074
Python实战量化交易理财系统https://edu.csdn.net/course/detail/35475
目录* 背景
模拟场景是不是因为order的值找出在哪里赋予的order值解决办法 背景
项目中自定义了拦截器Filter,项目中使用了spring security,它也有对应的拦截器,我想让我自定义的Filter在spring security的拦截器前执行。
因为我自定义的拦截器,需要提前做一些逻辑处理;然后spring security的拦截器需要用到这部分的处理结果;所以我必须要想办法让我自定义的拦截器靠前执行。
那就一起来看看spring security设置的拦截器的默认优先级等级是多少吧。
模拟场景自定义拦截器如下:
@Slf4j public class MyoncePerRequestFilter extends oncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { log.info("======== MyoncePerRequestFilter ========"); filterChain.doFilter(request, response); } } @Configuration public class Config { @Bean public FilterRegistrationBean i18nFilterRegistrationBean() { FilterRegistrationBean registrationBean = new FilterRegistrationBean(); MyoncePerRequestFilter myoncePerRequestFilter = new MyoncePerRequestFilter(); registrationBean.setFilter(myOncePerRequestFilter); registrationBean.addUrlPatterns(" private int order = DEFAULT_FILTER_ORDER; public int getOrder() { return this.order; } public void setOrder(int order) { this.order = order; } } } public interface OrderedFilter extends Filter, Ordered { int REQUEST_WRAPPER_FILTER_MAX_ORDER = 0; }
到此我们也找到了这个默认值,是根据spring.security.filter.order来决定的,默认值是-100
解决办法第一种就是修改自己的顺序:
@Configuration public class Config { @Bean public FilterRegistrationBean i18nFilterRegistrationBean() { FilterRegistrationBean registrationBean = new FilterRegistrationBean(); MyoncePerRequestFilter myoncePerRequestFilter = new MyoncePerRequestFilter(); registrationBean.setFilter(myOncePerRequestFilter); registrationBean.addUrlPatterns("/*"); registrationBean.setOrder(-101); // 这里 return registrationBean; } }
第二种就是修改spring security拦截器的顺序:
spring: security: filter: order: 0
大家可以自己跑跑试试看,完结撒花~~~~~~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)