Java Code Examples for org.apache.xml.security.signature.XMLSignature#getDocument()

The following examples show how to use org.apache.xml.security.signature.XMLSignature#getDocument() . 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: XmlSignatureBuilder.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void addKeyInfo(Credential signatureCredential, XMLSignature sig) throws TechnicalConnectorException, XMLSecurityException {
   if (signatureCredential.getCertificateChain() != null) {
      Certificate[] arr$ = signatureCredential.getCertificateChain();
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         Certificate cert = arr$[i$];
         if (sig.getKeyInfo().itemX509Data(0) == null) {
            X509Data x509data = new X509Data(sig.getDocument());
            sig.getKeyInfo().add(x509data);
         }

         sig.getKeyInfo().itemX509Data(0).addCertificate((X509Certificate)cert);
      }
   }

}
 
Example 2
Source File: XmlSignatureBuilder.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void addKeyInfo(Credential signatureCredential, XMLSignature sig) throws TechnicalConnectorException, XMLSecurityException {
   if (signatureCredential.getCertificateChain() != null) {
      Certificate[] arr$ = signatureCredential.getCertificateChain();
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         Certificate cert = arr$[i$];
         if (sig.getKeyInfo().itemX509Data(0) == null) {
            X509Data x509data = new X509Data(sig.getDocument());
            sig.getKeyInfo().add(x509data);
         }

         sig.getKeyInfo().itemX509Data(0).addCertificate((X509Certificate)cert);
      }
   }

}
 
Example 3
Source File: XmlSignatureBuilder.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void addKeyInfo(Credential signatureCredential, XMLSignature sig) throws TechnicalConnectorException, XMLSecurityException {
   if (signatureCredential.getCertificateChain() != null) {
      Certificate[] arr$ = signatureCredential.getCertificateChain();
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         Certificate cert = arr$[i$];
         if (sig.getKeyInfo().itemX509Data(0) == null) {
            X509Data x509data = new X509Data(sig.getDocument());
            sig.getKeyInfo().add(x509data);
         }

         sig.getKeyInfo().itemX509Data(0).addCertificate((X509Certificate)cert);
      }
   }

}
 
Example 4
Source File: PropertiesDataGenerationContext.java    From xades4j with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * A simple constructor to be used when only unsigned signature properties
 * will be processed.
 * @param targetXmlSignature the target signature
 * @param algorithmsProvider algorithms in use
 */
PropertiesDataGenerationContext(XMLSignature targetXmlSignature) throws XAdES4jXMLSigException
{
    this.targetXmlSignature = targetXmlSignature;
    this.sigDocument = targetXmlSignature.getDocument();
    this.referencesMappings = null;

    SignedInfo signedInfo = targetXmlSignature.getSignedInfo();
    List<Reference> refs = new ArrayList<Reference>(signedInfo.getLength());
    for (int i = 0; i < signedInfo.getLength(); i++)
    {
        try
        {
            refs.add(signedInfo.item(i));
        } catch (XMLSecurityException ex)
        {
            throw new XAdES4jXMLSigException(String.format("Cannot process the %dth reference", i), ex);
        }
    }
    this.references = Collections.unmodifiableList(refs);
}
 
Example 5
Source File: QualifyingPropertyVerificationContext.java    From xades4j with GNU Lesser General Public License v3.0 6 votes vote down vote up
SignedObjectsData(
        List<RawDataObjectDesc> references,
        XMLSignature signature)
{
    this.dataObjs = references;
    this.signatureDoc = signature.getDocument();

    // Map elements to References.
    this.references = new HashMap<Element, RawDataObjectDesc>(references.size());
    for (RawDataObjectDesc obj : references)
    {
        this.references.put(obj.getReference().getElement(), obj);
    }

    // Map elements to XMLObjects.
    int nXmlObjs = signature.getObjectLength();
    this.objects = new HashMap<Element, ObjectContainer>(nXmlObjs);
    for (int i = 0; i < nXmlObjs; i++)
    {
        ObjectContainer xmlObj = signature.getObjectItem(i);
        this.objects.put(xmlObj.getElement(), xmlObj);
    }
}
 
Example 6
Source File: URIContentReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void createReference(XMLSignature signature) {
    try {
        Transforms dsigTransforms = new Transforms(signature.getDocument());
        for (String transform : transforms) {
            dsigTransforms.addTransform(transform);
        }

        signature.addDocument(referenceID, dsigTransforms, digestAlgorithm);
    } catch (Exception e) {
        log.error("Error while adding content reference", e);
    }
}
 
Example 7
Source File: SAMLObjectContentReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Populate the inclusive namspace prefixes on the specified Apache (exclusive) transform object.
 * 
 * @param signature the Apache XMLSignature object
 * @param transform the Apache Transform object representing an exclusive transform
 */
private void processExclusiveTransform(XMLSignature signature, Transform transform) {
    // Namespaces that aren't visibly used, such as those used in QName attribute values, would
    // be stripped out by exclusive canonicalization. Need to make sure they aren't by explicitly
    // telling the transformer about them.
    log.debug("Adding list of inclusive namespaces for signature exclusive canonicalization transform");
    LazySet<String> inclusiveNamespacePrefixes = new LazySet<String>();
    populateNamespacePrefixes(inclusiveNamespacePrefixes, signableObject);
    
    if (inclusiveNamespacePrefixes != null && inclusiveNamespacePrefixes.size() > 0) {
        InclusiveNamespaces inclusiveNamespaces = new InclusiveNamespaces(signature.getDocument(),
                inclusiveNamespacePrefixes);
        transform.getElement().appendChild(inclusiveNamespaces.getElement());
    }
}