小编Ste*_*ven的帖子

Spring Security 是否进行自动过滤器注入?

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

似乎如果我通过扩展OncePerRequestFilteror制作自定义过滤器 bean GenericFilterBean,我的过滤器将自动添加到过滤器链中,无论我是否调用addFilter()在自定义类中HttpSecurity传递给的对象。configure()WebSecurityConfigurerAdapter

这是自定义过滤器代码:

@Component
public class CustomFilter extends GenericFilterBean {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        // custom filter code here
    }
}
Run Code Online (Sandbox Code Playgroud)

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

@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();
    }
}
Run Code Online (Sandbox Code Playgroud)

我观察到的是,即使我没有将它添加到过滤器链的任何地方,所有请求,甚至是 to …

java spring spring-security

6
推荐指数
1
解决办法
1076
查看次数

标签 统计

java ×1

spring ×1

spring-security ×1