Java 如何配置Spring Security在会话超时后重定向到IDP?

Java 如何配置Spring Security在会话超时后重定向到IDP?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个SecurityConfiguration类,它扩展了WebSecurityConfigurerAdapter,如下所示: @Override protected void configure(final HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/saml*").permitAll() .anyRequest().authenticated

我有一个
SecurityConfiguration
类,它扩展了
WebSecurityConfigurerAdapter
,如下所示:

@Override
protected void configure(final HttpSecurity http) throws Exception {

  http
  .authorizeRequests()
      .antMatchers("/saml*").permitAll()
      .anyRequest().authenticated()
      .and()
  .apply(SAMLConfigurer.saml())
      .serviceProvider()
            .keyStore()
            .storeFilePath(keystoreFilePath)
            .password(keystorePassword)
            .keyname(keystoreAlias)
            .keyPassword(keystorePassword)
            .and()
          .protocol(appProtocol)
          .hostname(appHostName)
          .basePath(appBasePath)
          .and()
      .identityProvider()
      .metadataFilePath(metadataFilePath);
}
首次登录时,身份验证工作正常,但在登录7200秒(2小时)后,您会收到一个错误。例外情况如下:

Caused by: org.springframework.security.authentication.CredentialsExpiredException: Authentication statement is too old to be used with value 2017-11-06T17:49:26.721Z
  at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.verifyAuthenticationStatement(WebSSOProfileConsumerImpl.java:538)
  at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.verifyAssertion(WebSSOProfileConsumerImpl.java:306)
  at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.processAuthenticationResponse(WebSSOProfileConsumerImpl.java:214)
  ... 75 more
这是有意义的,因为来自IDP的身份验证是很久以前的事了


当发生这种情况时,如何配置Spring重定向回IDP以获得新会话

严格来说,这不是一个直接的答案,但有助于解决问题

我也有同样的问题,当在第538行打开
websoprofileconsumeripl.java
的源代码时,它显示验证是在7200秒的默认配置下完成的

根据我的经验,ADFS和OKTA将身份验证重复使用超过24小时,即使您重定向回,它们也会返回用户,并产生相同的身份验证和无限重定向循环

为了解决这个问题(可能不正确/不安全),我所做的是通过创建
WebsProfileConsumer
Bean并调用其
setMaxAuthenticationAge()
来增加
maxAuthenticationAge
的值

/*以秒为单位设置最大身份验证期限-3天*24小时*3600秒/小时*/
私有静态最终长最大认证年龄=3*24*3600;
...
@豆子
公共网站ProfileConsumer网站ProfileConsumer(){
websoprofileconsumeripl consumer=新的websoprofileconsumeripl();
consumer.setMaxAuthenticationAge(最大认证年龄);
退货消费者;
}

hi nicholas79171,您找到解决此问题的方法了吗?