1 17 package com.sun.org.apache.xml.internal.security.transforms.implementations; 18 19 20 21 import com.sun.org.apache.xml.internal.security.signature.NodeFilter; 22 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; 23 import com.sun.org.apache.xml.internal.security.transforms.TransformSpi; 24 import com.sun.org.apache.xml.internal.security.transforms.TransformationException; 25 import com.sun.org.apache.xml.internal.security.transforms.Transforms; 26 import com.sun.org.apache.xml.internal.security.utils.Constants; 27 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 28 import org.w3c.dom.Element ; 29 import org.w3c.dom.Node ; 30 31 32 38 public class TransformEnvelopedSignature extends TransformSpi { 39 40 41 public static final String implementedTransformURI = 42 Transforms.TRANSFORM_ENVELOPED_SIGNATURE; 43 44 49 protected String engineGetURI() { 50 return implementedTransformURI; 51 } 52 53 56 protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input) 57 throws TransformationException { 58 59 60 61 72 73 78 79 Element transformElement = this._transformObject.getElement(); 80 Node signatureElement = transformElement; 81 82 83 signatureElement = searchSignatureElement(signatureElement); 84 input.setExcludeNode(signatureElement); 85 input.addNodeFilter(new EnvelopedNodeFilter(signatureElement)); 86 return input; 87 88 90 91 } 92 93 98 private static Node searchSignatureElement(Node signatureElement) throws TransformationException { 99 boolean found=false; 100 101 while (true) { 102 if ((signatureElement == null) 103 || (signatureElement.getNodeType() == Node.DOCUMENT_NODE)) { 104 break; 105 } 106 Element el=(Element )signatureElement; 107 if (el.getNamespaceURI().equals(Constants.SignatureSpecNS) 108 && 109 el.getLocalName().equals(Constants._TAG_SIGNATURE)) { 110 found = true; 111 break; 112 } 113 114 signatureElement = signatureElement.getParentNode(); 115 } 116 117 if (!found) { 118 throw new TransformationException( 119 "envelopedSignatureTransformNotInSignatureElement"); 120 } 121 return signatureElement; 122 } 123 class EnvelopedNodeFilter implements NodeFilter { 124 Node exclude; 125 EnvelopedNodeFilter(Node n) { 126 exclude=n; 127 } 128 131 public boolean isNodeInclude(Node n) { 132 return !XMLUtils.isDescendantOrSelf(exclude,n); 134 } 135 136 } 137 } 138 | Popular Tags |