【问题标题】:Can I enable just Spring Session header authentication?我可以只启用 Spring Session 标头身份验证吗?
【发布时间】:2015-02-07 17:04:43
【问题描述】:

目前我认为没有理由添加 Redis,但所有 Spring Session 示例都包含它。我想在设计时考虑到以后可能会添加它。我现在想要的是 Header Authentication。

如何在不启用 Redis 的情况下启用 Header Authentication?

(以 Spring Boot 单文件应用程序为例会很好)

【问题讨论】:

    标签: java spring spring-boot spring-session


    【解决方案1】:

    MapSessionRepository 就是为此目的而创建的。

    【讨论】:

      【解决方案2】:

      这适用于 1.2 版和未经测试的 1.1

      @EnableSpringHttpSession
      class HttpSessionConfig {
      
          @Bean
          MapSessionRepository sessionRepository() {
              return new MapSessionRepository();
          }
      
          @Bean
          HttpSessionStrategy httpSessionStrategy() {
              return new HeaderHttpSessionStrategy();
          }
      }
      

      【讨论】:

        【解决方案3】:

        我认为您需要的只是一个类型的过滤器 - SessionRepositoryFilter<Session>,在 Spring Boot 应用程序中意味着该类型的 @Bean。创建它时,您只需注入 HeaderHttpSessionStrategy

        【讨论】:

          猜你喜欢
          • 2021-04-28
          • 2011-05-11
          • 1970-01-01
          • 2019-02-21
          • 2015-12-27
          • 1970-01-01
          • 2022-10-05
          • 2019-02-14
          • 2019-06-19
          相关资源
          最近更新 更多