【问题标题】:Duplicate session creation & duplicate threads in AuthenticationProvider? Why?AuthenticationProvider 中的重复会话创建和重复线程?为什么?
【发布时间】:2017-10-17 10:34:32
【问题描述】:

所以我有一些 Spring Boot 安全代码,并且出于某种原因,尽管我的 STATELESS Angular 应用程序发送了一个 GET 请求。 Spring Security 似乎收到了两个请求,并在两个线程上以相同的毫秒数开始处理它们(然后我最终得到了一个唯一的用户约束,因为它试图将同一个用户两次添加到数据库中)。

我的 spring 安全配置是否有问题,发生双重请求? Spring Security 应该基本上检查来自无状态应用程序的所有请求以获取 X-AUTH-TOKEN。

http
            .authenticationProvider(authenticationProvider)
                .addFilterBefore(new HeaderAuthenticationFilter(), BasicAuthenticationFilter.class)
                //.addFilterBefore(new CorsFilter(request -> corsConfiguration), HeaderAuthenticationFilter.class)
                .authorizeRequests()
                .antMatchers("/").permitAll()
                .anyRequest()
                .authenticated()
                .and()
                .csrf().disable()
                .exceptionHandling().accessDeniedPage("/error");

基本上 HeaderAuthenticationProvider 和 HeaderAuthenticationFilter 用于检查 X-AUTH-TOKEN。

2017-05-17 19:46:41.868  INFO 5 --- [nio-8443-exec-8] o.a.c.util.SessionIdGeneratorBase        : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [13,338] milliseconds.
2017-05-17 19:46:41.868  INFO 5 --- [nio-8443-exec-1] o.a.c.util.SessionIdGeneratorBase        : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [8,315] milliseconds.
2017-05-17 19:46:41.872  INFO 5 --- [nio-8443-exec-8] m.d.f.a.HeaderAuthenticationProvider     : Authenticate:: Authorization Token: bf6bbb6f5a850fb7b152b5e143534e5bd13a96abd3250d2
2017-05-17 19:46:41.872  INFO 5 --- [nio-8443-exec-1] m.d.f.a.HeaderAuthenticationProvider     : Authenticate:: Authorization Token: bf6bbb6f5a850fb7b152b5e143534e5bd13a96abd3250d2

【问题讨论】:

    标签: spring-boot spring-security stateless-session


    【解决方案1】:

    不确定您是否仍有此问题。我之前遇到过类似的问题,我的问题是由于 Spring 启动了两个 DelegateFilter 链,一个是默认的,一个是自定义的。相反,每个过滤器都执行了两次。从您的日志看来,您可能有类似的问题。我解决它的方法是让我的过滤器扩展OncePerRequestFilter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-13
      • 2019-08-25
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      • 2013-03-13
      相关资源
      最近更新 更多