Spring Security SAML MetadataGenerator中的动态域

时间:2016-11-02 16:32:01

标签: java spring spring-security

我们正在运行一个Java Web应用程序,最终用户可以通过两个不同的域(“domain1”,“domain2”)访问它。

该应用程序使用SAML身份验证的远程提供程序进行用户登录。

我们正在使用Spring Security SAML库来处理SAML通信。在我们的Spring配置中创建的一个Spring bean是MetadataGenerator。我们已将其设置为将entityBaseURL设置为“domain1”。

@Bean
public MetadataGenerator metadataGenerator() {
    String entityBaseUrl = environment.getProperty("saml.entity.base.url");
    MetadataGenerator metadataGenerator = new MetadataGenerator();
    ...
    metadataGenerator.setEntityBaseURL(entityBaseUrl);
    return metadataGenerator;
}

当用户通过“domain2”URL访问我们的应用程序时,这会导致问题。 SAML请求被发送到SAML提供程序,但是一旦用户登录到提供程序,她就会被重定向到“domain1”,她的会话丢失并且SAML响应未正确映射到原始请求(至少这是如何我们解释这个问题。)

我们可以在日志中看到这个例外:

    2016.11.02 15:30:24.076 [ajp-nio-8009-exec-31] DEBUG  o.s.s.s.s.HttpSessionStorage  - Message a511iei787cgc6bi2a91c4264e83c4h not found in session 2cbc5d3a-5061-410a-9518-505e8d22d5a3
    2016.11.02 15:30:24.079 [ajp-nio-8009-exec-31] DEBUG  o.s.s.s.SAMLAuthenticationProvider  - Error validating SAML message
    org.opensaml.common.SAMLException: InResponseToField of the Response doesn't correspond to sent message a511iei787cgc6bi2a91c4264e83c4h
            at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.processAuthenticationResponse(WebSSOProfileConsumerImpl.java:139) ~[spring-security-saml2-core-1.0.2.RELEASE.jar:1.0.2.RELEASE]
            at org.springframework.security.saml.SAMLAuthenticationProvider.authenticate(SAMLAuthenticationProvider.java:87) ~[spring-security-saml2-core-1.0.2.RELEASE.jar:1.0.2.RELEASE]
            at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:167) [spring-security-core-4.0.2.RELEASE.jar:4.0.2.RELEASE]
...

是否有一些方法/最佳实践如何设置MetadataGenerator(或系统的其他组件)以避免此问题?

TIA

马丁

0 个答案:

没有答案