pac4j saml生成sp metaData

时间:2016-10-17 04:23:08

标签: java saml saml-2.0

我现在正在比较spring saml和pac4j saml。一般来说,我认为pac4j比spring sj​​l更容易实现。但有一点我无法弄清楚: 请参阅此配置代码:

@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提供metaData,我们可以直接使用。

但是sp-metadata.xml在哪里?我们需要生成它并为idp提供整合目的。

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

由于

3 个答案:

答案 0 :(得分:0)

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

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

请注意,只有在发生SAML请求时才会生成SPMetata。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

saml2Client.init()会执行生成sp-元数据的所有工作,只是确保您具有足够的权限在指定路径上创建文件。

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