java应用中spring自动注入_java-Spring Security会自动过滤注入吗?

我有一个使用spring-security core v4.1.1.RELEASE的spring-boot应用程序(spring-boot v1.3.3.RELEASE).

看来,如果我通过扩展OncePerRequestFilter或GenericFilterBean来制作自定义滤镜豆,则无论我是否在自定义中传递给configure()的HttpSecurity对象上调用addFilter(),我的滤镜都会自动添加到滤镜链中WebSecurityConfigurerAdapter类.

这是自定义过滤器代码:

@Component

public class CustomFilter extends GenericFilterBean {

@Override

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException {

// custom filter code here

}

}

这是缩写的安全配置代码:

@Configuration

@EnableWebSecurity

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override

public void configure(HttpSecurity http) throws Exception {

// not adding the custom filter here

http.authorizeRequests()

.antMatchers("/api/login/**").permitAll()

.anyRequest().authenticated();

}

}

我观察到的是,即使我没有将其添加到过滤器链中,所有请求,即使是对/ api / login的请求,都将通过CustomFilter.如果我声明的CustomFilter没有任何@Configuration或@Bean批注,则除非将其在SecurityConfiguration类中明确告知,否则不会将其添加到过滤器链中.

我的问题:这是预期的行为吗?如果是这样,为什么?在我看来,由于缺少更好的词,将过滤器自动添加到过滤器链是很危险的-无论我在SecurityConfiguration中指定了什么,每个请求都会通过过滤器.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值