大佬教程收集整理的这篇文章主要介绍了阻止Spring Boot注册Servlet过滤器,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
默认情况下,Spring Boot 在应用程序上下文中为FilterRegistrationBean
每个尚不存在的对象创建一个。这使你可以采取注册过程的控制,包括禁止注册,宣称自己的。对于你所需的配置如下所示:FilterFilterRegistrationBean FilterRegistrationBean FilterPreAuthenticationFilter
@Bean
public FilterRegistrationBean registration(PreAuthenticationFilter filter) {
FilterRegistrationBean registration = new FilterRegistrationBean(filter);
registration.setEnabled(false);
return registration;
}
有一个Spring Boot WebMVC应用程序,还有一个从AbstractPreAuthenticatedProcessingFilter继承的bean,我将其显式添加到Spring Security过滤器链中的特定位置。我的Spring Security配置如下所示:
<http pattern="/rest/**">
<intercept-url pattern="/**" access="ROLE_USER"/>
<http-basic/>
<custom-filter after="BASIC_AUTH_FILTER" ref="preAuthenticationFilter"/>
</http>
<beans:bean id="preAuthenticationFilter" class="a.b.PreAuthenticationFilter">
<beans:property name="authenticationManager" ref="customAuthenticationManager"/>
</beans:bean>
安全配置有效。问题是,因为PreAuthenticationFilter类继承自AbstractPreAuthenticatedProcessingFilter,所以Spring Boot将其视为通用servlet过滤器,并将其添加到所有请求的servlet过滤器链中。我不希望此过滤器成为所有请求的过滤器链的一部分。我只希望它成为我配置的特定Spring Security过滤器链的一部分。有没有一种方法可以防止Spring Boot自动将preAuthenticationFilter bean添加到过滤器链中?
以上是大佬教程为你收集整理的阻止Spring Boot注册Servlet过滤器全部内容,希望文章能够帮你解决阻止Spring Boot注册Servlet过滤器所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。