Class DefaultXmlSignature2Message
- java.lang.Object
-
- org.apache.camel.component.xmlsecurity.api.DefaultXmlSignature2Message
-
- All Implemented Interfaces:
XmlSignature2Message
public class DefaultXmlSignature2Message extends Object implements XmlSignature2Message
Maps the XML signature to a camel message. A output node is determined from the XML signature document via a node search and then serialized and set to the output message body.There are three output node search types supported: "Default", "ElementName", and "XPath". All these search types support enveloped XML signature or enveloping XML signature.
- The "ElementName" search uses the local name and namespace specified in the search value to determine the output element from the XML signature document. With the input parameter 'RemoveSignatureElements", you can specify whether the signature elements should be removed from the resulting output document. This flag shall be used for enveloped XML signatures.
- The "XPath" search uses an XPath expression to evaluate the output node. In this case the output node can be of type Element, TextNode, or Document. With the input parameter 'RemoveSignatureElements", you can specify whether the signature elements should be removed from the resulting output document. This flag shall be used for enveloped XML signatures.
- The "Default" search is explained in more detail below.
Default Output Node Search:
-
In the enveloped XML signature case, the XML document without the signature part is returned in the message body.
- Only same document references are taken into account (URI must start with '#').
- Also indirect same document references to an object via manifest are taken into account.
- The resulting number of object references must be 1.
- The referenced object must contain exactly 1
DOMStructure. - The node of the DOMStructure is serialized to a byte array and added as body to the message.
In the enveloping XML signature case, the message body is determined from a referenced Object element in the following way:
or the structure<Signature> <SignedInfo> <Reference URI="#object"/> <!-- further references possible but they must not point to an Object or Manifest containing an object reference --> ... </SignedInfo> <Object Id="object"> <!-- contains the DOM node which should be extracted to the message body --> <Object> <!-- further object elements possible which are not referenced--> ... (<KeyInfo>)? </Signature><Signature> <SignedInfo> <Reference URI="#manifest"/> <!-- further references are possible but they must not point to an Object or other manifest containing an object reference --> ... </SignedInfo> <Object > <Manifest Id="manifest"> <Reference URI=#object/> </Manifest> </Objet> <Object Id="object"> <!-- contains the DOM node which should be extracted to the message body --> </Object> <!-- further object elements possible which are not referenced --> ... (<KeyInfo>)? </Signature>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.camel.component.xmlsecurity.api.XmlSignature2Message
XmlSignature2Message.Input
-
-
Field Summary
Fields Modifier and Type Field Description static StringOUTPUT_NODE_SEARCH_TYPE_DEFAULTSearch type 'Default' for determining the output node.static StringOUTPUT_NODE_SEARCH_TYPE_ELEMENT_NAMESearch type 'ElementName' for determining the output element.static StringOUTPUT_NODE_SEARCH_TYPE_XPATHSearch type 'XPath' for determining the output node.
-
Constructor Summary
Constructors Constructor Description DefaultXmlSignature2Message()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddManifestReferencedObjects(List<XMLObject> allObjects, List<XMLObject> referencedObjects, String manifestId)protected voidcheckSearchValueNotNull(XmlSignature2Message.Input input)protected voidcheckSearchValueOfType(Class<?> cl, XmlSignature2Message.Input input)protected voidcheckStringSarchValueNotEmpty(String searchValue, String outputNodeSearchType)protected DOMStructuregetDomStructureForMessageBody(List<Reference> relevantReferences, List<XMLObject> relevantObjects)Returns the DOM structure which is transformed to a byte array and set to the camel message body.protected NodegetNodeForMessageBodyInEnvelopingCase(XmlSignature2Message.Input input)protected StringgetNonEmptyStringSearchValue(XmlSignature2Message.Input input)protected List<XMLObject>getObjectsForMessageMapping(XmlSignature2Message.Input input)Returns the objects which must be taken into account for the mapping to the camel message.protected NodegetOutputElementViaLocalNameAndNamespace(XmlSignature2Message.Input input)protected NodegetOutputNodeViaXPath(XmlSignature2Message.Input input)protected ManifestgetReferencedManifest(List<XMLObject> objects, String id)protected XMLObjectgetReferencedObject(List<XMLObject> objects, String id)protected List<XMLObject>getReferencedSameDocumentObjects(List<Reference> relevantReferences, List<XMLObject> relevantObjects)protected List<Reference>getReferencesForMessageMapping(XmlSignature2Message.Input input)Returns the references whose referenced objects are taken into account for the message body.protected StringgetSameDocumentReferenceUri(Reference ref)protected booleanisEnveloping(XmlSignature2Message.Input input)Checks whether the XML document has as root element the signature element.voidmapToMessage(XmlSignature2Message.Input input, org.apache.camel.Message output)Maps the references and objects of an XML signature to the camel message.protected BooleanomitXmlDeclaration(org.apache.camel.Message message, XmlSignature2Message.Input input)protected voidremoveSignatureElements(Node node)Removes the Signature elements from the document.protected voidtransformNodeToByteArrayAndSetToOutputMessage(XmlSignature2Message.Input input, org.apache.camel.Message output, Node node)
-
-
-
Field Detail
-
OUTPUT_NODE_SEARCH_TYPE_DEFAULT
public static final String OUTPUT_NODE_SEARCH_TYPE_DEFAULT
Search type 'Default' for determining the output node.- See Also:
- Constant Field Values
-
OUTPUT_NODE_SEARCH_TYPE_ELEMENT_NAME
public static final String OUTPUT_NODE_SEARCH_TYPE_ELEMENT_NAME
Search type 'ElementName' for determining the output element.- See Also:
- Constant Field Values
-
OUTPUT_NODE_SEARCH_TYPE_XPATH
public static final String OUTPUT_NODE_SEARCH_TYPE_XPATH
Search type 'XPath' for determining the output node. Search value must be of typeXPathFilterParameterSpec.- See Also:
- Constant Field Values
-
-
Method Detail
-
mapToMessage
public void mapToMessage(XmlSignature2Message.Input input, org.apache.camel.Message output) throws Exception
Description copied from interface:XmlSignature2MessageMaps the references and objects of an XML signature to the camel message.- Specified by:
mapToMessagein interfaceXmlSignature2Message- Parameters:
input- inputoutput- output message- Throws:
Exception
-
transformNodeToByteArrayAndSetToOutputMessage
protected void transformNodeToByteArrayAndSetToOutputMessage(XmlSignature2Message.Input input, org.apache.camel.Message output, Node node) throws Exception
- Throws:
Exception
-
getOutputNodeViaXPath
protected Node getOutputNodeViaXPath(XmlSignature2Message.Input input) throws Exception
- Throws:
Exception
-
getOutputElementViaLocalNameAndNamespace
protected Node getOutputElementViaLocalNameAndNamespace(XmlSignature2Message.Input input) throws Exception
- Throws:
Exception
-
getNonEmptyStringSearchValue
protected String getNonEmptyStringSearchValue(XmlSignature2Message.Input input) throws Exception
- Throws:
Exception
-
checkSearchValueOfType
protected void checkSearchValueOfType(Class<?> cl, XmlSignature2Message.Input input) throws Exception
- Throws:
Exception
-
checkStringSarchValueNotEmpty
protected void checkStringSarchValueNotEmpty(String searchValue, String outputNodeSearchType) throws Exception
- Throws:
Exception
-
checkSearchValueNotNull
protected void checkSearchValueNotNull(XmlSignature2Message.Input input) throws Exception
- Throws:
Exception
-
getNodeForMessageBodyInEnvelopingCase
protected Node getNodeForMessageBodyInEnvelopingCase(XmlSignature2Message.Input input) throws Exception
- Throws:
Exception
-
removeSignatureElements
protected void removeSignatureElements(Node node)
Removes the Signature elements from the document.
-
isEnveloping
protected boolean isEnveloping(XmlSignature2Message.Input input)
Checks whether the XML document has as root element the signature element.- Parameters:
input- XML signature input- Returns:
trueif the root element of the xml signature document is the signature element; otherwisefalse- Throws:
Exception
-
omitXmlDeclaration
protected Boolean omitXmlDeclaration(org.apache.camel.Message message, XmlSignature2Message.Input input)
-
getReferencesForMessageMapping
protected List<Reference> getReferencesForMessageMapping(XmlSignature2Message.Input input) throws Exception
Returns the references whose referenced objects are taken into account for the message body. This message you can use to filter the relevant references from the references provided by the input parameter.- Parameters:
input- references and objects- Returns:
- relevant references for the mapping to the camel message
- Throws:
Exception- if an error occurs
-
getObjectsForMessageMapping
protected List<XMLObject> getObjectsForMessageMapping(XmlSignature2Message.Input input) throws Exception
Returns the objects which must be taken into account for the mapping to the camel message.- Parameters:
input- references and objects- Returns:
- relevant objects for the mapping to camel message
- Throws:
Exception- if an error occurs
-
getDomStructureForMessageBody
protected DOMStructure getDomStructureForMessageBody(List<Reference> relevantReferences, List<XMLObject> relevantObjects) throws Exception
Returns the DOM structure which is transformed to a byte array and set to the camel message body.- Parameters:
relevantReferences- input from method#getReferencesForMessageMapping(ReferencesAndObjects)relevantObjects- input from method#getObjectsForMessageMapping(ReferencesAndObjects)- Returns:
- dom structure
- Throws:
Exception- if an error occurs
-
getReferencedSameDocumentObjects
protected List<XMLObject> getReferencedSameDocumentObjects(List<Reference> relevantReferences, List<XMLObject> relevantObjects)
-
addManifestReferencedObjects
protected void addManifestReferencedObjects(List<XMLObject> allObjects, List<XMLObject> referencedObjects, String manifestId)
-
-