Examples of XPathFilterParameterSpec


Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

        if (xpath == null) {
            throw new IllegalArgumentException("xpath is null");
        }
        XmlSignatureTransform transformXPath = new XmlSignatureTransform();
        transformXPath.setAlgorithm(Transform.XPATH);
        XPathFilterParameterSpec params = getXpathFilter(xpath, namespaceMap);
        transformXPath.setParameterSpec(params);
        return transformXPath;
    }
View Full Code Here

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

        transformXPath.setParameterSpec(params);
        return transformXPath;
    }

    public static XPathFilterParameterSpec getXpathFilter(String xpath, Map<String, String> namespaceMap) {
        XPathFilterParameterSpec params = namespaceMap == null ? new XPathFilterParameterSpec(xpath) : new XPathFilterParameterSpec(xpath,
                namespaceMap);
        return params;
    }
View Full Code Here

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

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

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec


    protected Node getOutputNodeViaXPath(Input input) throws Exception { //NOPMD
        checkSearchValueNotNull(input);
        checkSearchValueOfType(XPathFilterParameterSpec.class, input);
        XPathFilterParameterSpec xpathFilter = (XPathFilterParameterSpec) input.getOutputNodeSearch();
        XPathExpression expr = XmlSignatureHelper.getXPathExpression(xpathFilter);
        NodeList nodes = (NodeList) expr.evaluate(input.getMessageBodyDocument(), XPathConstants.NODESET);
        if (nodes == null || nodes.getLength() == 0) {
            throw new XmlSignatureException(
                    String.format(
                            "Cannot extract root node for the output document from the XML signature document. No node found for XPATH %s as specified in the output node search.",
                            xpathFilter.getXPath()));
        }
        if (nodes.getLength() > 1) {
            throw new XmlSignatureException(
                    String.format(
                            "Cannot extract root node for the output document from the XML signature document. XPATH %s as specified in the output node search results into more than one child.",
                            xpathFilter.getXPath()));

        }
        Node result = nodes.item(0);
        if (Node.ELEMENT_NODE == result.getNodeType() || Node.TEXT_NODE == result.getNodeType()
                || Node.DOCUMENT_NODE == result.getNodeType()) {
            return result;
        }
        throw new XmlSignatureException(String.format("Cannot extract root node for the output document from the XML signature document. "
                + "XPATH %s as specified in the output node search results into a node which has the wrong type.", xpathFilter.getXPath()));
    }
View Full Code Here

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

        Map<String, Object> headers = new TreeMap<String, Object>();
        headers.put(XmlSignatureConstants.HEADER_SCHEMA_RESOURCE_URI, (Object) "org/apache/camel/component/xmlsecurity/TestComplex.xsd");
        Map<String, String> namespaceMap = new TreeMap<String, String>();
        namespaceMap.put("ns", "http://test");
        namespaceMap.put("ns1", "http://testB");
        XPathFilterParameterSpec xpath1 = XmlSignatureHelper.getXpathFilter(xpath1exp, namespaceMap);
        XPathFilterParameterSpec xpath2 = XmlSignatureHelper.getXpathFilter(xpath2exp, namespaceMap);

        List<XPathFilterParameterSpec> xpaths = new ArrayList<XPathFilterParameterSpec>();
        xpaths.add(xpath1);
        xpaths.add(xpath2);
        headers.put(XmlSignatureConstants.HEADER_XPATHS_TO_ID_ATTRIBUTES, (Object) xpaths);
View Full Code Here

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

    }

    protected Node getOutputNodeViaXPath(Input input) throws Exception { //NOPMD
        checkSearchValueNotNull(input);
        checkSearchValueOfType(XPathFilterParameterSpec.class, input);
        XPathFilterParameterSpec xpathFilter = (XPathFilterParameterSpec) input.getOutputNodeSearch();
        XPathExpression expr = XmlSignatureHelper.getXPathExpression(xpathFilter);
        NodeList nodes = (NodeList) expr.evaluate(input.getMessageBodyDocument(), XPathConstants.NODESET);
        if (nodes == null || nodes.getLength() == 0) {
            throw new XmlSignatureException(
                    String.format(
                            "Cannot extract root node for the output document from the XML signature document. No node found for XPATH %s as specified in the output node search.",
                            xpathFilter.getXPath()));
        }
        if (nodes.getLength() > 1) {
            throw new XmlSignatureException(
                    String.format(
                            "Cannot extract root node for the output document from the XML signature document. XPATH %s as specified in the output node search results into more than one child.",
                            xpathFilter.getXPath()));

        }
        Node result = nodes.item(0);
        if (Node.ELEMENT_NODE == result.getNodeType() || Node.TEXT_NODE == result.getNodeType()
                || Node.DOCUMENT_NODE == result.getNodeType()) {
            return result;
        }
        throw new XmlSignatureException(
                String.format(
                        "Cannot extract root node for the output document from the XML signature document. "
                        + "XPATH %s as specified in the output node search results into a node which has the wrong type.",
                        xpathFilter.getXPath()));
    }
View Full Code Here

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

          String prefix = attr.getPrefix();
          if (prefix != null && prefix.equals("xmlns")) {
              namespaceMap.put(attr.getLocalName(), attr.getValue());
          }
      }
      this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
  } else {
      this.params = new XPathFilterParameterSpec(xPath);
  }
    }
View Full Code Here

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

    public void marshalParams(XMLStructure parent, XMLCryptoContext context)
        throws MarshalException {

  super.marshalParams(parent, context);
  XPathFilterParameterSpec xp =
      (XPathFilterParameterSpec) getParameterSpec();
  Element xpathElem = DOMUtils.createElement
      (ownerDoc, "XPath", XMLSignature.XMLNS,
       DOMUtils.getSignaturePrefix(context));
  xpathElem.appendChild(ownerDoc.createTextNode(xp.getXPath()));

  // add namespace attributes, if necessary
  Iterator i = xp.getNamespaceMap().entrySet().iterator();
  while (i.hasNext()) {
      Map.Entry entry = (Map.Entry) i.next();
      xpathElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:"
    + (String) entry.getKey(), (String) entry.getValue());
  }
View Full Code Here

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

    public void marshalParams(XMLStructure parent, XMLCryptoContext context)
        throws MarshalException {

  super.marshalParams(parent, context);
  XPathFilterParameterSpec xp =
      (XPathFilterParameterSpec) getParameterSpec();
  Element xpathElem = DOMUtils.createElement
      (ownerDoc, "XPath", XMLSignature.XMLNS,
       DOMUtils.getSignaturePrefix(context));
  xpathElem.appendChild(ownerDoc.createTextNode(xp.getXPath()));

  // add namespace attributes, if necessary
  Iterator i = xp.getNamespaceMap().entrySet().iterator();
  while (i.hasNext()) {
      Map.Entry entry = (Map.Entry) i.next();
      xpathElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:"
    + (String) entry.getKey(), (String) entry.getValue());
  }
View Full Code Here

Examples of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec

        if (xpath == null) {
            throw new IllegalArgumentException("xpath is null");
        }
        XmlSignatureTransform transformXPath = new XmlSignatureTransform();
        transformXPath.setAlgorithm(Transform.XPATH);
        XPathFilterParameterSpec params = getXpathFilter(xpath, namespaceMap);
        transformXPath.setParameterSpec(params);
        return transformXPath;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.