如何在Spring Security SAML 5.6.1中禁用签名验证?

4

我目前正在从旧的弃用的Spring Security SAML扩展1.0.10迁移到Spring Security 5.6.1中的SAML实现。

在旧扩展中,有可能禁用SAML响应的签名验证(属性wantAssertionSignedSpring Security SAML Extension documentation中)。这对我在测试期间非常有帮助。

我想知道在Spring Security 5.6.1中是否也可以这样做?


我在源代码中搜索并找到了类OpenSamlMetadataResolver,在我看来,这是硬编码的,无法更改:

private SPSSODescriptor buildSpSsoDescriptor(RelyingPartyRegistration registration) {
    SPSSODescriptor spSsoDescriptor = build(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
    (...)
    spSsoDescriptor.setWantAssertionsSigned(true);
    (...)
    return spSsoDescriptor;
}

另外,OpenSaml4AuthenticationProvider 中的代码似乎没有提供一种简单的方法来配置私有变量 assertionSignatureValidator 以覆盖验证行为。

感谢任何帮助。

1个回答

3
在即将于2022年5月16日发布的Spring Security 5.7.0中,硬编码行已被移除。因此,默认情况下不再进行签名验证。
如果需要,您还可以自定义EntityDescriptor,如下所示:
openSamlMetadataResolver.setEntityDescriptorCustomizer(
        (parameters) -> parameters.getEntityDescriptor().setEntityID("overriddenEntityId"));

在GA发布之前,您可以随时尝试里程碑版本。


太好了!一直在等待该版本的发布,因为还有一个SAML错误阻止升级到5.6.x。 - Sebastiaan van den Broek
不,响应或断言必须按规范进行签名,而Spring Security在5.7.0 RC1中仍然正确地执行此操作(请参见https://github.com/spring-projects/spring-security/blob/5.7.0-RC1/saml2/saml2-service-provider/src/opensaml4Main/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProvider.java#L546)。`wantAssertionSigned`是SAML元数据中的标志,作为提示,它并不强制执行签名。 - identigral
@identigral 我设置了一个 SAML IDP(Okta)以不使用签名,但在 Spring Boot 中消费 SAML 响应仍然失败,因为它需要签名,但 XML 是明文的。 - Sebastiaan van den Broek
@identigral,这会使测试变得非常困难。我也不会在生产中使用未签名的内容,但是已经很难测试整个周期了。而且像Spring Security 5.6这样的小惊喜会破坏基于数据库的依赖方注册,我们在生产中发现了这一点,因此即使只是自动升级Spring,测试也非常重要。 - Sebastiaan van den Broek
@identigral,你是对的,里程碑版本的更改对此行为毫无影响。这意味着我仍然没有运气,除非经过大量努力设置模拟的带证书的 IdP。 - Sebastiaan van den Broek
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接