Filter order in spring-boot

Filter order in spring-boot,第1张

Filter order in spring-boot

Spring Security不会在它创建的Filter bean上设置订单。这意味着,当Boot为它创建FilterRegistrationBean时,它将获得默认顺序LOWEST_PRECEDENCE。

如果你想在Spring Security之后使用自己的过滤器,则可以为Spring Security的过滤器创建自己的注册并指定顺序。

所以我的问题的答案是:

@Beanpublic FilterRegistrationBean securityFilterChain(@Qualifier(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) Filter securityFilter) {    FilterRegistrationBean registration = new FilterRegistrationBean(securityFilter);    registration.setOrder(Integer.MAX_VALUE - 1);    registration.setName(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME);    return registration;}@Beanpublic FilterRegistrationBean userInsertingMdcFilterRegistrationBean() {    FilterRegistrationBean registrationBean = new FilterRegistrationBean();    UserInsertingMdcFilter userFilter = new UserInsertingMdcFilter();    registrationBean.setFilter(userFilter);    registrationBean.setOrder(Integer.MAX_VALUE);    return registrationBean;}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5059802.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存