Examples of Transforms


Examples of org.apache.xml.security.transforms.Transforms

    XMLSignature sig = new XMLSignature(
      domdoc,
      (baseUri != null) ? baseUri.toString() : "",
      XMLSignature.ALGO_ID_SIGNATURE_DSA);
    dom.appendChild(sig.getElement());
    Transforms transforms = new Transforms(domdoc);
    transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
    transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
    sig.addDocument("", transforms, org.apache.xml.security.utils.Constants.ALGO_ID_DIGEST_SHA1);
    String[] refs = options.getReferences();
    for (String ref : refs) sig.addDocument(ref);
    sig.addKeyInfo(cert);
    sig.addKeyInfo(cert.getPublicKey());
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

        } else {
            throwFault("Signature Reference ID is invalid", null);
        }
       
       
        Transforms transforms = null;
        try {
            transforms = ref.getTransforms();
        } catch (XMLSecurityException ex) {
            throwFault("Signature transforms can not be obtained", ex);
        }
       
        boolean c14TransformConfirmed = false;
        String c14TransformExpected = sigProps != null ? sigProps.getSignatureC14Transform() : null;
        boolean envelopedConfirmed = false;
        for (int i = 0; i < transforms.getLength(); i++) {
            try {
                Transform tr = transforms.item(i);
                if (Transforms.TRANSFORM_ENVELOPED_SIGNATURE.equals(tr.getURI())) {
                    envelopedConfirmed = true;
                } else if (c14TransformExpected != null && c14TransformExpected.equals(tr.getURI())) {
                    c14TransformConfirmed = true;
                }
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

    private void signAssertion(Document doc, Element assertionElement) throws Exception {
        XMLSignature sig =
            new XMLSignature(doc, null, XMLSignature.ALGO_ID_SIGNATURE_RSA);
        assertionElement.appendChild(sig.getElement());

        Transforms transforms = new Transforms(doc);
        String filter = "here()/ancestor::ds.Signature/parent::node()/descendant-or-self::*";
        XPath2FilterContainer xpathC = XPath2FilterContainer.newInstanceIntersect(doc, filter);
        xpathC.setXPathNamespaceContext("dsig-xpath", Transforms.TRANSFORM_XPATH2FILTER);
       
        Element node = xpathC.getElement();
        transforms.addTransform(Transforms.TRANSFORM_XPATH2FILTER, node);
        sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);

        PrivateKey privateKey = crypto.getPrivateKey("16c73ab6-b892-458f-abf5-2f875f74882e", "security");

        sig.sign(privateKey);
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

            try {
                for (int part = 0; part < references.size(); part++) {
                    final WSEncryptionPart encPart = (WSEncryptionPart) references.get(part);

                    final String elemName = encPart.getName();
                    final Transforms transforms = new Transforms(document);

                    if (elemName != null && "ExternalSTRTransform".equals(encPart.getNamespace())) {
                        final Element ctx = this.createSTRParameter(document);
                        transforms.addTransform(STRTransform.implementedTransformURI, ctx);
                        this.sig.addDocument("#" + elemName, transforms, this.getDigestAlgo());
                    } else {
                        unalteredReferences.add(encPart);
                    }
                }
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

      super(element, BaseURI);
      this._baseURI=BaseURI;
      Element el=XMLUtils.getNextElement(element.getFirstChild());
      if (Constants._TAG_TRANSFORMS.equals(el.getLocalName()) &&
          Constants.SignatureSpecNS.equals(el.getNamespaceURI())) {
        transforms = new Transforms(el,this._baseURI);
        el=XMLUtils.getNextElement(el.getNextSibling());
      }
      digestMethodElem = el;
      digestValueElement =XMLUtils.getNextElement(digestMethodElem.getNextSibling());;
      this._manifest = manifest;
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

   private XMLSignatureInput getContentsAfterTransformation(XMLSignatureInput input, OutputStream os)
           throws XMLSignatureException {

      try {
         Transforms transforms = this.getTransforms();
         XMLSignatureInput output = null;

         if (transforms != null) {
            output = transforms.performTransforms(input,os);
            this._transformsOutput = output;//new XMLSignatureInput(output.getBytes());

            //this._transformsOutput.setSourceURI(output.getSourceURI());
         } else {
            output = input;
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

           throws XMLSignatureException {

      try {
         XMLSignatureInput input = this.getContentsBeforeTransformation();
         XMLSignatureInput output = input;
         Transforms transforms = this.getTransforms();

         if (transforms != null) {
            doTransforms: for (int i = 0; i < transforms.getLength(); i++) {
               Transform t = transforms.item(i);
               String URI = t.getURI();

               if (URI.equals(Transforms
                       .TRANSFORM_C14N_EXCL_OMIT_COMMENTS) || URI
                          .equals(Transforms
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

      try {
         XMLSignatureInput nodes = this.getNodesetBeforeFirstCanonicalization();
         Set inclusiveNamespaces = new HashSet();

         {
            Transforms transforms = this.getTransforms();
            Transform c14nTransform = null;

            if (transforms != null) {
               doTransforms: for (int i = 0; i < transforms.getLength(); i++) {
                  Transform t = transforms.item(i);
                  String URI = t.getURI();

                  if (URI.equals(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS)
                          || URI.equals(
                             Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS)) {
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

   // if signing and c14n11 property == true explicitly add
   // C14N11 transform if needed
   if (Reference.useC14N11 && !validating &&
       !output.isOutputStreamSet() && !output.isOctetStream()) {
       if (transforms == null) {
     transforms = new Transforms(this._doc);
                 this._constructionElement.insertBefore
         (transforms.getElement(), digestMethodElem);
       }
       transforms.addTransform(Transforms.TRANSFORM_C14N11_OMIT_COMMENTS);
             output.updateOutputStream(os, true);
View Full Code Here

Examples of org.apache.xml.security.transforms.Transforms

   *            InclusiveNamespaces to be WSI compliant.
   * @throws WSSecurityException
   */
  public void addReferencesToSign(Vector references, WSSecHeader secHeader)
      throws WSSecurityException {
    Transforms transforms = null;

    Element envelope = document.getDocumentElement();

    for (int part = 0; part < references.size(); part++) {
      WSEncryptionPart encPart = (WSEncryptionPart) references.get(part);

      String idToSign = encPart.getId();

      String elemName = encPart.getName();
      String nmSpace = encPart.getNamespace();

      /*
       * Set up the elements to sign. There are two resevered element
       * names: "Token" and "STRTransform" "Token": Setup the Signature to
       * either sign the information that points to the security token or
       * the token itself. If its a direct reference sign the token,
       * otherwise sign the KeyInfo Element. "STRTransform": Setup the
       * ds:Reference to use STR Transform
       *
       */
      transforms = new Transforms(document);
      try {
        if (idToSign != null) {
          Element toSignById = WSSecurityUtil.findElementById(
              document.getDocumentElement(), idToSign,
              WSConstants.WSU_NS);
          if (toSignById == null) {
            toSignById = WSSecurityUtil.findElementById(document
                .getDocumentElement(), idToSign, null);
          }
          transforms
              .addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
          if (wssConfig.isWsiBSPCompliant()) {
            transforms.item(0).getElement().appendChild(
                new InclusiveNamespaces(document,
                    getInclusivePrefixes(toSignById))
                    .getElement());
          }
          sig.addDocument("#" + idToSign, transforms);
        } else if (elemName.equals("Token")) {
          transforms
              .addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
          if (keyIdentifierType == WSConstants.BST_DIRECT_REFERENCE) {
            if (wssConfig.isWsiBSPCompliant()) {
              transforms
                  .item(0)
                  .getElement()
                  .appendChild(
                      new InclusiveNamespaces(
                          document,
                          getInclusivePrefixes(secHeader.getSecurityHeader()))
                          .getElement());
            }
            sig.addDocument("#" + certUri, transforms);
          } else {
            if (wssConfig.isWsiBSPCompliant()) {
              transforms.item(0).getElement().appendChild(
                  new InclusiveNamespaces(document,
                      getInclusivePrefixes(keyInfo
                          .getElement()))
                      .getElement());
            }
            sig.addDocument("#" + keyInfoUri, transforms);
          }
        } else if (elemName.equals("STRTransform")) { // STRTransform
          Element ctx = createSTRParameter(document);
          transforms.addTransform(
              STRTransform.implementedTransformURI, ctx);
          sig.addDocument("#" + strUri, transforms);
        } else if (elemName.equals("Assertion")) { // Assertion

          String id = null;
          id = SAMLUtil.getAssertionId(envelope, elemName, nmSpace);

          Element body = (Element) WSSecurityUtil.findElement(
              envelope, elemName, nmSpace);
          if (body == null) {
            throw new WSSecurityException(
                WSSecurityException.FAILURE, "noEncElement",
                new Object[] { nmSpace + ", " + elemName });
          }
          transforms
              .addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
          if (wssConfig.isWsiBSPCompliant()) {
            transforms.item(0).getElement().appendChild(
                new InclusiveNamespaces(document,
                    getInclusivePrefixes(body))
                    .getElement());
          }
          String prefix = WSSecurityUtil.setNamespace(body,
              WSConstants.WSU_NS, WSConstants.WSU_PREFIX);
          body.setAttributeNS(WSConstants.WSU_NS, prefix + ":Id", id);
          sig.addDocument("#" + id, transforms);

        } else {
          Element body = (Element) WSSecurityUtil.findElement(
              envelope, elemName, nmSpace);
          if (body == null) {
            throw new WSSecurityException(
                WSSecurityException.FAILURE, "noEncElement",
                new Object[] { nmSpace + ", " + elemName });
          }
          transforms
              .addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
          if (wssConfig.isWsiBSPCompliant()) {
            transforms.item(0).getElement().appendChild(
                new InclusiveNamespaces(document,
                    getInclusivePrefixes(body))
                    .getElement());
          }
          sig.addDocument("#" + setWsuId(body), transforms);
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.