Package org.apache.camel.component.xmlsecurity.api

Examples of org.apache.camel.component.xmlsecurity.api.XmlSignatureException


        } catch (XMLSignatureException se) {
            if (se.getCause() instanceof InvalidKeyException) {
                throw new XmlSignatureInvalidKeyException(se.getMessage(), se);
            } else {
                throw new XmlSignatureException(se);
            }
        } catch (GeneralSecurityException e) {
            // like NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException
            throw new XmlSignatureException(e);
        }

    }
View Full Code Here


    }

    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;
View Full Code Here

            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(
View Full Code Here

                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.");
        }
    }
View Full Code Here

        IOHelper.copyAndCloseInput(is, bos);
        try {
            String text = new String(bos.toByteArray(), encoding);
            return XmlSignatureHelper.newDocumentBuilder(true).newDocument().createTextNode(text);
        } catch (UnsupportedEncodingException e) {
            throw new XmlSignatureException(String.format("The message encoding %s is not supported.", encoding), e);
        }
    }
View Full Code Here

        try {
            List<Transform> transforms = getTransforms(fac, sigType);
            Reference ref = fac.newReference(uri, fac.newDigestMethod(getDigestAlgorithmUri(), null), transforms, type, null);
            return ref;
        } catch (NoSuchAlgorithmException e) {
            throw new XmlSignatureException("Wrong algorithm specified in the configuration.", e);
        }
    }
View Full Code Here

        for (XPathFilterParameterSpec xp : xpathsToIdAttributes) {
            XPathExpression exp;
            try {
                exp = XmlSignatureHelper.getXPathExpression(xp);
            } catch (XPathExpressionException e) {
                throw new XmlSignatureException("The configured xpath expression " + xp.getXPath() + " is invalid.", e);
            }
            NodeList list = (NodeList) exp.evaluate(messageBodyNode, XPathConstants.NODESET);
            if (list == null) {
                //assume optional element, XSD validation has been done before
                LOG.warn("No ID attribute found for xpath expression {}. Therfore this xpath expression will be ignored.", xp.getXPath());
                continue;
            }
            int length = list.getLength();
            for (int i = 0; i < length; i++) {
                Node node = list.item(i);
                if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
                    Attr attr = (Attr) node;
                    String value = attr.getValue();
                    // check that attribute is ID attribute
                    Element element = messageBodyNode.getOwnerDocument().getElementById(value);
                    if (element == null) {
                        throw new XmlSignatureException(
                                "Wrong configured xpath expression for ID attributes: The evaluation of the xpath expression "
                                        + xp.getXPath() + " resulted in an attribute which is not of type ID. The attribute value is "
                                        + value + ".");
                    }
                    result.add(new ComparableNode(element, "#" + value));
                    LOG.debug("ID attribute with value {} found for xpath {}", value, xp.getXPath());
                } else {
                    throw new XmlSignatureException(
                            "Wrong configured xpath expression for ID attributes: The evaluation of the xpath expression " + xp.getXPath()
                                    + " returned a node which was not of type Attribute.");
                }
            }
        }
        if (result.size() == 0) {
            throw new XmlSignatureException(
                    "No element to sign found in the detached case. No node found for the configured xpath expressions "
                            + toString(xpathsToIdAttributes)
                            + ". Either the configuration of the XML signature component is wrong or the incoming message has not the correct structure.");
        }
        // sort so that elements with deeper hierarchy level are treated first
View Full Code Here

        }
        if (result != null) {
            LOG.debug("Digest algorithm: {}", result);
            return result;
        }
        throw new XmlSignatureException(
                "Digest algorithm missing for XML signature generation. Specify the digest algorithm in the configuration.");
    }
View Full Code Here

        } catch (XMLSignatureException se) {
            if (se.getCause() instanceof InvalidKeyException) {
                throw new XmlSignatureInvalidKeyException(se.getMessage(), se);
            } else {
                throw new XmlSignatureException(se);
            }
        } catch (GeneralSecurityException e) {
            // like NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException
            throw new XmlSignatureException(e);
        }

    }
View Full Code Here

        IOHelper.copyAndCloseInput(is, bos);
        try {
            String text = new String(bos.toByteArray(), encoding);
            return XmlSignatureHelper.newDocumentBuilder(true).newDocument().createTextNode(text);
        } catch (UnsupportedEncodingException e) {
            throw new XmlSignatureException(String.format("The message encoding %s is not supported.", encoding), e);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.xmlsecurity.api.XmlSignatureException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.