Examples of XPathContainer


Examples of org.apache.xml.security.transforms.params.XPathContainer

        object2.setEncoding("http://www.w3.org/2000/09/xmldsig#base64");
        object2.appendChild(doc.createTextNode("SSBhbSB0aGUgdGV4dC4="));
        sig.appendObject(object2);

        Transforms transforms = new Transforms(doc);
        XPathContainer xpathC = new XPathContainer(doc);

        xpathC.setXPath("self::text()");
        transforms.addTransform(Transforms.TRANSFORM_XPATH, xpathC.getElementPlusReturns());
        sig.addDocument(
            "#object-1", transforms, Constants.ALGO_ID_DIGEST_SHA1, null,
            "http://www.w3.org/2000/09/xmldsig#Object"
        );
View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

      ed.getCipherData().getCipherReference().setTransforms(xencTransforms);
      org.apache.xml.security.transforms.Transforms dsTransforms =
        xencTransforms.getDSTransforms();

      // An XPath transform
      XPathContainer xpc = new XPathContainer(d);
      xpc.setXPath("self::text()[parent::CipherText[@Id=\"CipherTextId\"]]");
      dsTransforms.addTransform(org.apache.xml.security.transforms.Transforms.TRANSFORM_XPATH,
                    xpc.getElementPlusReturns());

      // Add a Base64 Transforms
      dsTransforms.addTransform(
                    org.apache.xml.security.transforms.Transforms.TRANSFORM_BASE64_DECODE);
View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

                         transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         xpathC.setXPath("self::text()");
         transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                 xpathC.getElementPlusReturns());
         sig.addDocument("#object-1", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }
      /*
      {
         Transforms transforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         //J-
         xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpathC.setXPath("\n"
          + " ancestor-or-self::ds:SignedInfo                    " + "\n"
          + "  and                                               " + "\n"
          + " count(ancestor-or-self::ds:Reference |             " + "\n"
          + "      here()/ancestor::ds:Reference[1]) >           " + "\n"
          + " count(ancestor-or-self::ds:Reference)              " + "\n"
          + "  or                                                " + "\n"
          + " count(ancestor-or-self::node() |                   " + "\n"
          + "      id('notaries')) =                             " + "\n"
          + " count(ancestor-or-self::node())                    " + "\n");
         //J+
         transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                 xpathC.getElementPlusReturns());
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }
      */

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_BASE64_DECODE);
         sig.addDocument("#object-2", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      sig.addDocument("#manifest-1", null, Constants.ALGO_ID_DIGEST_SHA1, null,
                      "http://www.w3.org/2000/09/xmldsig#Manifest");
      sig.addDocument("#signature-properties-1", null,
                      Constants.ALGO_ID_DIGEST_SHA1, null,
                      "http://www.w3.org/2000/09/xmldsig#SignatureProperties");

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         sig.addDocument("#xpointer(/)", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#xpointer(/)", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         sig.addDocument("#object-3", null, Constants.ALGO_ID_DIGEST_SHA1,
                         null, "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#object-3", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         sig.addDocument("#xpointer(id('object-3'))", null,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#xpointer(id('object-3'))", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         sig.addDocument("#manifest-reference-1", null,
                         Constants.ALGO_ID_DIGEST_SHA1, "reference-1",
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      {
         sig.addDocument("#reference-1", null,
                         Constants.ALGO_ID_DIGEST_SHA1, "reference-2",
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      {
         sig.addDocument("#reference-2", null,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      /*
       * Add KeyInfo and sign()
       */
      {
         Transforms retrievalTransforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpathC.setXPath("ancestor-or-self::ds:X509Data");
         retrievalTransforms.addTransform(Transforms.TRANSFORM_XPATH,
                                          xpathC.getElement());
         sig.getKeyInfo().add(
            new RetrievalMethod(
               doc, "#object-4", retrievalTransforms,
               "http://www.w3.org/2000/09/xmldsig#X509Data"));

View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

                         transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         xpathC.setXPath("self::text()");
         transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                 xpathC.getElementPlusReturns());
         sig.addDocument("#object-1", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }
      /*
      {
         Transforms transforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         //J-
         xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpathC.setXPath("\n"
          + " ancestor-or-self::ds:SignedInfo                    " + "\n"
          + "  and                                               " + "\n"
          + " count(ancestor-or-self::ds:Reference |             " + "\n"
          + "      here()/ancestor::ds:Reference[1]) >           " + "\n"
          + " count(ancestor-or-self::ds:Reference)              " + "\n"
          + "  or                                                " + "\n"
          + " count(ancestor-or-self::node() |                   " + "\n"
          + "      id('notaries')) =                             " + "\n"
          + " count(ancestor-or-self::node())                    " + "\n");
         //J+
         transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                 xpathC.getElementPlusReturns());
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }
      */

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_BASE64_DECODE);
         sig.addDocument("#object-2", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      sig.addDocument("#manifest-1", null, Constants.ALGO_ID_DIGEST_SHA1, null,
                      "http://www.w3.org/2000/09/xmldsig#Manifest");
      sig.addDocument("#signature-properties-1", null,
                      Constants.ALGO_ID_DIGEST_SHA1, null,
                      "http://www.w3.org/2000/09/xmldsig#SignatureProperties");

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         sig.addDocument("#xpointer(/)", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#xpointer(/)", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         sig.addDocument("#object-3", null, Constants.ALGO_ID_DIGEST_SHA1,
                         null, "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#object-3", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         sig.addDocument("#xpointer(id('object-3'))", null,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#xpointer(id('object-3'))", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         sig.addDocument("#manifest-reference-1", null,
                         Constants.ALGO_ID_DIGEST_SHA1, "reference-1",
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      {
         sig.addDocument("#reference-1", null,
                         Constants.ALGO_ID_DIGEST_SHA1, "reference-2",
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      {
         sig.addDocument("#reference-2", null,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      /*
       * Add KeyInfo and sign()
       */
      {
         Transforms retrievalTransforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpathC.setXPath("ancestor-or-self::ds:X509Data");
         retrievalTransforms.addTransform(Transforms.TRANSFORM_XPATH,
                                          xpathC.getElement());
         sig.getKeyInfo().add(
            new RetrievalMethod(
               doc, "#object-4", retrievalTransforms,
               "http://www.w3.org/2000/09/xmldsig#X509Data"));

View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

         c.setAttributeNS(null, "name", "val");
         ob1.appendChild(c);
         sig.appendObject(ob1);

         Transforms transforms = new Transforms(doc);
         XPathContainer xc = new XPathContainer(doc);
         xc.setXPathNamespaceContext("prof", Constants.SignatureSpecNS);

         //J-
         String xpath = "\n"
          + "count(" + "\n"
          + " ancestor-or-self::prof:Object " + "\n"
          + " | " + "\n"
          + " here()/ancestor::prof:Signature[1]/child::prof:Object[@Id='object-1']" + "\n"
          + ") <= count(" + "\n"
          + " ancestor-or-self::prof:Object" + "\n"
          + ") " + "\n";
         //J+

         xc.setXPath(xpath);
         HelperNodeList nl = new HelperNodeList();
         nl.appendChild(doc.createTextNode("\n"));
         nl.appendChild(xc.getElement());
         nl.appendChild(doc.createTextNode("\n"));

         transforms.addTransform(Transforms.TRANSFORM_XPATH, nl);
         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

         String rootnamespace = contract.getNamespaceURI();
         boolean rootprefixed = (rootnamespace != null)
                                && (rootnamespace.length() > 0);
         String rootlocalname = contract.getNodeName();
         Transforms transforms = new Transforms(doc);
         XPathContainer xpath = new XPathContainer(doc);

         xpath.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpath.setXPath("\n" + xp1 + "\n");
         transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                 xpath.getElementPlusReturns());
         firstSigner.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);

         {

            // not really secure ///////////////////
            firstSigner.getKeyInfo().add(new KeyName(doc, "First signer key"));

            ////////////////////////////////////////////////
            System.out.println("First signer: Start signing");
            firstSigner
               .sign(firstSigner
                  .createSecretKey("First signer key".getBytes()));
            System.out.println("First signer: Finished signing");
         }

         SignedInfo s = firstSigner.getSignedInfo();

         for (int i = 0; i < s.getSignedContentLength(); i++) {
            System.out.println("################ Signed Resource " + i
                               + " ################");
            System.out.println(new String(s.getSignedContentItem(i)));
            System.out.println();
         }
      }

      //////////////////////////////////////////////////////////////////
      // second signer /////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////
      {
         XMLSignature secondSigner = new XMLSignature(doc, BaseURI,
                                        XMLSignature.ALGO_ID_MAC_HMAC_SHA1);

         secondSigner.setId(id2);
         contract.appendChild(secondSigner.getElement());

         Transforms transforms2 = new Transforms(doc);
         XPathContainer xpath2 = new XPathContainer(doc);

         xpath2.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpath2.setXPath("\n" + xp2 + "\n");
         transforms2.addTransform(Transforms.TRANSFORM_XPATH,
                                  xpath2.getElementPlusReturns());
         secondSigner.addDocument("", transforms2,
                                  Constants.ALGO_ID_DIGEST_SHA1);

         {
            secondSigner.getKeyInfo().add(new KeyName(doc,
                                                      "Second signer key"));
            System.out.println("Second signer: Start signing");
            secondSigner
               .sign(secondSigner
                  .createSecretKey("Second signer key".getBytes()));
            System.out.println("Second signer: Finished signing");
         }

         SignedInfo s2 = secondSigner.getSignedInfo();

         for (int i = 0; i < s2.getSignedContentLength(); i++) {
            System.out.println("################ Signed Resource " + i
                               + " ################");
            System.out.println(new String(s2.getSignedContentItem(i)));
            System.out.println();
         }
      }

      //////////////////////////////////////////////////////////////////
      // third signer //////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////
      {
         XMLSignature thirdSigner =
            new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_MAC_HMAC_SHA1);

         thirdSigner.setId(id3);
         contract.appendChild(thirdSigner.getElement());

         Transforms transforms3 = new Transforms(doc);
         XPathContainer xpath3 = new XPathContainer(doc);

         xpath3.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpath3.setXPath("\n" + xp3 + "\n");
         transforms3.addTransform(Transforms.TRANSFORM_XPATH,
                                  xpath3.getElementPlusReturns());
         thirdSigner.addDocument("", transforms3,
                                 Constants.ALGO_ID_DIGEST_SHA1);

         {
            thirdSigner.getKeyInfo().add(new KeyName(doc, "Third signer key"));
            System.out.println("Third signer: Start signing");
            thirdSigner
               .sign(thirdSigner
                  .createSecretKey("Third signer key".getBytes()));
            System.out.println("Third signer: Finished signing");
         }

         SignedInfo s3 = thirdSigner.getSignedInfo();

         for (int i = 0; i < s3.getSignedContentLength(); i++) {
            System.out.println("################ Signed Resource " + i
                               + " ################");
            System.out.println(new String(s3.getSignedContentItem(i)));
            System.out.println();
         }
      }

      //////////////////////////////////////////////////////////////////
      // forth signer //////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////
      {
         XMLSignature forthSigner =
            new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_MAC_HMAC_SHA1);

         forthSigner.setId("sig4");
         contract.appendChild(forthSigner.getElement());

         {

            // first of all, add the basic document without signatures
            Transforms transforms4 = new Transforms(doc);
            XPathContainer xpath4 = new XPathContainer(doc);

            xpath4.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
            xpath4.setXPath("\n" + "not(ancestor-or-self::ds:Signature)"
                            + "\n");
            transforms4.addTransform(Transforms.TRANSFORM_XPATH,
                                     xpath4.getElementPlusReturns());
            forthSigner.addDocument("", transforms4,
                                    Constants.ALGO_ID_DIGEST_SHA1);
         }

         {
View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

                         transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         xpathC.setXPath("self::text()");
         transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                 xpathC.getElementPlusReturns());
         sig.addDocument("#object-1", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }
      /*
      {
         Transforms transforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         //J-
         xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpathC.setXPath("\n"
          + " ancestor-or-self::ds:SignedInfo                    " + "\n"
          + "  and                                               " + "\n"
          + " count(ancestor-or-self::ds:Reference |             " + "\n"
          + "      here()/ancestor::ds:Reference[1]) >           " + "\n"
          + " count(ancestor-or-self::ds:Reference)              " + "\n"
          + "  or                                                " + "\n"
          + " count(ancestor-or-self::node() |                   " + "\n"
          + "      id('notaries')) =                             " + "\n"
          + " count(ancestor-or-self::node())                    " + "\n");
         //J+
         transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                 xpathC.getElementPlusReturns());
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }
      */

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_BASE64_DECODE);
         sig.addDocument("#object-2", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      sig.addDocument("#manifest-1", null, Constants.ALGO_ID_DIGEST_SHA1, null,
                      "http://www.w3.org/2000/09/xmldsig#Manifest");
      sig.addDocument("#signature-properties-1", null,
                      Constants.ALGO_ID_DIGEST_SHA1, null,
                      "http://www.w3.org/2000/09/xmldsig#SignatureProperties");

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         sig.addDocument("#xpointer(/)", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#xpointer(/)", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         sig.addDocument("#object-3", null, Constants.ALGO_ID_DIGEST_SHA1,
                         null, "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#object-3", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         sig.addDocument("#xpointer(id('object-3'))", null,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         Transforms transforms = new Transforms(doc);

         transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
         sig.addDocument("#xpointer(id('object-3'))", transforms,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Object");
      }

      {
         sig.addDocument("#manifest-reference-1", null,
                         Constants.ALGO_ID_DIGEST_SHA1, "reference-1",
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      {
         sig.addDocument("#reference-1", null,
                         Constants.ALGO_ID_DIGEST_SHA1, "reference-2",
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      {
         sig.addDocument("#reference-2", null,
                         Constants.ALGO_ID_DIGEST_SHA1, null,
                         "http://www.w3.org/2000/09/xmldsig#Reference");
      }

      /*
       * Add KeyInfo and sign()
       */
      {
         Transforms retrievalTransforms = new Transforms(doc);
         XPathContainer xpathC = new XPathContainer(doc);

         xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
         xpathC.setXPath("ancestor-or-self::ds:X509Data");
         retrievalTransforms.addTransform(Transforms.TRANSFORM_XPATH,
                                          xpathC.getElement());
         sig.getKeyInfo().add(
            new RetrievalMethod(
               doc, "#object-4", retrievalTransforms,
               "http://www.w3.org/2000/09/xmldsig#X509Data"));

View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

         String rootnamespace = signedResourceElement.getNamespaceURI();
         boolean rootprefixed = (rootnamespace != null)
                                && (rootnamespace.length() > 0);
         String rootlocalname = signedResourceElement.getNodeName();
         Transforms transforms = new Transforms(doc);
         XPathContainer xpath = new XPathContainer(doc);

         xpath.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);

         if (rootprefixed) {
            xpath.setXPathNamespaceContext("root", rootnamespace);
         }

         //J-
         String xpathStr = "\n"
          + "count(                                                                 " + "\n"
          + " ancestor-or-self::" + (rootprefixed ? "root:" : "") + rootlocalname + "" + "\n"
          + " |                                                                     " + "\n"
          + " here()/ancestor::" + (rootprefixed ? "root:" : "") + rootlocalname + "[1] " + "\n"
          + ") <= count(                                                             " + "\n"
          + " ancestor-or-self::" + (rootprefixed ? "root:" : "") + rootlocalname + "" + "\n"
          + ")                                                                      " + "\n"
          + " and                                                                   " + "\n"
          + "count(                                                                 " + "\n"
          + " ancestor-or-self::ds:Signature                                        " + "\n"
          + " |                                                                     " + "\n"
          + " here()/ancestor::ds:Signature[1]                                      " + "\n"
          + ") > count(                                                             " + "\n"
          + " ancestor-or-self::ds:Signature                                        " + "\n"
          + ")                                                                      " + "\n"



          ;
         //J+
         xpath.setXPath(xpathStr);
         transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                 xpath.getElementPlusReturns());
         sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
      }

      {
         sig.getKeyInfo()
View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

        doc.appendChild(xmlSignature.getElement());
        {
            // ref 0
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath(
                "self::Parent or (parent::Parent and not(self::Child)) or self::GrandChild or parent::GrandChild");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            xmlSignature.addDocument("iaikTests.example1.xml", tf);
        }

        {
            // ref 1
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath(
                "self::Parent or (parent::Parent and not(self::Child)) or self::GrandChild or parent::GrandChild");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            tf.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
            xmlSignature.addDocument("iaikTests.example1.xml", tf);
        }

        {
            // ref 2
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPathNamespaceContext("xmlns:default", "http://example.org");
                xc.setXPath(
                "self::Parent or (parent::Parent and not(self::default:Child)) or self::GrandChild or parent::GrandChild");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            xmlSignature.addDocument("iaikTests.example2.xml", tf);
        }

        {
            // ref 3
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPathNamespaceContext("xmlns:default", "http://example.org");
                xc.setXPath(
                "self::Parent or (parent::Parent and not(self::default:Child)) or self::GrandChild or parent::GrandChild");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            tf.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
            xmlSignature.addDocument("iaikTests.example2.xml", tf);
        }

        {
            // ref 4
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPathNamespaceContext("xmlns:default",
                "http://example.org/default");
                xc.setXPathNamespaceContext("xmlns:ns1", "http://example.org/ns1");
                xc.setXPath(
                "self::default:Parent or (parent::default:Parent and not(self::default:Child)) or self::ns1:GrandChild or parent::ns1:GrandChild or self::default:GrandChild or parent::default:GrandChild");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }

            xmlSignature.addDocument("iaikTests.example3.xml", tf);
        }

        {
            // ref 5
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPathNamespaceContext("xmlns:default",
                "http://example.org/default");
                xc.setXPathNamespaceContext("xmlns:ns1", "http://example.org/ns1");
                xc.setXPath(
                "self::default:Parent or (parent::default:Parent and not(self::default:Child)) or self::ns1:GrandChild or parent::ns1:GrandChild or self::default:GrandChild or parent::default:GrandChild");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            tf.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
            xmlSignature.addDocument("iaikTests.example3.xml", tf);
        }

        {
            // ref 6
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPathNamespaceContext("xmlns:ns1", "http://example.org/ns1");
                xc.setXPath(
                "self::Parent or (parent::Parent and not(self::Child)) or self::ns1:GrandChild or parent::ns1:GrandChild");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            xmlSignature.addDocument("iaikTests.example4.xml", tf);
        }

        {
            // ref 7
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPathNamespaceContext("xmlns:ns1", "http://example.org/ns1");
                xc.setXPath(
                "self::Parent or (parent::Parent and not(self::Child)) or self::ns1:GrandChild or parent::ns1:GrandChild");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            {
                InclusiveNamespaces incNS = new InclusiveNamespaces(doc, "ns2");

                tf.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS,
                                incNS.getElement());
            }
            xmlSignature.addDocument("iaikTests.example4.xml", tf);
        }

        {
            // ref 8
            ObjectContainer obj = new ObjectContainer(doc);
            String id = "object1";

            obj.setId(id);

            String xmlStr = "" + "<included    xml:lang='de'>" + "\n"
            + "<notIncluded xml:lang='de'>" + "\n"
            + "<notIncluded xml:lang='uk'>" + "\n"
            + "<included                 >" + "\n" + "</included>"
            + "\n" + "</notIncluded>" + "\n" + "</notIncluded>"
            + "\n" + "</included>";
            Document importDoc =
                db.parse(new ByteArrayInputStream(xmlStr.getBytes()));

            obj.getElement().appendChild(doc.createTextNode("\n"));
            obj.getElement()
            .appendChild(doc.importNode(importDoc.getDocumentElement(), true));
            obj.getElement().appendChild(doc.createTextNode("\n"));
            xmlSignature.appendObject(obj);

            // ref apache_8
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath("self::node()[local-name()='included']");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            xmlSignature.addDocument("#" + id, tf);
        }

        {
            // ref 9
            ObjectContainer obj = new ObjectContainer(doc);
            String id = "object2";

            obj.setId(id);

            String xmlStr = "" + "<included    xml:lang='uk'>" + "\n"
            + "<notIncluded xml:lang='de'>" + "\n"
            + "<notIncluded xml:lang='uk'>" + "\n"
            + "<included                 >" + "\n" + "</included>"
            + "\n" + "</notIncluded>" + "\n" + "</notIncluded>"
            + "\n" + "</included>";
            Document importDoc =
                db.parse(new ByteArrayInputStream(xmlStr.getBytes()));

            obj.getElement().appendChild(doc.createTextNode("\n"));
            obj.getElement()
            .appendChild(doc.importNode(importDoc.getDocumentElement(), true));
            obj.getElement().appendChild(doc.createTextNode("\n"));
            xmlSignature.appendObject(obj);

            // ref apache_8
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath("self::node()[local-name()='included']");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }
            xmlSignature.addDocument("#" + id, tf);
        }

        {
            // ref 10
            ObjectContainer obj = new ObjectContainer(doc);
            String id = "object3";

            obj.setId(id);

            String xmlStr = "" + "<included    xml:lang='de'>" + "\n"
            + "<notIncluded xml:lang='de'>" + "\n"
            + "<notIncluded xml:lang='uk'>" + "\n"
            + "<included    xml:lang='de'>" + "\n" + "</included>"
            + "\n" + "</notIncluded>" + "\n" + "</notIncluded>"
            + "\n" + "</included>";
            Document importDoc =
                db.parse(new ByteArrayInputStream(xmlStr.getBytes()));

            obj.getElement().appendChild(doc.createTextNode("\n"));
            obj.getElement()
            .appendChild(doc.importNode(importDoc.getDocumentElement(), true));
            obj.getElement().appendChild(doc.createTextNode("\n"));
            xmlSignature.appendObject(obj);

            // ref apache_8
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath("self::node()[local-name()='included']");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }

            xmlSignature.addDocument("#" + id, tf);
        }

        {
            // ref 11
            ObjectContainer obj = new ObjectContainer(doc);
            String id = "object4";

            obj.setId(id);

            String xmlStr = "" + "<included    xml:lang='de'>" + "\n"
            + "<included    xml:lang='de'>" + "\n"
            + "<notIncluded xml:lang='uk'>" + "\n"
            + "<included                 >" + "\n" + "</included>"
            + "\n" + "</notIncluded>" + "\n" + "</included>"
            + "\n" + "</included>";
            Document importDoc =
                db.parse(new ByteArrayInputStream(xmlStr.getBytes()));

            obj.getElement().appendChild(doc.createTextNode("\n"));
            obj.getElement()
            .appendChild(doc.importNode(importDoc.getDocumentElement(), true));
            obj.getElement().appendChild(doc.createTextNode("\n"));
            xmlSignature.appendObject(obj);

            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath("self::node()[local-name()='included']");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }

            xmlSignature.addDocument("#" + id, tf);
        }

        {
            // ref 12
            ObjectContainer obj = new ObjectContainer(doc);
            String id = "object5";

            obj.setId(id);

            String xmlStr = "" + "<included                         xml:lang='de'>"
            + "\n"
            + "<included                         xml:lang='de'>"
            + "\n"
            + "<notIncluded xml:space='preserve' xml:lang='uk'>"
            + "\n" + "<included                 >" + "\n"
            + "</included>" + "\n" + "</notIncluded>" + "\n"
            + "</included>" + "\n" + "</included>";
            Document importDoc =
                db.parse(new ByteArrayInputStream(xmlStr.getBytes()));

            obj.getElement().appendChild(doc.createTextNode("\n"));
            obj.getElement()
            .appendChild(doc.importNode(importDoc.getDocumentElement(), true));
            obj.getElement().appendChild(doc.createTextNode("\n"));
            xmlSignature.appendObject(obj);

            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath("self::node()[local-name()='included']");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }

            xmlSignature.addDocument("#" + id, tf);
        }

        {
            // ref 13
            ObjectContainer obj = new ObjectContainer(doc);
            String id = "object6";

            obj.setId(id);

            String xmlStr = "" + "<included   xml:space='preserve'  xml:lang='de'>"
            + "\n"
            + "<included                         xml:lang='de'>"
            + "\n"
            + "<notIncluded                      xml:lang='uk'>"
            + "\n" + "<included>" + "\n" + "</included>" + "\n"
            + "</notIncluded>" + "\n" + "</included>" + "\n"
            + "</included>";
            Document importDoc =
                db.parse(new ByteArrayInputStream(xmlStr.getBytes()));

            obj.getElement().appendChild(doc.createTextNode("\n"));
            obj.getElement()
            .appendChild(doc.importNode(importDoc.getDocumentElement(), true));
            obj.getElement().appendChild(doc.createTextNode("\n"));
            xmlSignature.appendObject(obj);

            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath("self::node()[local-name()='included']");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
            }

            xmlSignature.addDocument("#" + id, tf);
        }

        {
            // ref 13b
            String id = "object6";
            Transforms tf = new Transforms(doc);
            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath("self::node()[local-name()='included']");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
                tf.addTransform(Transforms.TRANSFORM_C14N_OMIT_COMMENTS);
            }
            xmlSignature.addDocument("#" + id, tf);
        }

        {
            // ref 13c
            String id = "object6";
            Transforms tf = new Transforms(doc);

            {
                XPathContainer xc = new XPathContainer(doc);

                xc.setXPath("self::node()[local-name()='included']");
                tf.addTransform(Transforms.TRANSFORM_XPATH, xc.getElement());
                tf.addTransform(Transforms.TRANSFORM_C14N_OMIT_COMMENTS);
                tf.addTransform(Transforms.TRANSFORM_C14N_OMIT_COMMENTS);
            }
            xmlSignature.addDocument("#" + id, tf);
            // xmlSignature.addDocument("#" + id, tf, org.apache.xml.security.algorithms.MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1, "ref13c", null);
View Full Code Here

Examples of org.apache.xml.security.transforms.params.XPathContainer

        object2.setEncoding("http://www.w3.org/2000/09/xmldsig#base64");
        object2.appendChild(doc.createTextNode("SSBhbSB0aGUgdGV4dC4="));
        sig.appendObject(object2);

        Transforms transforms = new Transforms(doc);
        XPathContainer xpathC = new XPathContainer(doc);

        xpathC.setXPath("self::text()");
        transforms.addTransform(Transforms.TRANSFORM_XPATH, xpathC.getElementPlusReturns());
        sig.addDocument(
            "#object-1", transforms, Constants.ALGO_ID_DIGEST_SHA1, null,
            "http://www.w3.org/2000/09/xmldsig#Object"
        );
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.