Java Code Examples for com.sun.org.apache.xml.internal.security.utils.XMLUtils#addReturnToElement()

The following examples show how to use com.sun.org.apache.xml.internal.security.utils.XMLUtils#addReturnToElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XPath2FilterContainer04.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor XPath2FilterContainer04
 *
 * @param doc
 * @param xpath2filter
 * @param filterType
 */
private XPath2FilterContainer04(Document doc, String xpath2filter, String filterType) {
    super(doc);

    this.constructionElement.setAttributeNS(
        null, XPath2FilterContainer04._ATT_FILTER, filterType);

    if ((xpath2filter.length() > 2)
        && (!Character.isWhitespace(xpath2filter.charAt(0)))) {
        XMLUtils.addReturnToElement(this.constructionElement);
        this.constructionElement.appendChild(doc.createTextNode(xpath2filter));
        XMLUtils.addReturnToElement(this.constructionElement);
    } else {
        this.constructionElement.appendChild(doc.createTextNode(xpath2filter));
    }
}
 
Example 2
Source File: Manifest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This <code>addDocument</code> method is used to add a new resource to the
 * signed info. A {@link com.sun.org.apache.xml.internal.security.signature.Reference} is built
 * from the supplied values.
 *
 * @param baseURI the URI of the resource where the XML instance was stored
 * @param referenceURI <code>URI</code> attribute in <code>Reference</code> for specifying
 * where data is
 * @param transforms com.sun.org.apache.xml.internal.security.signature.Transforms object with an ordered
 * list of transformations to be performed.
 * @param digestURI The digest algorithm URI to be used.
 * @param referenceId
 * @param referenceType
 * @throws XMLSignatureException
 */
public void addDocument(
    String baseURI, String referenceURI, Transforms transforms,
    String digestURI, String referenceId, String referenceType
) throws XMLSignatureException {
    // the this.doc is handed implicitly by the this.getOwnerDocument()
    Reference ref =
        new Reference(this.doc, baseURI, referenceURI, this, transforms, digestURI);

    if (referenceId != null) {
        ref.setId(referenceId);
    }

    if (referenceType != null) {
        ref.setType(referenceType);
    }

    // add Reference object to our cache vector
    this.references.add(ref);

    // add the Element of the Reference object to the Manifest/SignedInfo
    this.constructionElement.appendChild(ref.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 3
Source File: KeyValue.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor KeyValue
 *
 * @param doc
 * @param dsaKeyValue
 */
public KeyValue(Document doc, DSAKeyValue dsaKeyValue) {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);
    this.constructionElement.appendChild(dsaKeyValue.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 4
Source File: XMLSignature.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Appends an Object (not a <code>java.lang.Object</code> but an Object
 * element) to the Signature. Please note that this is only possible
 * when signing.
 *
 * @param object ds:Object to be appended.
 * @throws XMLSignatureException When this object is used to verify.
 */
public void appendObject(ObjectContainer object) throws XMLSignatureException {
    //try {
    //if (this.state != MODE_SIGN) {
    // throw new XMLSignatureException(
    //  "signature.operationOnlyBeforeSign");
    //}

    this.constructionElement.appendChild(object.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
    //} catch (XMLSecurityException ex) {
    // throw new XMLSignatureException("empty", ex);
    //}
}
 
Example 5
Source File: XMLSignature.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the KeyInfo child. If we are in signing mode and the KeyInfo
 * does not exist yet, it is created on demand and added to the Signature.
 * <br>
 * This allows to add arbitrary content to the KeyInfo during signing.
 *
 * @return the KeyInfo object
 */
public KeyInfo getKeyInfo() {
    // check to see if we are signing and if we have to create a keyinfo
    if (this.state == MODE_SIGN && this.keyInfo == null) {

        // create the KeyInfo
        this.keyInfo = new KeyInfo(this.doc);

        // get the Element from KeyInfo
        Element keyInfoElement = this.keyInfo.getElement();
        Element firstObject =
            XMLUtils.selectDsNode(
                this.constructionElement.getFirstChild(), Constants._TAG_OBJECT, 0
            );

        if (firstObject != null) {
            // add it before the object
            this.constructionElement.insertBefore(keyInfoElement, firstObject);
            XMLUtils.addReturnBeforeChild(this.constructionElement, firstObject);
        } else {
            // add it as the last element to the signature
            this.constructionElement.appendChild(keyInfoElement);
            XMLUtils.addReturnToElement(this.constructionElement);
        }
    }

    return this.keyInfo;
}
 
Example 6
Source File: KeyInfo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method addX509Data
 *
 * @param x509data
 */
public void add(X509Data x509data) {
    if (x509Datas == null) {
        x509Datas = new ArrayList<X509Data>();
    }
    x509Datas.add(x509data);
    this.constructionElement.appendChild(x509data.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 7
Source File: KeyValue.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor KeyValue
 *
 * @param doc
 * @param unknownKeyValue
 */
public KeyValue(Document doc, Element unknownKeyValue) {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);
    this.constructionElement.appendChild(unknownKeyValue);
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 8
Source File: Reference.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor Reference
 *
 * @param doc the {@link Document} in which <code>XMLsignature</code> is placed
 * @param baseURI the URI of the resource where the XML instance will be stored
 * @param referenceURI URI indicate where is data which will digested
 * @param manifest
 * @param transforms {@link Transforms} applied to data
 * @param messageDigestAlgorithm {@link MessageDigestAlgorithm Digest algorithm} which is
 * applied to the data
 * TODO should we throw XMLSignatureException if MessageDigestAlgoURI is wrong?
 * @throws XMLSignatureException
 */
protected Reference(
    Document doc, String baseURI, String referenceURI, Manifest manifest,
    Transforms transforms, String messageDigestAlgorithm
) throws XMLSignatureException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    this.baseURI = baseURI;
    this.manifest = manifest;

    this.setURI(referenceURI);

    // important: The ds:Reference must be added to the associated ds:Manifest
    //            or ds:SignedInfo _before_ the this.resolverResult() is called.
    // this.manifest.appendChild(this.constructionElement);
    // this.manifest.appendChild(this.doc.createTextNode("\n"));

    if (transforms != null) {
        this.transforms=transforms;
        this.constructionElement.appendChild(transforms.getElement());
        XMLUtils.addReturnToElement(this.constructionElement);
    }
    MessageDigestAlgorithm mda =
        MessageDigestAlgorithm.getInstance(this.doc, messageDigestAlgorithm);

    digestMethodElem = mda.getElement();
    this.constructionElement.appendChild(digestMethodElem);
    XMLUtils.addReturnToElement(this.constructionElement);

    digestValueElement =
        XMLUtils.createElementInSignatureSpace(this.doc, Constants._TAG_DIGESTVALUE);

    this.constructionElement.appendChild(digestValueElement);
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 9
Source File: XPathFilterCHGPContainer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor XPathFilterCHGPContainer
 *
 * @param doc
 * @param includeSlashPolicy
 * @param includeButSearch
 * @param excludeButSearch
 * @param exclude
 */
private XPathFilterCHGPContainer(
    Document doc, boolean includeSlashPolicy, String includeButSearch,
    String excludeButSearch, String exclude
) {
    super(doc);

    if (includeSlashPolicy) {
        this.constructionElement.setAttributeNS(
            null, XPathFilterCHGPContainer._ATT_INCLUDESLASH, "true"
        );
    } else {
        this.constructionElement.setAttributeNS(
            null, XPathFilterCHGPContainer._ATT_INCLUDESLASH, "false"
        );
    }

    if ((includeButSearch != null) && (includeButSearch.trim().length() > 0)) {
        Element includeButSearchElem =
            ElementProxy.createElementForFamily(
                doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_INCLUDE_BUT_SEARCH
            );

        includeButSearchElem.appendChild(
            this.doc.createTextNode(indentXPathText(includeButSearch))
        );
        XMLUtils.addReturnToElement(this.constructionElement);
        this.constructionElement.appendChild(includeButSearchElem);
    }

    if ((excludeButSearch != null) && (excludeButSearch.trim().length() > 0)) {
        Element excludeButSearchElem =
            ElementProxy.createElementForFamily(
                doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_EXCLUDE_BUT_SEARCH
            );

        excludeButSearchElem.appendChild(
            this.doc.createTextNode(indentXPathText(excludeButSearch)));

        XMLUtils.addReturnToElement(this.constructionElement);
        this.constructionElement.appendChild(excludeButSearchElem);
    }

    if ((exclude != null) && (exclude.trim().length() > 0)) {
        Element excludeElem =
            ElementProxy.createElementForFamily(
               doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_EXCLUDE);

        excludeElem.appendChild(this.doc.createTextNode(indentXPathText(exclude)));
        XMLUtils.addReturnToElement(this.constructionElement);
        this.constructionElement.appendChild(excludeElem);
    }

    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 10
Source File: X509Data.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Constructor X509Data
 *
 * @param doc
 */
public X509Data(Document doc) {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 11
Source File: SignatureProperties.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor SignatureProperties
 *
 * @param doc
 */
public SignatureProperties(Document doc) {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 12
Source File: X509Data.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor X509Data
 *
 * @param doc
 */
public X509Data(Document doc) {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 13
Source File: XPathFilterCHGPContainer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor XPathFilterCHGPContainer
 *
 * @param doc
 * @param includeSlashPolicy
 * @param includeButSearch
 * @param excludeButSearch
 * @param exclude
 */
private XPathFilterCHGPContainer(
    Document doc, boolean includeSlashPolicy, String includeButSearch,
    String excludeButSearch, String exclude
) {
    super(doc);

    if (includeSlashPolicy) {
        this.constructionElement.setAttributeNS(
            null, XPathFilterCHGPContainer._ATT_INCLUDESLASH, "true"
        );
    } else {
        this.constructionElement.setAttributeNS(
            null, XPathFilterCHGPContainer._ATT_INCLUDESLASH, "false"
        );
    }

    if ((includeButSearch != null) && (includeButSearch.trim().length() > 0)) {
        Element includeButSearchElem =
            ElementProxy.createElementForFamily(
                doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_INCLUDE_BUT_SEARCH
            );

        includeButSearchElem.appendChild(
            this.doc.createTextNode(indentXPathText(includeButSearch))
        );
        XMLUtils.addReturnToElement(this.constructionElement);
        this.constructionElement.appendChild(includeButSearchElem);
    }

    if ((excludeButSearch != null) && (excludeButSearch.trim().length() > 0)) {
        Element excludeButSearchElem =
            ElementProxy.createElementForFamily(
                doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_EXCLUDE_BUT_SEARCH
            );

        excludeButSearchElem.appendChild(
            this.doc.createTextNode(indentXPathText(excludeButSearch)));

        XMLUtils.addReturnToElement(this.constructionElement);
        this.constructionElement.appendChild(excludeButSearchElem);
    }

    if ((exclude != null) && (exclude.trim().length() > 0)) {
        Element excludeElem =
            ElementProxy.createElementForFamily(
               doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_EXCLUDE);

        excludeElem.appendChild(this.doc.createTextNode(indentXPathText(exclude)));
        XMLUtils.addReturnToElement(this.constructionElement);
        this.constructionElement.appendChild(excludeElem);
    }

    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 14
Source File: X509Data.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor X509Data
 *
 * @param doc
 */
public X509Data(Document doc) {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 15
Source File: XMLX509IssuerSerial.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructor XMLX509IssuerSerial
 *
 * @param doc
 * @param x509IssuerName
 * @param x509SerialNumber
 */
public XMLX509IssuerSerial(Document doc, String x509IssuerName, BigInteger x509SerialNumber) {
    super(doc);
    XMLUtils.addReturnToElement(this.constructionElement);
    addTextElement(x509IssuerName, Constants._TAG_X509ISSUERNAME);
    addTextElement(x509SerialNumber.toString(), Constants._TAG_X509SERIALNUMBER);
}
 
Example 16
Source File: X509Data.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method add
 *
 * @param xmlX509CRL
 */
public void add(XMLX509CRL xmlX509CRL) {
    this.constructionElement.appendChild(xmlX509CRL.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 17
Source File: X509Data.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method add
 *
 * @param XMLX509Digest
 */
public void add(XMLX509Digest xmlX509Digest) {
    this.constructionElement.appendChild(xmlX509Digest.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 18
Source File: KeyInfo.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Method add
 *
 * @param retrievalmethod
 */
public void add(RetrievalMethod retrievalmethod) {
    this.constructionElement.appendChild(retrievalmethod.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 19
Source File: KeyInfo.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method add
 *
 * @param retrievalmethod
 */
public void add(RetrievalMethod retrievalmethod) {
    this.constructionElement.appendChild(retrievalmethod.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example 20
Source File: SignatureProperties.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method addSignatureProperty
 *
 * @param sp
 */
public void addSignatureProperty(SignatureProperty sp) {
    this.constructionElement.appendChild(sp.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);
}