【问题标题】:SLO fails when SP has timed outSP 超时时 SLO 失败
【发布时间】:2021-08-13 16:03:47
【问题描述】:

使用 Spring Security SAML 1.0.10,当 SAML 会话在 SP 上超时,但在 IdP 上仍处于活动状态时,SLO 尝试失败。

如何复制

  1. 将会话超时设置为一分钟 (server.servlet.session = 1m)
  2. 在您的 SP 上登录
  3. 在不同的辅助 SP 上登录 - 它必须使用 SSO
  4. 等待会话超时
  5. 在辅助 SP 上进行锁定

这会在 Spring 中导致 ClassCastException,因为 SecurityContextHolder.getContext().getAuthentication() 包含不包含凭据的 AnonymousAuthenticationToken。它还会破坏过滤器链,并且永远不会向 IdP 发送 LogoutResponse,并且会在浏览器中显示错误页面。

java.lang.ClassCastException: class java.lang.String cannot be cast to class org.springframework.security.saml.SAMLCredential (java.lang.String is in module java.base of loader 'bootstrap'; org.springframework.security.saml.SAMLCredential is in unnamed module of loader 'app')
at org.springframework.security.saml.SAMLLogoutProcessingFilter.processLogout(SAMLLogoutProcessingFilter.java:172)

这是故意的,是错误还是我配置错误? 如果它是有意的或错误的,是否存在解决方法?

【问题讨论】:

    标签: spring-security spring-saml


    【解决方案1】:

    错误发生在SAMLLogoutProcessingFilter.processLogout() 中,其中以下代码导致 ClassCastException。在用户会话超时的情况下auth.getCredentials() 返回一个空字符串。

    SAMLCredential credential = null;
    if (auth != null) {
        credential = (SAMLCredential)auth.getCredentials();
    }
    

    我发现的唯一解决方法是创建一个 LogoutFilter 来处理该问题。

    我创建了一个扩展 SAMLLogoutProcessingFilter 的新 LogoutFilter。在 LogoutRequest 和 AnonymousAuthenticationToken 的情况下,我创建了一个 LogoutResponse。在任何其他情况下,我都转发到 SAMLLogoutProcessingFilter 或从 SAMLLogoutProcessingFilter 调用方法的副本,其中我删除了失败的部分。

      private void overwrittenLogout(HttpServletRequest request, HttpServletResponse response, SAMLMessageContext context)
          throws ServletException, SAMLException, MetadataProviderException, MessageEncodingException
      {  
          var auth = SecurityContextHolder.getContext().getAuthentication();
          if (auth instanceof AnonymousAuthenticationToken) {
              logoutProfile.sendLogoutResponse(context, StatusCode.SUCCESS_URI, null);
          } else if (auth != null) {
              followNormalProcedure(request, response, auth, context);
          }
      }
    

    【讨论】:

      猜你喜欢
      • 2014-09-17
      • 1970-01-01
      • 2012-09-04
      • 2019-09-24
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多