org.apache.camel.component.xmlsecurity.processor
Class XmlSignerProcessor

java.lang.Object
  extended by org.apache.camel.component.xmlsecurity.processor.XmlSignatureProcessor
      extended by org.apache.camel.component.xmlsecurity.processor.XmlSignerProcessor
All Implemented Interfaces:
org.apache.camel.Processor

public class XmlSignerProcessor
extends XmlSignatureProcessor

Creates from the message body a XML signature element which is returned in the message body of the output message. Enveloped and enveloping XML signatures are supported.

In the enveloped XML signature case, the method XmlSignerConfiguration.getParentLocalName() must not return null. In this case the parent element must be contained in the XML document provided by the message body and the signature element is added as last child element of the parent element. If a KeyInfo instance is provided by the KeyAccessor and XmlSignerConfiguration.getAddKeyInfoReference() is true, then also a reference to the KeyInfo element is added. The generated XML signature has the following structure:

 <[parent element]>
     ...
      <Signature Id="[signature_id]">
          <SignedInfo>
                <Reference URI=""> 
                      <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                      (<Transform>)*
                      <DigestMethod>
                      <DigestValue>
                </Reference>
                (<Reference URI="#[keyinfo_Id]">
                      <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
                      <DigestMethod>
                      <DigestValue>
                </Reference>)?
                <!-- further references possible, see XmlSignerConfiguration#setProperties(XmlSignatureProperties) -->
         </SignedInfo>
         <SignatureValue>
         (<KeyInfo Id="[keyinfo_id]">)?
         <!-- Object elements possible, see XmlSignerConfiguration#setProperties(XmlSignatureProperties) -->
     </Signature>
 </[parent element]>
 
 

In the enveloping XML signature case, the generated XML signature has the following structure:

  <Signature Id="[signature_id]">
     <SignedInfo>
            <Reference URI="#[object_id]" type="[optional_type_value]"> 
                  (<Transform>)*
                  <DigestMethod>
                  <DigestValue>
            </Reference>
            (<Reference URI="#[keyinfo_id]">
                  <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
                  <DigestMethod>
                  <DigestValue>
            </Reference>)?
             <!-- further references possible, see XmlSignerConfiguration#setProperties(XmlSignatureProperties) -->
     </SignedInfo>
     <SignatureValue>
     (<KeyInfo Id="[keyinfo_id]">)?
     <Object Id="[object_id]"/>
     <!-- further Object elements possible, see XmlSignerConfiguration#setProperties(XmlSignatureProperties) -->
 </Signature>   
  
 
In the enveloping XML signature case, also message bodies containing plain text are supported. This must be indicated via the header XmlSignatureConstants.HEADER_MESSAGE_IS_PLAIN_TEXT or via the configuration XmlSignerConfiguration.getPlainText().

In both cases, the digest algorithm is either read from the configuration method XmlSignerConfiguration.getDigestAlgorithm() or calculated from the signature algorithm ( XmlSignerConfiguration.getSignatureAlgorithm(). The optional transforms are read from XmlSignerConfiguration.getTransformMethods() .

In both cases, you can add additional references and objects which contain properties for the XML signature, see XmlSignerConfiguration.setProperties(XmlSignatureProperties).


Constructor Summary
XmlSignerProcessor(XmlSignerConfiguration config)
           
 
Method Summary
protected  Reference createKeyInfoReference(XMLSignatureFactory fac, String keyInfoId, String digestAlgorithm)
           
protected  Reference createReference(XMLSignatureFactory fac, String uri, String type)
           
protected  SignedInfo createSignedInfo(XMLSignatureFactory fac, List<? extends Reference> refs)
           
protected  XMLObject createXMLObject(XMLSignatureFactory fac, Node node, String id)
           
 XmlSignerConfiguration getConfiguration()
           
protected  String getContentReferenceType(org.apache.camel.Message message)
           
protected  String getContentReferenceUri(org.apache.camel.Message message)
           
protected  String getDigestAlgorithmUri()
           
protected  Node getMessageBodyNode(org.apache.camel.Message message)
           
protected  String getMessageEncoding(org.apache.camel.Message inMessage)
           
protected  List<? extends XMLObject> getObjects(XmlSignatureProperties.Input input, XmlSignatureProperties.Output properties)
           
protected  Element getParentOfSignature(org.apache.camel.Message inMessage, Node messageBodyNode)
           
protected  List<? extends Reference> getReferences(XmlSignatureProperties.Input input, XmlSignatureProperties.Output properties, String keyInfoId)
           
protected  XmlSignatureProperties.Output getSignatureProperties(XmlSignatureProperties.Input input)
           
protected  boolean isEnveloped()
           
protected  Boolean isPlainText(org.apache.camel.Message message)
           
protected  Boolean omitXmlDeclaration(org.apache.camel.Message message)
           
protected  Document parseInput(InputStream is, Boolean disallowDoctypeDecl)
           
 void process(org.apache.camel.Exchange exchange)
           
protected  Document sign(org.apache.camel.Message out)
           
 
Methods inherited from class org.apache.camel.component.xmlsecurity.processor.XmlSignatureProcessor
clearMessageHeaders, setCryptoContextProperties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlSignerProcessor

public XmlSignerProcessor(XmlSignerConfiguration config)
Method Detail

getConfiguration

public XmlSignerConfiguration getConfiguration()
Specified by:
getConfiguration in class XmlSignatureProcessor

process

public void process(org.apache.camel.Exchange exchange)
             throws Exception
Throws:
Exception

sign

protected Document sign(org.apache.camel.Message out)
                 throws Exception
Throws:
Exception

getSignatureProperties

protected XmlSignatureProperties.Output getSignatureProperties(XmlSignatureProperties.Input input)
                                                        throws Exception
Throws:
Exception

omitXmlDeclaration

protected Boolean omitXmlDeclaration(org.apache.camel.Message message)

createSignedInfo

protected SignedInfo createSignedInfo(XMLSignatureFactory fac,
                                      List<? extends Reference> refs)
                               throws Exception
Throws:
Exception

getMessageBodyNode

protected Node getMessageBodyNode(org.apache.camel.Message message)
                           throws Exception
Throws:
Exception

isPlainText

protected Boolean isPlainText(org.apache.camel.Message message)

getParentOfSignature

protected Element getParentOfSignature(org.apache.camel.Message inMessage,
                                       Node messageBodyNode)
                                throws Exception
Throws:
Exception

getReferences

protected List<? extends Reference> getReferences(XmlSignatureProperties.Input input,
                                                  XmlSignatureProperties.Output properties,
                                                  String keyInfoId)
                                           throws Exception
Throws:
Exception

getObjects

protected List<? extends XMLObject> getObjects(XmlSignatureProperties.Input input,
                                               XmlSignatureProperties.Output properties)
                                        throws Exception
Throws:
Exception

getMessageEncoding

protected String getMessageEncoding(org.apache.camel.Message inMessage)

parseInput

protected Document parseInput(InputStream is,
                              Boolean disallowDoctypeDecl)
                       throws XmlSignatureFormatException,
                              ParserConfigurationException,
                              IOException
Throws:
XmlSignatureFormatException
ParserConfigurationException
IOException

createReference

protected Reference createReference(XMLSignatureFactory fac,
                                    String uri,
                                    String type)
                             throws InvalidAlgorithmParameterException,
                                    XmlSignatureException
Throws:
InvalidAlgorithmParameterException
XmlSignatureException

getContentReferenceType

protected String getContentReferenceType(org.apache.camel.Message message)

getContentReferenceUri

protected String getContentReferenceUri(org.apache.camel.Message message)

createXMLObject

protected XMLObject createXMLObject(XMLSignatureFactory fac,
                                    Node node,
                                    String id)

isEnveloped

protected boolean isEnveloped()

getDigestAlgorithmUri

protected String getDigestAlgorithmUri()
                                throws XmlSignatureException
Throws:
XmlSignatureException

createKeyInfoReference

protected Reference createKeyInfoReference(XMLSignatureFactory fac,
                                           String keyInfoId,
                                           String digestAlgorithm)
                                    throws Exception
Throws:
Exception


Apache Camel