ePrivacy and GPDR Cookie Consent by Cookie Consent

Reading metadata with OpenSAML

OpenSAML have several methods for reading and parsings SAML metadata.

Meta data is loaded using providers. For example

FilesystemMetadataProvider - Used to load data from a file on the filesystem HTTPMetadataProvider - Used to load data from an Internet address

Here is an example on how to load meta data using the FilesystemMetadataProvider.

1FilesystemMetadataProvider idpMetaDataProvider = new FilesystemMetadataProvider(new File("path to file"));
2idpMetaDataProvider.setRequireValidMetadata(true);
3idpMetaDataProvider.setParserPool(new BasicParserPool());
4idpMetaDataProvider.initialize();
5EntityDescriptor idpEntityDescriptor = idpMetaDataProvider.getEntityDescriptor("Some entity id");

The EntityDescriptor can then be used to extract data from the metadata. Here are some examples on how to use it.

SSO services

1SingleSignOnService redirectEndpoint = null;
2for (SingleSignOnService sss : idpEntityDescriptor.getIDPSSODescriptor(SAMLConstants.SAML20P_NS).getSingleSignOnServices()) {
3   if (sss.getBinding().equals(SAMLConstants.SAML2_REDIRECT_BINDING_URI)) {
4      redirectEndpoint = sss;
5   }
6}

ArtifactResolutionService

1for (ArtifactResolutionService ars : idpEntityDescriptor.getIDPSSODescriptor(SAMLConstants.SAML20P_NS)
2      .getArtifactResolutionServices()) {
3   if (ars.getBinding().equals(SAMLConstants.SAML2_SOAP11_BINDING_URI)) {
4      artifactResolutionServiceURL = ars.getLocation();
5   }
6}

The objects of OpenSAML metadata follows the structure of the metadata XML, so if you look at the XML it pretty easy to figure out how to read it with OpenSAML.