使用OpenSAML v3从IDP元数据创建凭证对象

时间:2017-02-20 15:46:23

标签: single-sign-on saml saml-2.0 opensaml

我正在尝试验证我从SSO Sircle(IDP)回来的SAML响应。为了做到这一点,我使用SSO圈子(https://idp.ssocircle.com/idp-meta.xml)提供的IDP元数据,以便使用IDP公钥创建凭证对象,如下所示:

    FilesystemMetadataResolver idpMetadataResolver = new  FilesystemMetadataResolver(new File("C:\\idp_metadata.xml"));
    idpMetadataResolver.setRequireValidMetadata(true);
    idpMetadataResolver.setParserPool(new BasicParserPool());
    idpMetadataResolver.initialize();

    MetadataCredentialResolver credentialResolver = new MetadataCredentialResolver();

    credentialResolver.setRoleDescriptorResolver(new BasicRoleDescriptorResolver(idpMetadataResolver));

    CriteriaSet criteriaSet = new CriteriaSet();
    criteriaSet.add(new EntityIdCriterion("https://idp.ssocircle.com"));
    criteriaSet.add(new EntityRoleCriterion(IDPSSODescriptor.DEFAULT_ELEMENT_NAME));

    X509Credential credential = (X509Credential)credentialResolver.resolveSingle(criteriaSet);

但是,这会在尝试初始化idpMetadataResolver时抛出异常:

net.shibboleth.utilities.java.support.component.ComponentInitializationException: Component identifier can not be null
at net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent.doInitialize(AbstractIdentifiedInitializableComponent.java:65)
at org.opensaml.saml.metadata.resolver.impl.AbstractMetadataResolver.doInitialize(AbstractMetadataResolver.java:188)
at net.shibboleth.utilities.java.support.component.AbstractInitializableComponent.initialize(AbstractInitializableComponent.java:61)

我是OpenSAML的新手,我主要在线查看示例和教程,但大多数是为OpenSAML v2.0编写的。我想知道在初始化对象时我是否做错了什么。

1 个答案:

答案 0 :(得分:1)

在对OpenSAML 3 Java文档和Shibboleth开发社区进行一些挖掘后,我想我找到了一个问题的答案。元数据解析程序对象需要按如下方式设置:

    FilesystemMetadataResolver idpMetadataResolver = new FilesystemMetadataResolver(new File("C:\\idp.xml"));
    idpMetadataResolver.setRequireValidMetadata(true);
    idpMetadataResolver.setParserPool(XMLObjectProviderRegistrySupport.getParserPool());
    idpMetadataResolver.setId("someidentifier");
    idpMetadataResolver.initialize();