【问题标题】:Warn to user with message in session timeout in spring boot app 2.0在 Spring Boot 应用程序 2.0 中向用户发出会话超时消息警告
【发布时间】:2018-07-20 02:53:56
【问题描述】:

我想在登录页面中向用户显示“因不活动而退出”的消息。

我在 spring security 中尝试了下面的代码,但它没有受到影响。

httpsecurity 中的 sessionManagement().maximumSessions(1).expiredUrl("/login?expired")。

会话超时后,仅重定向到/login,没有得到过期值。

使用以下版本:

春季启动 2.0

Spring 安全 5.0

【问题讨论】:

  • 你添加了会话监听器吗?
  • 不是,我直接在http安全中添加了sessionManagement().maximumSessions(1).expiredUrl("/login?expired")
  • 这还不够。您还必须添加会话侦听器。
  • 嘿伙计,你的问题解决了吗?如果是,请发布您的解决方案!

标签: spring-boot spring-security thymeleaf


【解决方案1】:

这只是我整个配置的一个 sn-p,但这将检查会话是否仅为经过身份验证的用户过期。当您使用.maximumSessions(1) 时,您正在处理并发用户管理。这不是你需要的。

在下面的 sn-p 中,我检查所有传入的请求是否经过身份验证 .anyRequest().authenticated()。如果请求来自经过身份验证的用户(我不检查角色)并且会话已超时.sessionManagement().invalidSessionUrl(),请将它们重定向回具有登录表单的索引页面。

@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http.authorizeRequests()
          .anyRequest().authenticated()
          .and()
          .sessionManagement().invalidSessionUrl("/?sessionexpired=true");
  }

}

【讨论】:

    猜你喜欢
    • 2019-08-22
    • 2015-07-29
    • 2015-05-21
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 2018-01-30
    • 2017-03-16
    • 1970-01-01
    相关资源
    最近更新 更多