Package org.apache.wss4j.dom.util
Class WSSecurityUtil
- java.lang.Object
-
- org.apache.wss4j.dom.util.WSSecurityUtil
-
public final class WSSecurityUtil extends Object
WS-Security Utility methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ElementcloneElement(Document doc, Element clonedElement)Register the jakarta.xml.soap.Node with new Cloned Dom Node with java9static TextcreateBase64EncodedTextNode(Document doc, byte[] data)create a base64 test nodestatic List<Integer>decodeAction(String action)static List<HandlerAction>decodeHandlerAction(String action, WSSConfig wssConfig)Decode an action String.static ElementfindBodyElement(Document doc)return the first soap "Body" element.static List<Element>findElements(WSEncryptionPart part, CallbackLookup callbackLookup)Find the DOM Element in the SOAP Envelope that is referenced by the WSEncryptionPart argument.static ElementfindWsseSecurityHeaderBlock(Document doc, Element envelope, boolean doCreate)find the first ws-security header blockstatic ElementfindWsseSecurityHeaderBlock(Document doc, Element envelope, String actor, boolean doCreate)find a WS-Security header block for a given actorstatic StringgetAttachmentId(String xopUri)static byte[]getBytesFromAttachment(String xopUri, CallbackHandler attachmentCallbackHandler)static byte[]getBytesFromAttachment(String xopUri, CallbackHandler attachmentCallbackHandler, boolean removeAttachments)static byte[]getBytesFromAttachment(String xopUri, RequestData data)static WSEncryptionPartgetDefaultEncryptionPart(Document doc)Get the default encryption part - the SOAP Body of type "Content".static List<Element>getDirectChildElements(Node fNode, String localName, String namespace)Gets all direct children with specified localname and namespace.static ElementgetSecurityHeader(Document doc, String actor)Returns the first WS-Security header element for a given actor.static ElementgetSecurityHeader(Element soapHeader, String actor, boolean soap12)Returns the first WS-Security header element for a given actor.static SOAPConstantsgetSOAPConstants(Element startElement)static ElementgetSOAPHeader(Document doc)static StringgetSOAPNamespace(Element startElement)static voidinlineAttachments(List<Element> includeElements, CallbackHandler attachmentCallbackHandler, boolean removeAttachments)static booleanisActorEqual(String actor, String hActor)Compares two actor strings and returns true if these are equal.static ElementprependChildElement(Element parent, Element child)prepend a child element
-
-
-
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:Securityelement ornullif not such element found - Throws:
WSSecurityException
-
getSecurityHeader
public static Element getSecurityHeader(Element soapHeader, String actor, boolean soap12) throws WSSecurityException
Returns the first WS-Security header element for a given actor. Only one WS-Security header is allowed for an actor.- 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 searchlocalName- local name of the children to getnamespace- the namespace of the children to get- Returns:
- the list of nodes or
nullif 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
nullif document does not contain a SOAP body
-
findElements
public static List<Element> findElements(WSEncryptionPart part, CallbackLookup callbackLookup) 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 wantcallbackLookup- The CallbackLookup object used to find Elements- 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 elementchild- 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 envelopedoCreate- 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 envelopeactor- the actor (role) name of the WSS headerdoCreate- 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
-
getSOAPConstants
public static SOAPConstants getSOAPConstants(Element startElement)
-
decodeAction
public static List<Integer> decodeAction(String action) throws WSSecurityException
- Throws:
WSSecurityException
-
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 performwssConfig- This object holds the list of custom actions to be performed.- Returns:
- The list of HandlerAction Objects
- Throws:
WSSecurityException
-
inlineAttachments
public static void inlineAttachments(List<Element> includeElements, CallbackHandler attachmentCallbackHandler, boolean removeAttachments) throws WSSecurityException
- Throws:
WSSecurityException
-
cloneElement
public static Element cloneElement(Document doc, Element clonedElement) throws WSSecurityException
Register the jakarta.xml.soap.Node with new Cloned Dom Node with java9- Parameters:
doc- The SOAPDocumentImplclonedElement- The cloned Element- Returns:
- new clonedElement which already associated with the SAAJ Node
- Throws:
WSSecurityException
-
getBytesFromAttachment
public static byte[] getBytesFromAttachment(String xopUri, RequestData data) throws WSSecurityException
- Throws:
WSSecurityException
-
getBytesFromAttachment
public static byte[] getBytesFromAttachment(String xopUri, CallbackHandler attachmentCallbackHandler) throws WSSecurityException
- Throws:
WSSecurityException
-
getBytesFromAttachment
public static byte[] getBytesFromAttachment(String xopUri, CallbackHandler attachmentCallbackHandler, boolean removeAttachments) throws WSSecurityException
- Throws:
WSSecurityException
-
getAttachmentId
public static String getAttachmentId(String xopUri) throws WSSecurityException
- Throws:
WSSecurityException
-
-