use of org.apache.camel.component.xmlsecurity.api.XmlSignatureFormatException in project camel by apache.
the class XmlVerifierProcessor method parseInput.
protected Document parseInput(InputStream is, Message message) throws Exception {
//NOPMD
try {
ValidatorErrorHandler errorHandler = new DefaultValidationErrorHandler();
Schema schema = getSchema(message);
DocumentBuilder db = XmlSignatureHelper.newDocumentBuilder(getConfiguration().getDisallowDoctypeDecl(), schema);
db.setErrorHandler(errorHandler);
Document doc = db.parse(is);
// throws ValidationException
errorHandler.handleErrors(message.getExchange(), schema, null);
return doc;
} catch (SAXException e) {
throw new XmlSignatureFormatException("Message has wrong format, it is not a XML signature document. Check the sent message.", e);
}
}
use of org.apache.camel.component.xmlsecurity.api.XmlSignatureFormatException in project camel by apache.
the class XmlVerifierProcessor method getSignatureNodes.
private NodeList getSignatureNodes(Document doc) throws IOException, ParserConfigurationException, XmlSignatureFormatException {
// Find Signature element
NodeList nl = doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
if (nl.getLength() == 0) {
throw new XmlSignatureFormatException("Message is not a correct XML signature document: 'Signature' element is missing. Check the sent message.");
}
LOG.debug("{} signature elements found", nl.getLength());
return nl;
}
use of org.apache.camel.component.xmlsecurity.api.XmlSignatureFormatException in project camel by apache.
the class XmlSignerProcessor method getParentForEnvelopedCase.
protected Element getParentForEnvelopedCase(Document doc, Message inMessage) throws Exception {
//NOPMD
if (getConfiguration().getParentXpath() != null) {
XPathFilterParameterSpec xp = getConfiguration().getParentXpath();
XPathExpression exp;
try {
exp = XmlSignatureHelper.getXPathExpression(xp);
} catch (XPathExpressionException e) {
throw new XmlSignatureException("The parent XPath " + getConfiguration().getParentXpath().getXPath() + " is wrongly configured: The XPath " + xp.getXPath() + " is invalid.", e);
}
NodeList list = (NodeList) exp.evaluate(doc.getDocumentElement(), XPathConstants.NODESET);
if (list == null || list.getLength() == 0) {
throw new XmlSignatureException("The parent XPath " + xp.getXPath() + " returned no result. Check the configuration of the XML signer component.");
}
int length = list.getLength();
for (int i = 0; i < length; i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
// return the first element
return (Element) node;
}
}
throw new XmlSignatureException("The parent XPath " + xp.getXPath() + " returned no element. Check the configuration of the XML signer component.");
} else {
// parent local name is not null!
NodeList parents = doc.getElementsByTagNameNS(getConfiguration().getParentNamespace(), getConfiguration().getParentLocalName());
if (parents == null || parents.getLength() == 0) {
throw new XmlSignatureFormatException(String.format("Incoming message has wrong format: The parent element with the local name %s and the namespace %s was not found in the message to build an enveloped XML signature.", getConfiguration().getParentLocalName(), getConfiguration().getParentNamespace()));
}
// return the first element
return (Element) parents.item(0);
}
}
use of org.apache.camel.component.xmlsecurity.api.XmlSignatureFormatException in project camel by apache.
the class XmlSignerProcessor method parseInput.
protected Document parseInput(InputStream is, Boolean disallowDoctypeDecl, Schema schema, ErrorHandler errorHandler) throws ParserConfigurationException, IOException, XmlSignatureFormatException {
try {
DocumentBuilder db = XmlSignatureHelper.newDocumentBuilder(disallowDoctypeDecl, schema);
db.setErrorHandler(errorHandler);
return db.parse(is);
} catch (SAXException e) {
throw new XmlSignatureFormatException("XML signature generation not possible. Sent message is not an XML document. Check the sent message.", e);
} finally {
IOHelper.close(is, "input stream");
}
}
Aggregations