Package org.apache.xml.security.transforms

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



         if (noOfSteps == 0) {
            Object exArgs[] = { Transforms.TRANSFORM_XPATH2FILTER, "XPath" };

            throw new TransformationException("xml.WrongContent", exArgs);
         }

         if (true) {
            _filterTypes.add(FUnion);

            // Set root = new HashSet(); root.add(inputDoc);
            HelperNodeList root = new HelperNodeList();

            root.appendChild(inputDoc);
            _filterNodes.add(root);
         }

         for (int i = 0; i < noOfSteps; i++) {
            Element xpathElement =XMLUtils.selectNode(
               this._transformObject.getElement().getFirstChild(),
                  XPath2FilterContainer.XPathFilter2NS,
                  XPath2FilterContainer._TAG_XPATH2,i);
            XPath2FilterContainer xpathContainer =
               XPath2FilterContainer.newInstance(xpathElement,
                                                   input.getSourceURI());

            if (xpathContainer.isIntersect()) {
               _filterTypes.add(FIntersect);
            } else if (xpathContainer.isSubtract()) {
               _filterTypes.add(FSubtract);
            } else if (xpathContainer.isUnion()) {
               _filterTypes.add(FUnion);
            } else {
               _filterTypes.add(null);
            }

            NodeList subtreeRoots = xPathFuncHereAPI.selectNodeList(inputDoc,
                                       xpathContainer.getXPathFilterTextNode(),
                                       CachedXPathFuncHereAPI.getStrFromNode(xpathContainer.getXPathFilterTextNode()),
                                       xpathContainer.getElement());

            // _filterNodes.add(XMLUtils.convertNodelistToSet(subtreeRoots));
            _filterNodes.add(subtreeRoots);
         }

         this._F = new HashSet();
         this._ancestors = new ArrayList();

         this.traversal(inputDoc);

         Set resultSet = new HashSet();
         Iterator it = this._inputSet.iterator();
         while (it.hasNext()) {
            Object n = it.next();
            if (this._F.contains(n)) {
               resultSet.add(n);
            }
         }

         XMLSignatureInput result = new XMLSignatureInput(resultSet);


         result.setSourceURI(input.getSourceURI());

         return result;
      } catch (TransformerException ex) {
         throw new TransformationException("empty", ex);
      } catch (DOMException ex) {
         throw new TransformationException("empty", ex);
      } catch (IOException ex) {
         throw new TransformationException("empty", ex);
      } catch (CanonicalizationException ex) {
         throw new TransformationException("empty", ex);
      } catch (InvalidCanonicalizerException ex) {
         throw new TransformationException("empty", ex);
      } catch (ParserConfigurationException ex) {
         throw new TransformationException("empty", ex);
      } catch (XMLSecurityException ex) {
         throw new TransformationException("empty", ex);
      } catch (SAXException ex) {
         throw new TransformationException("empty", ex);
      }
   }
View Full Code Here


            traverseElement(rootNode,sb);
            byte[] decodedBytes = Base64.decode(sb.toString());
     
            return new XMLSignatureInput(decodedBytes);
      } catch (ParserConfigurationException e) {
        throw new TransformationException("c14n.Canonicalizer.Exception",e);
      } catch (SAXException e) {
        throw new TransformationException("SAX exception", e);
      }     
  } catch (Base64DecodingException e) {
        throw new TransformationException("Base64Decoding", e);
  }
   }
View Full Code Here

   }

   private String canonicalize(Element element, Element method) throws TransformationException, InvalidCanonicalizerException, CanonicalizationException
   {
      if (method == null || ! method.getLocalName().equals("CanonicalizationMethod"))
         throw new TransformationException("CanonicalizationMethod expected!");

      String algorithm = method.getAttribute("Algorithm");
      if (algorithm == null || algorithm.length() == 0)
         throw new TransformationException("CanonicalizationMethod missing algorithm!");

      Canonicalizer canon = Canonicalizer.getInstance(algorithm);

      return new String(canon.canonicalizeSubtree(element, "#default"));
   }
View Full Code Here

         // Obtain the canonicalizer specified in the transformation parameters
         Element parameters = XMLUtils.selectNode(transformObject.getElement().getFirstChild(), Constants.WSSE_NS,
               "TransformationParameters", 0);
         if (parameters == null)
            throw new TransformationException("wsse:TransformationParameters expected!");

         Element method = Util.getFirstChildElement(parameters);
         String transformed = canonicalize(element, method);

         // Now WS-Security says we must augment the transformed output to ensure that there is
         // a default namespace
         int startTag = transformed.indexOf('<');
         int endTag = transformed.indexOf('>', startTag + 1);
         String within = transformed.substring(startTag + 1, endTag);
         if (! within.contains("xmlns="))
         {
            int insPos = within.indexOf(" ") + startTag + 1;
            transformed = new StringBuilder(transformed).insert(insPos, " xmlns=\"\"").toString();
         }

         return new XMLSignatureInput(transformed.getBytes());
      }
      catch (WSSecurityException e)
      {
         throw new TransformationException(e.getMessage(), e);
      }
      finally
      {
         ThreadLocalAssociation.localStrTransformAssoc().set(null);
      }
View Full Code Here

/*     */
/*     */   private String canonicalize(Element element, Element method)
/*     */     throws TransformationException, InvalidCanonicalizerException, CanonicalizationException
/*     */   {
/*  74 */     if ((method == null) || (!method.getLocalName().equals("CanonicalizationMethod"))) {
/*  75 */       throw new TransformationException("CanonicalizationMethod expected!");
/*     */     }
/*  77 */     String algorithm = method.getAttribute("Algorithm");
/*  78 */     if ((algorithm == null) || (algorithm.length() == 0)) {
/*  79 */       throw new TransformationException("CanonicalizationMethod missing algorithm!");
/*     */     }
/*  81 */     Canonicalizer canon = Canonicalizer.getInstance(algorithm);
/*     */
/*  83 */     return new String(canon.canonicalizeSubtree(element, "#default"));
/*     */   }
View Full Code Here

/* 115 */       element = token.getSTRTransformElement();
/*     */
/* 118 */       Element parameters = XMLUtils.selectNode(this._transformObject.getElement().getFirstChild(), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "TransformationParameters", 0);
/*     */
/* 120 */       if (parameters == null) {
/* 121 */         throw new TransformationException("wsse:TransformationParameters expected!");
/*     */       }
/* 123 */       Element method = Util.getFirstChildElement(parameters);
/* 124 */       String transformed = canonicalize(element, method);
/*     */
/* 128 */       int startTag = transformed.indexOf('<');
/* 129 */       int endTag = transformed.indexOf('>', startTag + 1);
/* 130 */       String within = transformed.substring(startTag + 1, endTag);
/* 131 */       if (!within.contains("xmlns="))
/*     */       {
/* 133 */         insPos = within.indexOf(" ") + startTag + 1;
/* 134 */         transformed = new StringBuilder(transformed).insert(insPos, " xmlns=\"\"").toString();
/*     */       }
/*     */
/* 137 */       int insPos = new XMLSignatureInput(transformed.getBytes());
/*     */       return insPos;
/*     */     }
/*     */     catch (WSSecurityException e)
/*     */     {
/* 141 */       throw new TransformationException(e.getMessage(), e);
/*     */     }
/*     */     finally
/*     */     {
/* 145 */       ThreadLocalAssociation.localStrTransformAssoc().set(null); } throw localObject;
/*     */   }
View Full Code Here

TOP

Related Classes of org.apache.xml.security.transforms.TransformationException

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.