OpenSaml 检索错误的 RoleDescriptor 对象

OpenSaml retrieving wrong RoleDescriptor object

我正在尝试使用以下代码和 OpenSaml 库从服务提供商元数据文件 (SAML 2.0) 中检索 RoleDescriptor 节点:

EntitiesDescriptor entityDescriptors = getConfiguration(providerId);
List<RoleDescriptor> roleDescriptors = (List<RoleDescriptor>) entityDescriptors.getEntityDescriptors().get(0).
            getRoleDescriptors();
EntityDescriptor ed = entityDescriptors.getEntityDescriptors().get(0);
if(roleDescriptors != null && !roleDescriptors.isEmpty()){
    RoleDescriptor r = (RoleDescriptor) roleDescriptors.get(0); 
    return roleDescriptors.get(0).getErrorURL();
}

我的问题是变量 r 最终是 org.opensaml.saml2.metadata.impl.SPSSODescriptorImpl 类型而不是 org.opensaml.saml2.metadata.impl.RoleDescriptorImpl

这是我正在使用的元数据 xml 文件:

<EntityDescriptor entityID="http://mysp.com/resource">

    <RoleDescriptor errorURL="http://localhost:8080/dummy-sp/error.jsp">
    </RoleDescriptor>

    <SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
        <KeyDescriptor use="encryption">
            <EncryptionMethod Algorithm=
                "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256">
            </EncryptionMethod>
        </KeyDescriptor>

        <AssertionConsumerService index="1"
            isDefault="true" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
            Location="http://localhost:8080/dummy-sp/dummysp" />

    </SPSSODescriptor>

    <Organization>
        <OrganizationName xml:lang="en">Your Service
        </OrganizationName>
        <OrganizationDisplayName xml:lang="en">Your
            Service
        </OrganizationDisplayName>
        <OrganizationURL xml:lang="en">http://sp.example.org/
        </OrganizationURL>
    </Organization>
    <ContactPerson contactType="technical">
        <GivenName>Your</GivenName>
        <SurName>Admin</SurName>
        <EmailAddress>admin@example.org</EmailAddress>
    </ContactPerson>

</EntityDescriptor>

最后扫描了我的 Eclipse 调试屏幕:

http://imgur.com/01xRD5f

我尝试使用此处描述的方法验证您的元数据 xml。 https://wiki.surfnet.nl/display/OpenConext/Validating+SAML2+metadata

它表示该元素(在添加元数据命名空间之后)

RoleDescriptor: Schemas validity error : Element '{urn:oasis:names:tc:SAML:2.0:metadata}RoleDescriptor': The type definition is abstract.

正如 saml 元数据规范所说,

The RoleDescriptor element is an abstract extension point that contains common descriptive information intended to provide processing commonality across different roles. New roles can be defined by extending its abstract RoleDescriptorType complex type

所以您的元数据中不能有 RoleDescriptor 元素 xml。您必须使用规范中描述的具体角色(SSO 身份提供者、SSO 服务提供者、身份验证机构、属性机构、策略决策点、从属关系)或扩展抽象 RoleDescriptor。

所以由于上述原因,org.opensaml.saml2.metadata.impl.RoleDescriptorImpl在opensaml中是一个抽象class,具体角色的实现扩展了这个抽象class。