【问题标题】:Spring Boot: How to specify nameID policy for SAMLSpring Boot:如何为 SAML 指定 nameID 策略
【发布时间】:2020-12-27 09:24:30
【问题描述】:

我正在使用 Spring Boot v2.3.3。

我正在尝试通过使用 v5.2 中添加到 spring 的 saml 支持向我的应用程序添加 SSO 支持:(https://docs.spring.io/spring-security/site/docs/5.2.1.RELEASE/reference/htmlsingle/#saml2)

我对 Spring 和 SAML 还很陌生,虽然该参考页面提到当前功能集“支持加密的 NameId 元素”,但我不确定如何配置应用程序以添加名称 ID 格式,或者如何发送身份提供者的名称 ID。

我在此处复制了 Spring Boot 示例应用程序 (https://github.com/spring-projects/spring-security/tree/5.3.x/samples/boot/saml2login),但我的 IDP 说他们也需要 nameID。

任何帮助理解我需要添加的内容将不胜感激。

【问题讨论】:

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


    【解决方案1】:

    在您使用基于代码的配置时,您可以使用

      @Bean
      public WebSSOProfileOptions defaultWebSSOProfileOptions() {
        WebSSOProfileOptions webSSOProfileOptions = new WebSSOProfileOptions();
        // do not enable IdP-Proxy support
        webSSOProfileOptions.setIncludeScoping(false);
        webSSOProfileOptions.setNameID(NameIDType.TRANSIENT);
        return webSSOProfileOptions;
      }
    

    但是,通常 IdP 在 IdP 元数据文件中定义它支持的 NameID 格式,Spring Security SAML 将使用指定的第一个 NameID 格式。您可以重新排序。

    【讨论】:

    • 谢谢!我正在使用属性让 Spring Boot 为我创建我的 bean,但就在昨晚我切换到了基于代码的配置。我不知道 Spring 使用指定的第一个 NameID。我会在没有bean的情况下尝试它,如果它不起作用,我会尝试它。非常感谢!
    • 嗨!所以,我尝试了这段代码,我意识到它使用的是 Spring SAML 扩展中的 WebSSOProfileOptions。我正在使用来自 Spring Security Core 的新 SAML 库。 :(
    猜你喜欢
    • 2012-04-23
    • 1970-01-01
    • 2016-06-29
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 2021-01-23
    • 1970-01-01
    相关资源
    最近更新 更多