【问题标题】:Spring WebFlux + Security - do we have the "remember-me" feature?Spring WebFlux + Security - 我们有“记住我”功能吗?
【发布时间】:2019-07-26 05:27:50
【问题描述】:

当我开发一个非反应式应用程序并在身份验证中使用 rememberMe 功能时,我只是扩展 WebSecurityConfigurerAdapter 类并覆盖 configure(HttpSecurity httpSecurity) 方法。在这种情况下,我在 httpSecurity 对象中有一个 rememberMe() 方法。

但是当我使用 Spring WebFlux 时有区别。据我所知,我所要做的就是使用 ServerHttpSecurity 类的实例定义一个 SecurityWebFilterChain bean,通过调用如下链:

serverHttpSecurity.authorizeExchange()
                .anyExchange().authenticated()
                .and()
                .httpBasic()
                .build();

但是这里没有像 HttpSecurity 对象那样处理 rememberMe cookie 的方法,我可以用这种方式处理它:

httpSecurity.authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .httpBasic()
                .and()
                .rememberMe()

你知道有什么解决办法吗?

【问题讨论】:

  • 你找到什么了吗?

标签: java spring spring-security java-8 spring-webflux


【解决方案1】:

不幸的是,这似乎是不可能的。

有一个旧的issue on github,不幸的是,不知道什么时候能解决。

cmets 建议使用更长的会话到期时间并将会话卸载到外部数据存储(即 Redis)。这样,您可以将信息存储在数据库中,而不是存储在 cookie 中。

他们推荐使用 Spring Session 项目。

【讨论】:

  • 我正在使用 JWT,不想使用外部会话存储,如 redis 或任何其他存储。所以春季会议对我来说不是一个选择。
  • 也许在这里 - stackoverflow.com/questions/23603801/… 有你的问题的答案,即也许你应该与 jwt 一起进行无限会话并实现链接描述的算法。
【解决方案2】:

cmets 表示使用更长的会话到期时间并将会话卸载到外部数据存储(即 Redis)。这样,您可以将信息存储在数据库中,而不是存储在 cookie 中。

他们说使用 Spring Session 项目。

【讨论】:

  • 不确定这是不是答案
猜你喜欢
  • 2012-03-13
  • 1970-01-01
  • 2014-07-23
  • 2014-08-02
  • 2015-05-10
  • 2012-01-21
  • 2014-09-04
  • 2018-12-02
  • 2017-08-10
相关资源
最近更新 更多