IDP 发起的 SAML 登录错误 - 身份验证语句太旧,无法与值一起使用

IDP initiated SAML login error - Authentication statement is too old to be used with value

我们将 ADFS 用作 IDP,而我们的应用程序充当 SP。以下是 Auth 响应示例

<?xml version="1.0" encoding="UTF-8"?>
<Assertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion" ID="_82062d3d-897f-473e-90ad-0bb351d63b22" IssueInstant="2015-04-29T20:39:17.240Z" Version="2.0">
   <Issuer>http://adfs/services/trust</Issuer>
   <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
      <ds:SignedInfo>
         <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
         <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
         <ds:Reference URI="#_82062d3d-897f-473e-90ad-0bb351d63b22">
            <ds:Transforms>
               <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
               <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <ds:DigestValue />
         </ds:Reference>
      </ds:SignedInfo>
      <ds:SignatureValue />
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
         <ds:X509Data>
            <ds:X509Certificate>certificate..... </ds:X509Certificate>
         </ds:X509Data>
      </KeyInfo>
   </ds:Signature>
   <Subject>
      <NameID>username</NameID>
      <SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
         <SubjectConfirmationData InResponseTo="923ki0eg8h7g7y2243fi9jbdd1977j9" NotOnOrAfter="2015-04-29T20:44:17.240Z" Recipient="https://localhost/saml/SSO" />
      </SubjectConfirmation>
   </Subject>
   <Conditions NotBefore="2015-04-29T20:39:17.240Z" NotOnOrAfter="2015-04-29T21:39:17.240Z">
      <AudienceRestriction>
         <Audience>https://localhost/saml/metadata</Audience>
      </AudienceRestriction>
   </Conditions>
   <AuthnStatement AuthnInstant="2015-04-29T20:39:17.162Z" SessionIndex="_92062g3d-897f-473e-90ad-0aa351d63b22">
      <AuthnContext>
         <AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</AuthnContextClassRef>
      </AuthnContext>
   </AuthnStatement>
</Assertion>

我面临的问题可以分为两种情况:

  1. 空闲 1 小时后,我在本地注销了用户。服务器会话到期时间的默认值为 30 分钟。如果用户正在积极处理某事,我有我的代码每 10 分钟发送一次心跳 ping。现在,问题是当用户在 1 小时会话到期后尝试登录时,出现以下异常

    Caused by: org.springframework.security.authentication.CredentialsExpiredException: Authentication statement is too old to be used with value 2015-05-28T17:41:52.648Z
        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)
        ... 77 more
    

这里的问题是.. 为什么我们的应用程序会尝试验证令牌发布时间的实例?它可以随时授予..

  1. 我不断收到消息 "Local entity is not the intended audience of the assertion in at least one AudienceRestriction" 的 SAMLException。轨迹如下

    Caused by: org.opensaml.common.SAMLException: Local entity is not the intended audience of the assertion in at least one AudienceRestriction
        at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.verifyAudience(WebSSOProfileConsumerImpl.java:506)
        at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.verifyAssertionConditions(WebSSOProfileConsumerImpl.java:458)
        at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.verifyAssertion(WebSSOProfileConsumerImpl.java:303)
        at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.processAuthenticationResponse(WebSSOProfileConsumerImpl.java:214)
        ... 77 more
    

我不明白为什么会出现这个异常。

请帮助我理解这个概念。

谢谢!

您的 IDP 正在重复使用用户之前已经过身份验证的信息(在 Authentication Instant 标识的时间)并且 Spring SAML 默认配置为如果用户在超过 7200 秒之前已经过身份验证则不允许她登录.

这是一种安全措施 - 如果计算机对用户进行身份验证是很久以前的事,则很难保证操作计算机的仍然是同一个人。 Spring SAML 为您提供了一些方法来配置可接受的安全级别 - 例如通过使其可配置。

您可以通过在 WebSSOProfileConsumerImpl bean 上设置 属性 maxAuthenticationAge 来增加此值。

仅当断言包含 Audience 元素并且其中 none 与您的应用程序的实体 ID 匹配时,才会发生受众错误。我不认为你问题中的响应是触发此错误的响应?

仅供参考,Google 已确认目前不支持 SAML 重定向的 forceAuthN 标志。结果发现 SAML 令牌的身份验证超时问题。此处记录:Google Apps SSO as IdP into Spring SAML2 - Authentication token timeout