IDP启动了SAML登录错误 - 身份验证语句太旧而无法与值一起使用

时间:2015-05-29 11:38:07

标签: spring spring-security saml-2.0 spring-saml

我们使用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
    
  2. 这里的问题是..为什么我们的应用程序会尝试验证令牌何时发出的实例?它可以随时授予..

    1. 我不断收到带有消息&#34的SAMLException;本地实体不是至少一个AudienceRestriction&#34;中的断言的目标受众。跟踪如下

      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
      
    2. 我不明白为什么会发生此异常。

      请帮助我理解这个概念。

      谢谢!

2 个答案:

答案 0 :(得分:23)

您的IDP正在重新使用用户之前已经过身份验证的信息(在Authentication Instant标识的时间),默认情况下,Spring SAML配置为如果她在超过7200秒之前已经过身份验证,则不允许用户登录。< / p>

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

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

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

答案 1 :(得分:2)

仅就该主题而言,Google已确认目前不遵守SAML重定向的forceAuthN标志。因此,在SAML令牌上查看身份验证超时问题。记录在这里:Google Apps SSO as IdP into Spring SAML2 - Authentication token timeout