Class SAMLUtilsCommon

  • Direct Known Subclasses:
    SAMLUtils

    public class SAMLUtilsCommon
    extends Object
    This class contains a set of generic common utility methods.
    • Field Detail

      • random

        public static SecureRandom random
        SecureRandom instance.
      • bundle

        public static ResourceBundle bundle
        SAML resource bundle object.
      • debug

        public static Debug debug
        SAML debug object.
    • Constructor Detail

      • SAMLUtilsCommon

        public SAMLUtilsCommon()
    • Method Detail

      • setResourceBundle

        public static void setResourceBundle​(ResourceBundle resBundle)
        Sets the ResourceBundle of the service.
        Parameters:
        resBundle - ResourceBundle instance to be set.
      • setDebugInstance

        public static void setDebugInstance​(Debug dbg)
        Sets the Debug of the service.
        Parameters:
        dbg - Debug instance to be set.
      • generateAssertionID

        public static String generateAssertionID()
        Generates an ID String with length of SAMLConstants.ID_LENGTH.
        Returns:
        string the ID String; or null if it fails.
      • generateID

        public static String generateID()
        Generates an ID String with length of SAMLConstants.ID_LENGTH.
        Returns:
        string the ID String; or null if it fails.
      • byteArrayToHexString

        public static String byteArrayToHexString​(byte[] byteArray)
        Converts a byte array to a hex string.
      • makeEndElementTagXML

        public static String makeEndElementTagXML​(String elementName,
                                                  boolean includeNS)
        Generates end element tag. It takes in the name of element and produces a String as output which is in XML format. For example given "SubjectConfirmation", It produces output like </saml:SubjectConfirmation> if includeNS is true else produces </SubjectConfirmation>
        Parameters:
        elementName - name of an element
        includeNS - true to include namespace prefix; false otherwise.
        Returns:
        String which is an xml element end tag.
      • makeStartElementTagXML

        public static String makeStartElementTagXML​(String elementName,
                                                    boolean includeNS,
                                                    boolean declareNS)
        Generates xml element start tag. This utility method takes in the name fo element and produces a String as output which is in XML format. For example given "SubjectConfirmation". It produces output like <saml:SubjectConfirmation xmlns:saml= "http://www.oasis-open.org/committees/security/docs/ draft-sstc-schema-assertion-16.xsd"> where nameSpace is defined in AssertionBase class if declareNS and includeNS are true.
        Parameters:
        elementName - name of the element.
        includeNS - true to include namespace prefix; false otherwise.
        declareNS - true to include namespace declaration; false otherwise.
        Returns:
        xml element start tag.
      • checkStatement

        public static boolean checkStatement​(Element element,
                                             String statementname)
        Verifies if an element is a type of a specific statement. Currently, this method is used by class AuthenticationStatement, AuthorizationDecisionStatement and AttributeStatement.
        Parameters:
        element - a DOM Element which needs to be verified.
        statementname - A specific name of a statement, for example, AuthenticationStatement, AuthorizationDecisionStatement or AttributeStatement
        Returns:
        true if the element is of the specified type; false otherwise.
      • decodePassword

        public static String decodePassword​(String password)
        Decodes a password. The value passed is the value to be decoded using the decoder class defined in FederationConfig.properties. The decoded value will be returned unless the decoder class is not defined, or cannot be located. In that case, the original value will be returned.
        Parameters:
        password - original password.
        Returns:
        decoded password.
      • removeNewLineChars

        public static String removeNewLineChars​(String s)
        Removes new line charactors.
        Parameters:
        s - A String to be checked.
        Returns:
        a String with new line charactor removed.
      • getDecodedSourceIDString

        public static String getDecodedSourceIDString​(String encodedID)
        Decodes the Base64 encoded sourceid and returns a String of the raw-byte source id.
        Parameters:
        encodedID - A String representing the Base64 encoded source id.
        Returns:
        A String representing the raw byte source id.
      • byteArrayToString

        public static String byteArrayToString​(byte[] bytes)
        Converts byte array to string.
        Parameters:
        bytes - byte array to be converted.
        Returns:
        result string.