Class XmlSignatureHelper
- java.lang.Object
-
- org.apache.camel.component.xmlsecurity.api.XmlSignatureHelper
-
public final class XmlSignatureHelper extends Object
Helps to construct the transformations and the canonicalization methods for the XML Signature generator.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XmlSignatureHelper.XPathAndFilter
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static AlgorithmMethod
getBase64Transform()
Returns a configuration for a base64 transformation.static AlgorithmMethod
getCanonicalizationMethod(String algorithm)
Returns a configuration for a canonicalization algorithm.static AlgorithmMethod
getCanonicalizationMethod(String algorithm, List<String> inclusiveNamespacePrefixes)
Returns a configuration for a canonicalization algorithm.static Document
getDocument(Node node)
static AlgorithmMethod
getEnvelopedTransform()
static List<Node>
getTextAndElementChildren(Node node)
static List<AlgorithmMethod>
getTransforms(List<AlgorithmMethod> list)
static AlgorithmMethod
getXPath2Transform(String xpath, String filter)
Returns a configuration for an XPATH2 transformation.static AlgorithmMethod
getXPath2Transform(String xpath, String filter, Map<String,String> namespaceMap)
Returns a configuration for an XPATH2 transformation which consists of several XPATH expressions.static AlgorithmMethod
getXPath2Transform(List<XmlSignatureHelper.XPathAndFilter> xpathAndFilterList)
Returns a configuration for an XPATH2 transformation which consists of several XPATH expressions.static AlgorithmMethod
getXPath2Transform(List<XmlSignatureHelper.XPathAndFilter> xpathAndFilterList, Map<String,String> namespaceMap)
Returns a configuration for an XPATH2 transformation which consists of several XPATH expressions.static XPathExpression
getXPathExpression(XPathFilterParameterSpec xpathFilter)
static XPathFilterParameterSpec
getXpathFilter(String xpath)
static XPathFilterParameterSpec
getXpathFilter(String xpath, Map<String,String> namespaceMap)
static AlgorithmMethod
getXPathTransform(String xpath)
Returns a configuration for an XPATH transformation.static AlgorithmMethod
getXPathTransform(String xpath, Map<String,String> namespaceMap)
Returns a configuration for an XPATH transformation which needs a namespace map.static AlgorithmMethod
getXslTranform(InputStream is)
Returns a configuration for an XSL transformation.static AlgorithmMethod
getXslTransform(String path)
Returns a configuration for an XSL transformation.static DocumentBuilder
newDocumentBuilder(Boolean disallowDoctypeDecl)
static DocumentBuilder
newDocumentBuilder(Boolean disallowDoctypeDecl, Schema schema)
protected static InputStream
readXslTransform(String path)
static byte[]
tranformTextNodeToByteArray(Node node)
Deprecated.static byte[]
tranformTextNodeToByteArray(Node node, String encoding)
Trannsforms a text node to byte array using a certain character encoding.static void
transformNonTextNodeToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration)
Deprecated.static void
transformNonTextNodeToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration, String encoding)
Serializes a node using a certain character encoding.static void
transformToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration)
Deprecated.static void
transformToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration, String encoding)
-
-
-
Method Detail
-
getCanonicalizationMethod
public static AlgorithmMethod getCanonicalizationMethod(String algorithm)
Returns a configuration for a canonicalization algorithm.- Parameters:
algorithm
- algorithm URI- Returns:
- canonicalization
- Throws:
IllegalArgumentException
- if algorithm isnull
-
getCanonicalizationMethod
public static AlgorithmMethod getCanonicalizationMethod(String algorithm, List<String> inclusiveNamespacePrefixes)
Returns a configuration for a canonicalization algorithm.- Parameters:
algorithm
- algorithm URIinclusiveNamespacePrefixes
- namespace prefixes which should be treated like in the inclusive canonicalization, only relevant if the algorithm is exclusive- Returns:
- canonicalization
- Throws:
IllegalArgumentException
- if algorithm isnull
-
getEnvelopedTransform
public static AlgorithmMethod getEnvelopedTransform()
-
getBase64Transform
public static AlgorithmMethod getBase64Transform()
Returns a configuration for a base64 transformation.- Returns:
- Base64 transformation
-
getXPathTransform
public static AlgorithmMethod getXPathTransform(String xpath)
Returns a configuration for an XPATH transformation.- Parameters:
xpath
- XPATH expression- Returns:
- XPATH transformation
- Throws:
IllegalArgumentException
- if xpath isnull
-
getXPathTransform
public static AlgorithmMethod getXPathTransform(String xpath, Map<String,String> namespaceMap)
Returns a configuration for an XPATH transformation which needs a namespace map.- Parameters:
xpath
- XPATH expressionnamespaceMap
- namespace map, key is the prefix, value is the namespace, can benull
- Returns:
- XPATH transformation
- Throws:
IllegalArgumentException
- if xpath isnull
-
getXpathFilter
public static XPathFilterParameterSpec getXpathFilter(String xpath, Map<String,String> namespaceMap)
-
getXpathFilter
public static XPathFilterParameterSpec getXpathFilter(String xpath)
-
getXPathExpression
public static XPathExpression getXPathExpression(XPathFilterParameterSpec xpathFilter) throws XPathExpressionException
- Throws:
XPathExpressionException
-
getXPath2Transform
public static AlgorithmMethod getXPath2Transform(String xpath, String filter)
Returns a configuration for an XPATH2 transformation.- Parameters:
xpath
- XPATH expressionfilter
- possible values are "intersect", "subtract", "union"- Returns:
- XPATH transformation
- Throws:
IllegalArgumentException
- if xpath or filter isnull
, or is neither "intersect", nor "subtract", nor "union"
-
getXPath2Transform
public static AlgorithmMethod getXPath2Transform(String xpath, String filter, Map<String,String> namespaceMap)
Returns a configuration for an XPATH2 transformation which consists of several XPATH expressions.- Parameters:
namespaceMap
- namespace map, key is the prefix, value is the namespace, can benull
- Returns:
- XPATH transformation
- Throws:
IllegalArgumentException
- if xpathAndFilterList isnull
or empty, or the specified filter values are neither "intersect", nor "subtract", nor "union"
-
getXPath2Transform
public static AlgorithmMethod getXPath2Transform(List<XmlSignatureHelper.XPathAndFilter> xpathAndFilterList, Map<String,String> namespaceMap)
Returns a configuration for an XPATH2 transformation which consists of several XPATH expressions.- Parameters:
xpathAndFilterList
- list of XPATH expressions with their filtersnamespaceMap
- namespace map, key is the prefix, value is the namespace, can benull
- Returns:
- XPATH transformation
- Throws:
IllegalArgumentException
- if xpathAndFilterList isnull
or empty, or the specified filter values are neither "intersect", nor "subtract", nor "union"
-
getXPath2Transform
public static AlgorithmMethod getXPath2Transform(List<XmlSignatureHelper.XPathAndFilter> xpathAndFilterList)
Returns a configuration for an XPATH2 transformation which consists of several XPATH expressions.- Parameters:
xpathAndFilterList
- list of XPATH expressions with their filters- Returns:
- XPATH transformation
- Throws:
IllegalArgumentException
- if xpathAndFilterList isnull
or empty, or the specified filte values are neither "intersect", nor "subtract", nor "union"
-
getXslTransform
public static AlgorithmMethod getXslTransform(String path) throws Exception
Returns a configuration for an XSL transformation.- Parameters:
path
- path to the XSL file in the classpath- Returns:
- XSL transform
- Throws:
IllegalArgumentException
- if path isnull
IllegalStateException
- if the XSL file cannot be foundException
- if an error during the reading of the XSL file occurs
-
getXslTranform
public static AlgorithmMethod getXslTranform(InputStream is) throws SAXException, IOException, ParserConfigurationException
Returns a configuration for an XSL transformation.- Parameters:
is
- input stream of the XSL- Returns:
- XSL transform
- Throws:
IllegalArgumentException
- if is isnull
Exception
- if an error during the reading of the XSL file occursSAXException
IOException
ParserConfigurationException
-
readXslTransform
protected static InputStream readXslTransform(String path) throws Exception
- Throws:
Exception
-
getTransforms
public static List<AlgorithmMethod> getTransforms(List<AlgorithmMethod> list)
-
newDocumentBuilder
public static DocumentBuilder newDocumentBuilder(Boolean disallowDoctypeDecl) throws ParserConfigurationException
- Throws:
ParserConfigurationException
-
newDocumentBuilder
public static DocumentBuilder newDocumentBuilder(Boolean disallowDoctypeDecl, Schema schema) throws ParserConfigurationException
- Throws:
ParserConfigurationException
-
transformToOutputStream
public static void transformToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration, String encoding) throws Exception
- Throws:
Exception
-
transformToOutputStream
@Deprecated public static void transformToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration) throws Exception
Deprecated.- Throws:
Exception
-
transformNonTextNodeToOutputStream
@Deprecated public static void transformNonTextNodeToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration) throws Exception
Deprecated.- Throws:
Exception
-
transformNonTextNodeToOutputStream
public static void transformNonTextNodeToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration, String encoding) throws Exception
Serializes a node using a certain character encoding.- Parameters:
node
- DOM node to serializeos
- output stream, to which the node is serializedomitXmlDeclaration
- indicator whether to omit the XML declaration or notencoding
- character encoding, can benull
, ifnull
then "UTF-8" is used- Throws:
Exception
-
tranformTextNodeToByteArray
@Deprecated public static byte[] tranformTextNodeToByteArray(Node node)
Deprecated.usetranformTextNodeToByteArray(Node, String)
instead.
-
tranformTextNodeToByteArray
public static byte[] tranformTextNodeToByteArray(Node node, String encoding)
Trannsforms a text node to byte array using a certain character encoding.- Parameters:
node
- text nodeencoding
- character encoding, can benull
, ifnull
then UTF-8 is used- Returns:
- byte array,
null
if the node has not text content - Throws:
IllegalStateException
- if the encoding is not supported
-
-