【问题标题】:pac4j saml generate sp metaDatapac4j saml 生成 sp 元数据
【发布时间】:2017-02-25 23:15:49
【问题描述】:

我现在比较 spring saml 和 pac4j saml。一般来说,我认为pac4j比spring saml更容易实现。但有一件事我想不通: 查看此配置代码:

@Configuration
public class Pac4jConfig {

    @Bean
    public Config config() {

        final SAML2ClientConfiguration cfg = new SAML2ClientConfiguration(
                "resource:samlKeystoreNgcsc.jks",
                "juniper",
                "juniper",
                "resource:metadata-okta.xml"
                );
        cfg.setMaximumAuthenticationLifetime(3600);

        cfg.setServiceProviderEntityId("http://localhost:8080/callback?client_name=SAML2Client");

        cfg.setServiceProviderMetadataPath("sp-metadata.xml");
        final SAML2Client saml2Client = new SAML2Client(cfg);

        final Clients clients = new Clients("http://localhost:8080/callback", saml2Client);

        final Config config = new Config(clients);
        //config.addAuthorizer("admin", new RequireAnyRoleAuthorizer("ROLE_ADMIN"));
        //config.addAuthorizer("custom", new CustomAuthorizer());
        return config;
    }
}

从这个示例代码中,我们已经有了 IDP 元数据,没关系,我们只要求 IDP 提供元数据,我们可以直接使用。

但是 sp-metadata.xml 在哪里?我们需要生成它并提供给 idp 以实现集成目的。

如果我使用的是 springSaml,它提供了一个 UI 来生成这个元数据,我们只需要下载并发送给 IDP。但是对于 pac4j saml,我根本看不到这个实用程序。那么任何人都可以帮助告诉我生成 sp 元数据的最佳解决方案是什么?

谢谢

【问题讨论】:

    标签: java saml saml-2.0


    【解决方案1】:

    我设法通过在 SecurityModule 配置中使用此设置来生成它。这可能不是最好的方法,但我仍在寻找最好的方法。

    cfg.setServiceProviderMetadataPath(new File("yourPath", "fileName.xml").getAbsolutePath())
    

    请注意,SPMetata 仅在发生 SAML 请求时生成。

    【讨论】:

      【解决方案2】:

      如果您在使用 pac4j 和 TestShib 时遇到此问题,请确保您的身份提供者元数据是最新的,即使用来自 the TestShib website 的那个更新您的本地 testshib-providers.xml。

      【讨论】:

        【解决方案3】:

        saml2Client.init() 完成生成 sp-metadata 的所有工作,只需确保您有足够的权限在指定路径上创建文件。

        saml2Client.getConfiguration().setServiceProviderMetadataResource(new FileSystemResource(new File("C:\\sp-metadata.xml").getAbsolutePath()));
        saml2Client.init();
        String spMetadata = saml2Client.getServiceProviderMetadataResolver().getMetadata();
        

        【讨论】:

          猜你喜欢
          • 2016-08-25
          • 2015-02-03
          • 2014-07-25
          • 1970-01-01
          • 2020-02-10
          • 1970-01-01
          • 2014-12-20
          • 2016-09-01
          • 2017-12-17
          相关资源
          最近更新 更多