Class SAML2MetaUtils


  • public final class SAML2MetaUtils
    extends Object
    The SAML2MetaUtils provides metadata related util methods.
    • Method Detail

      • getMetaJAXBContext

        public static JAXBContext getMetaJAXBContext()
        Returns JAXB context for the metadata service.
        Returns:
        JAXB context object.
      • convertStringToJAXB

        public static Object convertStringToJAXB​(String str)
                                          throws JAXBException
        Converts a String object to a JAXB object.
        Parameters:
        str - a String object
        Returns:
        a JAXB object converted from the String object.
        Throws:
        JAXBException - if an error occurs while converting String object
      • convertInputStreamToJAXB

        public static Object convertInputStreamToJAXB​(InputStream is)
                                               throws JAXBException
        Reads from the InputStream and converts to a JAXB object.
        Parameters:
        is - a InputStream object
        Returns:
        a JAXB object converted from the InputStream object.
        Throws:
        JAXBException - if an error occurs while converting InputStream object
      • convertNodeToJAXB

        public static Object convertNodeToJAXB​(Node node)
                                        throws JAXBException
        Converts a Node object to a JAXB object.
        Parameters:
        node - a Node object
        Returns:
        a JAXB object converted from the Node object.
        Throws:
        JAXBException - if an error occurs while converting Node object
      • convertJAXBToString

        public static String convertJAXBToString​(Object jaxbObj)
                                          throws JAXBException
        Converts a JAXB object to a String object.
        Parameters:
        jaxbObj - a JAXB object
        Returns:
        a String representing the JAXB object.
        Throws:
        JAXBException - if an error occurs while converting JAXB object
      • convertJAXBToOutputStream

        public static void convertJAXBToOutputStream​(Object jaxbObj,
                                                     OutputStream os)
                                              throws JAXBException
        Converts a JAXB object and writes to an OutputStream object.
        Parameters:
        jaxbObj - a JAXB object
        os - an OutputStream object
        Throws:
        JAXBException - if an error occurs while converting JAXB object
      • convertJAXBToAttrMap

        protected static Map convertJAXBToAttrMap​(String attrName,
                                                  Object jaxbObj)
                                           throws JAXBException
        Converts a JAXB object to a String object and creates a Map. The key is 'attrName' and the value is a Set contains the String object.
        Parameters:
        attrName - attribute name
        jaxbObj - a JAXB object
        Returns:
        a Map. The key is 'attrName' and the value is a Set contains the String object converted from the JAXB object.
        Throws:
        JAXBException - if an error occurs while converting JAXB object
      • getAttributes

        public static Map<String,​List<String>> getAttributes​(BaseConfigType config)
        Gets attribute value pairs from BaseConfigType and put in a Map. The key is attribute name and the value is a List of attribute values;
        Parameters:
        config - the BaseConfigType object
        Returns:
        a attrbute value Map
      • getRealmByMetaAlias

        public static String getRealmByMetaAlias​(String metaAlias)
        Returns the realm by parsing the metaAlias. MetaAlias format is
         <realm>/<any string without '/'> for non-root realm or
         /<any string without '/'> for root realm.
         
        Parameters:
        metaAlias - The metaAlias.
        Returns:
        the realm associated with the metaAlias.
      • getMetaAliasByUri

        public static String getMetaAliasByUri​(String uri)
        Returns metaAlias embedded in uri.
        Parameters:
        uri - The uri string.
        Returns:
        the metaAlias embedded in uri or null if not found.
      • getPolicyDecisionPointDescriptor

        public static XACMLPDPDescriptorElement getPolicyDecisionPointDescriptor​(EntityDescriptorElement eDescriptor)
        Returns first policy decision point descriptor in an entity descriptor.
        Parameters:
        eDescriptor - The entity descriptor.
        Returns:
        policy decision point descriptor or null if it is not found.
      • getPolicyEnforcementPointDescriptor

        public static XACMLAuthzDecisionQueryDescriptorElement getPolicyEnforcementPointDescriptor​(EntityDescriptorElement eDescriptor)
        Returns first policy enforcement point descriptor in an entity descriptor.
        Parameters:
        eDescriptor - The entity descriptor.
        Returns:
        policy enforcement point descriptor or null if it is not found.
      • getSPSSODescriptor

        public static SPSSODescriptorElement getSPSSODescriptor​(EntityDescriptorElement eDescriptor)
        Returns first service provider's SSO descriptor in an entity descriptor.
        Parameters:
        eDescriptor - The entity descriptor.
        Returns:
        SPSSODescriptorElement for the entity or null if not found.
      • getIDPSSODescriptor

        public static IDPSSODescriptorElement getIDPSSODescriptor​(EntityDescriptorElement eDescriptor)
        Returns first identity provider's SSO descriptor in an entity descriptor.
        Parameters:
        eDescriptor - The entity descriptor.
        Returns:
        IDPSSODescriptorElement for the entity or null if not found.
      • getAttributeAuthorityDescriptor

        public static AttributeAuthorityDescriptorElement getAttributeAuthorityDescriptor​(EntityDescriptorElement eDescriptor)
        Returns attribute authority descriptor in an entity descriptor.
        Parameters:
        eDescriptor - The entity descriptor.
        Returns:
        an AttributeAuthorityDescriptorElement object for the entity or null if not found.
      • getAttributeQueryDescriptor

        public static AttributeQueryDescriptorElement getAttributeQueryDescriptor​(EntityDescriptorElement eDescriptor)
        Returns attribute query descriptor in an entity descriptor.
        Parameters:
        eDescriptor - The entity descriptor.
        Returns:
        an AttributeQueryDescriptorElement object for the entity or null if not found.
      • getAuthnAuthorityDescriptor

        public static AuthnAuthorityDescriptorElement getAuthnAuthorityDescriptor​(EntityDescriptorElement eDescriptor)
        Returns authentication authority descriptor in an entity descriptor.
        Parameters:
        eDescriptor - The entity descriptor.
        Returns:
        an AuthnAuthorityDescriptorElement object for the entity or null if not found.
      • getFirstEntry

        public static String getFirstEntry​(Map attrMap,
                                           String key)
        Get the first value of set by given key searching in the given map. return null if attrMap is null or key is null.
        Parameters:
        attrMap - Map of which set is to be added.
        key - Key of the entry to be added.
        Returns:
        the first value of a matching set by the given key.
      • fillEntriesInSet

        public static void fillEntriesInSet​(Map attrMap,
                                            String key,
                                            String value)
        Adds a set of a given value to a map. Set will not be added if attrMap is null or value is null or key is null.
        Parameters:
        attrMap - Map of which set is to be added.
        key - Key of the entry to be added.
        value - Value to be added to the Set.
      • getSPSSOConfig

        public static SPSSOConfigElement getSPSSOConfig​(EntityConfigElement eConfig)
                                                 throws SAML2MetaException
        Returns first service provider's SSO configuration in an entity.
        Parameters:
        eConfig - EntityConfigElement of the entity to be retrieved.
        Returns:
        SPSSOConfigElement for the entity or null if not found.
        Throws:
        SAML2MetaException - if unable to retrieve the first service provider's SSO configuration.
      • getIDPSSOConfig

        public static IDPSSOConfigElement getIDPSSOConfig​(EntityConfigElement eConfig)
                                                   throws SAML2MetaException
        Returns first identity provider's SSO configuration in an entity
        Parameters:
        eConfig - EntityConfigElement of the entity to be retrieved.
        Returns:
        IDPSSOConfigElement for the entity or null if not found.
        Throws:
        SAML2MetaException - if unable to retrieve the first identity provider's SSO configuration.
      • getEntityDescriptorElement

        public static EntityDescriptorElement getEntityDescriptorElement​(String metadata)
                                                                  throws SAML2MetaException,
                                                                         JAXBException
        Parameters:
        metadata - A string representing an EntityDescriptorElement XML document
        Returns:
        EntityDescriptorElement an EntityDescriptorElement from the passed metadata
        Throws:
        SAML2MetaException - If there was a problem with the parsed metadata
        JAXBException - If there was a problem parsing the metadata
      • importSAML2Document

        public static List<String> importSAML2Document​(SAML2MetaManager metaManager,
                                                       String realm,
                                                       Document doc)
                                                throws SAML2MetaException,
                                                       JAXBException
        For the given XML metadata document representing either a SAML2 EntityDescriptorElement or EntitiesDescriptorElement, return a list of entityId's for all the Entities created. Carries out a signature validation of the document as part of the import process.
        Parameters:
        metaManager - An instance of the SAML2MetaManager, used to do the actual create.
        realm - The realm to create the Entities in
        doc - The XML document that represents either an EntityDescriptorElement or EntitiesDescriptorElement
        Returns:
        A list of all entityId's imported or an empty list if no Entities were imported.
        Throws:
        SAML2MetaException - for any issues as a result of trying to create the Entities.
        JAXBException - for any issues converting the document into a JAXB document.