Search in sources :

Example 1 with InclusiveNamespaces

use of com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces in project jdk8u_jdk by JetBrains.

the class Reference method getHTMLRepresentation.

/**
     * Method getHTMLRepresentation
     * @return The HTML of the transformation
     * @throws XMLSignatureException
     */
public String getHTMLRepresentation() throws XMLSignatureException {
    try {
        XMLSignatureInput nodes = this.getNodesetBeforeFirstCanonicalization();
        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)) {
                    c14nTransform = t;
                    break doTransforms;
                }
            }
        }
        Set<String> inclusiveNamespaces = new HashSet<String>();
        if (c14nTransform != null && (c14nTransform.length(InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1)) {
            // there is one InclusiveNamespaces element
            InclusiveNamespaces in = new InclusiveNamespaces(XMLUtils.selectNode(c14nTransform.getElement().getFirstChild(), InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 0), this.getBaseURI());
            inclusiveNamespaces = InclusiveNamespaces.prefixStr2Set(in.getInclusiveNamespaces());
        }
        return nodes.getHTMLRepresentation(inclusiveNamespaces);
    } catch (TransformationException ex) {
        throw new XMLSignatureException("empty", ex);
    } catch (InvalidTransformException ex) {
        throw new XMLSignatureException("empty", ex);
    } catch (XMLSecurityException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
Also used : InvalidTransformException(com.sun.org.apache.xml.internal.security.transforms.InvalidTransformException) TransformationException(com.sun.org.apache.xml.internal.security.transforms.TransformationException) Transforms(com.sun.org.apache.xml.internal.security.transforms.Transforms) InclusiveNamespaces(com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces) Transform(com.sun.org.apache.xml.internal.security.transforms.Transform) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) HashSet(java.util.HashSet)

Example 2 with InclusiveNamespaces

use of com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces in project jdk8u_jdk by JetBrains.

the class SignedInfo method getInclusiveNamespaces.

public String getInclusiveNamespaces() {
    String c14nMethodURI = c14nMethod.getAttributeNS(null, Constants._ATT_ALGORITHM);
    if (!(c14nMethodURI.equals("http://www.w3.org/2001/10/xml-exc-c14n#") || c14nMethodURI.equals("http://www.w3.org/2001/10/xml-exc-c14n#WithComments"))) {
        return null;
    }
    Element inclusiveElement = XMLUtils.getNextElement(c14nMethod.getFirstChild());
    if (inclusiveElement != null) {
        try {
            String inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement, InclusiveNamespaces.ExclusiveCanonicalizationNamespace).getInclusiveNamespaces();
            return inclusiveNamespaces;
        } catch (XMLSecurityException e) {
            return null;
        }
    }
    return null;
}
Also used : Element(org.w3c.dom.Element) InclusiveNamespaces(com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Example 3 with InclusiveNamespaces

use of com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces in project jdk8u_jdk by JetBrains.

the class TransformC14NExclusive method enginePerformTransform.

protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transformObject) throws CanonicalizationException {
    try {
        String inclusiveNamespaces = null;
        if (transformObject.length(InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1) {
            Element inclusiveElement = XMLUtils.selectNode(transformObject.getElement().getFirstChild(), InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 0);
            inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement, transformObject.getBaseURI()).getInclusiveNamespaces();
        }
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        if (os != null) {
            c14n.setWriter(os);
        }
        byte[] result = c14n.engineCanonicalize(input, inclusiveNamespaces);
        XMLSignatureInput output = new XMLSignatureInput(result);
        if (os != null) {
            output.setOutputStream(os);
        }
        return output;
    } catch (XMLSecurityException ex) {
        throw new CanonicalizationException("empty", ex);
    }
}
Also used : CanonicalizationException(com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException) Element(org.w3c.dom.Element) InclusiveNamespaces(com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) Canonicalizer20010315ExclOmitComments(com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Example 4 with InclusiveNamespaces

use of com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces in project jdk8u_jdk by JetBrains.

the class TransformC14NExclusiveWithComments method enginePerformTransform.

protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transformObject) throws CanonicalizationException {
    try {
        String inclusiveNamespaces = null;
        if (transformObject.length(InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1) {
            Element inclusiveElement = XMLUtils.selectNode(transformObject.getElement().getFirstChild(), InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 0);
            inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement, transformObject.getBaseURI()).getInclusiveNamespaces();
        }
        Canonicalizer20010315ExclWithComments c14n = new Canonicalizer20010315ExclWithComments();
        if (os != null) {
            c14n.setWriter(os);
        }
        byte[] result = c14n.engineCanonicalize(input, inclusiveNamespaces);
        XMLSignatureInput output = new XMLSignatureInput(result);
        return output;
    } catch (XMLSecurityException ex) {
        throw new CanonicalizationException("empty", ex);
    }
}
Also used : Canonicalizer20010315ExclWithComments(com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments) CanonicalizationException(com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException) Element(org.w3c.dom.Element) InclusiveNamespaces(com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Aggregations

XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)4 InclusiveNamespaces (com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces)4 Element (org.w3c.dom.Element)3 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)2 XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)2 Canonicalizer20010315ExclOmitComments (com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments)1 Canonicalizer20010315ExclWithComments (com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments)1 InvalidTransformException (com.sun.org.apache.xml.internal.security.transforms.InvalidTransformException)1 Transform (com.sun.org.apache.xml.internal.security.transforms.Transform)1 TransformationException (com.sun.org.apache.xml.internal.security.transforms.TransformationException)1 Transforms (com.sun.org.apache.xml.internal.security.transforms.Transforms)1 HashSet (java.util.HashSet)1