use of org.apache.camel.component.xmlsecurity.api.XmlSignatureException in project camel by apache.
the class XmlSignerProcessor method createReference.
protected Reference createReference(XMLSignatureFactory fac, String uri, String type, SignatureType sigType, String id, Message message) throws InvalidAlgorithmParameterException, XmlSignatureException {
try {
List<Transform> transforms = getTransforms(fac, sigType, message);
Reference ref = fac.newReference(uri, fac.newDigestMethod(getDigestAlgorithmUri(), null), transforms, type, id);
return ref;
} catch (NoSuchAlgorithmException e) {
throw new XmlSignatureException("Wrong algorithm specified in the configuration.", e);
}
}
use of org.apache.camel.component.xmlsecurity.api.XmlSignatureException in project camel by apache.
the class XmlSignerProcessor method determineSignatureType.
private SignatureType determineSignatureType(Message message) throws XmlSignatureException {
if (getConfiguration().getParentLocalName() != null && getConfiguration().getParentXpath() != null) {
throw new XmlSignatureException("The configuration of the XML signer component is wrong. The parent local name " + getConfiguration().getParentLocalName() + " and the parent XPath " + getConfiguration().getParentXpath().getXPath() + " are specified. You must not specify both parameters.");
}
boolean isEnveloped = getConfiguration().getParentLocalName() != null || getConfiguration().getParentXpath() != null;
boolean isDetached = getXpathToIdAttributes(message).size() > 0;
if (isEnveloped && isDetached) {
if (getConfiguration().getParentLocalName() != null) {
throw new XmlSignatureException("The configuration of the XML signer component is wrong. The parent local name " + getConfiguration().getParentLocalName() + " for an enveloped signature and the XPATHs to ID attributes for a detached signature are specified. You must not specify both parameters.");
} else {
throw new XmlSignatureException("The configuration of the XML signer component is wrong. The parent XPath " + getConfiguration().getParentXpath().getXPath() + " for an enveloped signature and the XPATHs to ID attributes for a detached signature are specified. You must not specify both parameters.");
}
}
SignatureType result;
if (isEnveloped) {
result = SignatureType.enveloped;
} else if (isDetached) {
if (getSchemaResourceUri(message) == null) {
throw new XmlSignatureException("The configruation of the XML Signature component is wrong: No XML schema specified in the detached case");
}
result = SignatureType.detached;
} else {
result = SignatureType.enveloping;
}
LOG.debug("Signature type: {}", result);
return result;
}
use of org.apache.camel.component.xmlsecurity.api.XmlSignatureException in project camel by apache.
the class XmlSignerProcessor method getParentForDetachedCase.
private Element getParentForDetachedCase(Document doc, Message inMessage, String referenceUri) throws XmlSignatureException {
String elementId = referenceUri;
if (elementId.startsWith("#")) {
elementId = elementId.substring(1);
}
Element el = doc.getElementById(elementId);
if (el == null) {
// should not happen because has been checked before
throw new IllegalStateException("No element found for element ID " + elementId);
}
LOG.debug("Sibling element of the detached XML Signature with reference URI {}: {} {} ", new Object[] { referenceUri, el.getLocalName(), el.getNamespaceURI() });
Element result = getParentElement(el);
if (result != null) {
return result;
} else {
throw new XmlSignatureException("Either the configuration of the XML Signature component is wrong or the incoming document has an invalid structure: The element " + el.getLocalName() + "{" + el.getNamespaceURI() + "} which is referenced by the reference URI " + referenceUri + " has no parent element. The element must have a parent element in the configured detached case.");
}
}
Aggregations