我可以只启用 Spring Session header 身份验证吗?

Can I enable just Spring Session header authentication?

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

如何在不启用 Redis 的情况下启用 Header 身份验证?

(以 spring 引导单文件应用程序为例会很好)

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

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

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

@EnableSpringHttpSession
class HttpSessionConfig {

    @Bean
    MapSessionRepository sessionRepository() {
        return new MapSessionRepository();
    }

    @Bean
    HttpSessionStrategy httpSessionStrategy() {
        return new HeaderHttpSessionStrategy();
    }
}