我现在正在比较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 metaData,这很好,我们只需要IDP提供metaData,我们可以直接使用。
但是sp-metadata.xml在哪里呢?我们需要生成它并将其提供给idp以达到集成的目的。
如果我使用的是springSaml,它提供了一个UI来生成这个metaData,我们只需要下载并发送到IDP。但是对于pac4j saml,我根本看不到这个实用程序。那么,谁能告诉我生成sp metaData的最佳解决方案是什么?
谢谢
发布于 2020-01-02 17:07:42
saml2Client.init()执行生成sp元数据的所有工作,只需确保您有足够的权限在指定路径上创建文件即可。
saml2Client.getConfiguration().setServiceProviderMetadataResource(new FileSystemResource(new File("C:\\sp-metadata.xml").getAbsolutePath()));
saml2Client.init();
String spMetadata = saml2Client.getServiceProviderMetadataResolver().getMetadata();发布于 2016-12-27 13:09:45
通过在SecurityModule配置中使用此设置,我设法生成了它。这可能不是最好的方法,但我还是想出了最好的方法。
cfg.setServiceProviderMetadataPath(new File("yourPath", "fileName.xml").getAbsolutePath())请注意,SPMetata仅在发生SAML请求时生成。
发布于 2017-12-15 22:30:22
如果您在使用pac4j和TestShib时遇到此问题,请确保您的身份提供程序元数据是最新的,即使用the TestShib website中的元数据更新本地testshib-providers.xml。
https://stackoverflow.com/questions/40078459
复制相似问题