Я пытаюсь получить узел RoleDescriptor
файла метаданных поставщика услуг (SAML 2.0), используя следующий код и библиотеки OpenSaml:
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>[email protected]</EmailAddress>
</ContactPerson>
</EntityDescriptor>
И, наконец, сканирование моего отладочного экрана Eclipse:
Я попытался проверить ваш метаданные 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,
Элемент RoleDescriptor представляет собой абстрактную точку расширения, которая содержит общую описательную информацию, предназначенную для обеспечения унификации обработки в разных ролях. Новые роли можно определить, расширив свой абстрактный тип RoleDescriptorType
Таким образом, вы не можете иметь элемент RoleDescriptor в вашем метаданных xml. Либо вы должны использовать конкретную роль, описанную в спецификации (SSO Identity Provider, SSO Service Provider, Authentication Authority, Attribute Authority, Policy Decision Point, Affiliation) или расширить абстрактный RoleDescriptor.
Поэтому из-за вышеуказанной причины org.opensaml.saml2.metadata.impl.RoleDescriptorImpl
является абстрактным классом в opensaml, и реализации конкретных ролей расширяет этот абстрактный класс.