Search in sources :

Example 6 with XmlSignatureException

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);
    }
}
Also used : XmlSignatureException(org.apache.camel.component.xmlsecurity.api.XmlSignatureException) Reference(javax.xml.crypto.dsig.Reference) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transform(javax.xml.crypto.dsig.Transform)

Example 7 with XmlSignatureException

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;
}
Also used : XmlSignatureException(org.apache.camel.component.xmlsecurity.api.XmlSignatureException) SignatureType(org.apache.camel.component.xmlsecurity.api.SignatureType)

Example 8 with XmlSignatureException

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.");
    }
}
Also used : XmlSignatureException(org.apache.camel.component.xmlsecurity.api.XmlSignatureException) Element(org.w3c.dom.Element)

Aggregations

XmlSignatureException (org.apache.camel.component.xmlsecurity.api.XmlSignatureException)8 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 XPathFilterParameterSpec (javax.xml.crypto.dsig.spec.XPathFilterParameterSpec)2 XPathExpression (javax.xml.xpath.XPathExpression)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 SignatureType (org.apache.camel.component.xmlsecurity.api.SignatureType)2 NodeList (org.w3c.dom.NodeList)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 ArrayList (java.util.ArrayList)1 KeySelector (javax.xml.crypto.KeySelector)1 Reference (javax.xml.crypto.dsig.Reference)1 SignedInfo (javax.xml.crypto.dsig.SignedInfo)1 Transform (javax.xml.crypto.dsig.Transform)1