Class WSSecurityUtil


  • public final class WSSecurityUtil
    extends Object
    WS-Security Utility methods.

    • Method Detail

      • getSecurityHeader

        public static Element getSecurityHeader​(Document doc,
                                                String actor)
                                         throws WSSecurityException
        Returns the first WS-Security header element for a given actor. Only one WS-Security header is allowed for an actor.
        Parameters:
        doc -
        actor -
        Returns:
        the wsse:Security element or null if not such element found
        Throws:
        WSSecurityException
      • isActorEqual

        public static boolean isActorEqual​(String actor,
                                           String hActor)
        Compares two actor strings and returns true if these are equal. Takes care of the null length strings and uses ignore case.
        Parameters:
        actor -
        hActor -
        Returns:
        true is the actor arguments are equal
      • getDirectChildElements

        public static List<Element> getDirectChildElements​(Node fNode,
                                                           String localName,
                                                           String namespace)
        Gets all direct children with specified localname and namespace.

        Parameters:
        fNode - the node where to start the search
        localName - local name of the children to get
        namespace - the namespace of the children to get
        Returns:
        the list of nodes or null if not such nodes are found
      • findBodyElement

        public static Element findBodyElement​(Document doc)
        return the first soap "Body" element.

        Parameters:
        doc -
        Returns:
        the body element or null if document does not contain a SOAP body
      • findElements

        public static List<Element> findElements​(WSEncryptionPart part,
                                                 CallbackLookup callbackLookup,
                                                 Document doc)
                                          throws WSSecurityException
        Find the DOM Element in the SOAP Envelope that is referenced by the WSEncryptionPart argument. The "Id" is used before the Element localname/namespace.
        Parameters:
        part - The WSEncryptionPart object corresponding to the DOM Element(s) we want
        callbackLookup - The CallbackLookup object used to find Elements
        doc - The owning document
        Returns:
        the DOM Element in the SOAP Envelope that is found
        Throws:
        WSSecurityException
      • getDefaultEncryptionPart

        public static WSEncryptionPart getDefaultEncryptionPart​(Document doc)
        Get the default encryption part - the SOAP Body of type "Content".
      • prependChildElement

        public static Element prependChildElement​(Element parent,
                                                  Element child)
        prepend a child element

        Parameters:
        parent - element of this child element
        child - the element to append
        Returns:
        the child element
      • findWsseSecurityHeaderBlock

        public static Element findWsseSecurityHeaderBlock​(Document doc,
                                                          Element envelope,
                                                          boolean doCreate)
                                                   throws WSSecurityException
        find the first ws-security header block

        Parameters:
        doc - the DOM document (SOAP request)
        envelope - the SOAP envelope
        doCreate - if true create a new WSS header block if none exists
        Returns:
        the WSS header or null if none found and doCreate is false
        Throws:
        WSSecurityException
      • findWsseSecurityHeaderBlock

        public static Element findWsseSecurityHeaderBlock​(Document doc,
                                                          Element envelope,
                                                          String actor,
                                                          boolean doCreate)
                                                   throws WSSecurityException
        find a WS-Security header block for a given actor

        Parameters:
        doc - the DOM document (SOAP request)
        envelope - the SOAP envelope
        actor - the actor (role) name of the WSS header
        doCreate - if true create a new WSS header block if none exists
        Returns:
        the WSS header or null if none found and doCreate is false
        Throws:
        WSSecurityException
      • createBase64EncodedTextNode

        public static Text createBase64EncodedTextNode​(Document doc,
                                                       byte[] data)
        create a base64 test node

        Parameters:
        doc - the DOM document (SOAP request)
        data - to encode
        Returns:
        a Text node containing the base64 encoded data
      • getSOAPNamespace

        public static String getSOAPNamespace​(Element startElement)
      • decodeHandlerAction

        public static List<HandlerAction> decodeHandlerAction​(String action,
                                                              WSSConfig wssConfig)
                                                       throws WSSecurityException
        Decode an action String. This method should only be called on the outbound side.
        Parameters:
        action - The initial String of actions to perform
        wssConfig - This object holds the list of custom actions to be performed.
        Returns:
        The list of HandlerAction Objects
        Throws:
        WSSecurityException
      • generateNonce

        public static byte[] generateNonce​(int length)
                                    throws WSSecurityException
        Generate a nonce of the given length using the SHA1PRNG algorithm. The SecureRandom instance that backs this method is cached for efficiency.
        Returns:
        a nonce of the given length
        Throws:
        WSSecurityException
      • cloneElement

        public static Element cloneElement​(Document doc,
                                           Element clonedElement)
                                    throws WSSecurityException
        Register the javax.xml.soap.Node with new Cloned Dom Node with java9
        Parameters:
        doc - The SOAPDocumentImpl
        clonedElement - The cloned Element
        Returns:
        new clonedElement which already associated with the SAAJ Node
        Throws:
        WSSecurityException