Class Metadata

java.lang.Object
com.onelogin.saml2.settings.Metadata

public class Metadata extends Object
Metadata class of OneLogin's Java Toolkit. A class that contains methods related to the metadata of the SP
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
      Private property to construct a logger for this class.
    • N_DAYS_VALID_UNTIL

      private static final int N_DAYS_VALID_UNTIL
      See Also:
    • SECONDS_CACHED

      private static final int SECONDS_CACHED
      See Also:
    • attributeConsumingService

      private AttributeConsumingService attributeConsumingService
      AttributeConsumingService
    • metadataString

      private final String metadataString
      Generated metadata in string format
    • validUntilTime

      private final Calendar validUntilTime
      validUntilTime of the metadata. How long the metadata is valid
    • cacheDuration

      private final Integer cacheDuration
      cacheDuration of the metadata. Duration of the cache in seconds
  • Constructor Details

  • Method Details

    • postProcessXml

      protected String postProcessXml(String metadataXml, Saml2Settings settings)
      Allows for an extension class to post-process the SAML metadata XML generated for this metadata instance, in order to customize the result.

      This method is invoked at construction time, after all the other fields of this class have already been initialised. Its default implementation simply returns the input XML as-is, with no change.

      Parameters:
      metadataXml - the XML produced for this metadata instance by the standard implementation provided by Metadata
      settings - the settings
      Returns:
      the post-processed XML for this metadata instance, which will then be returned by any call to getMetadataString()
    • generateSubstitutor

      private org.apache.commons.lang3.text.StrSubstitutor generateSubstitutor(Saml2Settings settings) throws CertificateEncodingException
      Substitutes metadata variables within a string by values.
      Parameters:
      settings - Saml2Settings object. Setting data
      Returns:
      the StrSubstitutor object of the metadata
      Throws:
      CertificateEncodingException
    • getMetadataTemplate

      private static StringBuilder getMetadataTemplate()
      Returns:
      the metadata's template
    • getAttributeConsumingServiceXml

      private String getAttributeConsumingServiceXml()
      Generates the AttributeConsumingService section of the metadata's template
      Returns:
      the AttributeConsumingService section of the metadata's template
    • toContactsXml

      private String toContactsXml(List<Contact> contacts)
      Generates the contact section of the metadata's template
      Parameters:
      contacts - List of contact objects
      Returns:
      the contact section of the metadata's template
    • toOrganizationXml

      private String toOrganizationXml(Organization organization)
      Generates the organization section of the metadata's template
      Parameters:
      organization - organization object
      Returns:
      the organization section of the metadata's template
    • toX509KeyDescriptorsXML

      private String toX509KeyDescriptorsXML(X509Certificate cert, Boolean wantsEncrypted) throws CertificateEncodingException
      Generates the KeyDescriptor section of the metadata's template
      Parameters:
      cert - the public cert that will be used by the SP to sign and encrypt
      wantsEncrypted - Whether to include the KeyDescriptor for encryption
      Returns:
      the KeyDescriptor section of the metadata's template
      Throws:
      CertificateEncodingException
    • toX509KeyDescriptorsXML

      private String toX509KeyDescriptorsXML(X509Certificate certCurrent, X509Certificate certNew, Boolean wantsEncrypted) throws CertificateEncodingException
      Generates the KeyDescriptor section of the metadata's template
      Parameters:
      certCurrent - the public cert that will be used by the SP to sign and encrypt
      certNew - the public cert that will be used by the SP to sign and encrypt in future
      wantsEncrypted - Whether to include the KeyDescriptor for encryption
      Returns:
      the KeyDescriptor section of the metadata's template
      Throws:
      CertificateEncodingException
    • toSLSXml

      private String toSLSXml(URL spSingleLogoutServiceUrl, String spSingleLogoutServiceBinding)
      Returns:
      the md:SingleLogoutService section of the metadata's template
    • getMetadataString

      public final String getMetadataString()
      Returns:
      the metadata
    • signMetadata

      public static String signMetadata(String metadata, PrivateKey key, X509Certificate cert, String signAlgorithm) throws XPathExpressionException, org.apache.xml.security.exceptions.XMLSecurityException
      Signs the metadata with the key/cert provided
      Parameters:
      metadata - SAML Metadata XML
      key - Private Key
      cert - x509 Public certificate
      signAlgorithm - Signature Algorithm
      Returns:
      string Signed Metadata
      Throws:
      org.apache.xml.security.exceptions.XMLSecurityException
      XPathExpressionException
    • signMetadata

      public static String signMetadata(String metadata, PrivateKey key, X509Certificate cert, String signAlgorithm, String digestAlgorithm) throws XPathExpressionException, org.apache.xml.security.exceptions.XMLSecurityException
      Signs the metadata with the key/cert provided
      Parameters:
      metadata - SAML Metadata XML
      key - Private Key
      cert - x509 Public certificate
      signAlgorithm - Signature Algorithm
      digestAlgorithm - Digest Algorithm
      Returns:
      string Signed Metadata
      Throws:
      org.apache.xml.security.exceptions.XMLSecurityException
      XPathExpressionException