Search in sources :

Example 16 with DataObjectDesc

use of xades4j.properties.DataObjectDesc in project xades4j by luisgoncalves.

the class SignerBESTest method testSignBES.

@Test
public void testSignBES() throws Exception {
    System.out.println("signBES");
    Document doc1 = getTestDocument();
    Document doc2 = getDocument("content.xml");
    Node objectContent = doc1.importNode(doc2.getDocumentElement(), true);
    Element elemToSign = doc1.getDocumentElement();
    SignerBES signer = (SignerBES) new XadesBesSigningProfile(keyingProviderMy).newSigner();
    IndividualDataObjsTimeStampProperty dataObjsTimeStamp = new IndividualDataObjsTimeStampProperty();
    AllDataObjsCommitmentTypeProperty globalCommitment = AllDataObjsCommitmentTypeProperty.proofOfApproval();
    CommitmentTypeProperty commitment = (CommitmentTypeProperty) CommitmentTypeProperty.proofOfCreation().withQualifier("MyQualifier");
    DataObjectDesc obj1 = new DataObjectReference('#' + elemToSign.getAttribute("Id")).withTransform(new EnvelopedSignatureTransform()).withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding").withDescription("Isto é uma descrição do elemento raiz").withDocumentationUri("http://doc1.txt").withDocumentationUri("http://doc2.txt").withIdentifier("http://elem.root")).withCommitmentType(commitment).withDataObjectTimeStamp(dataObjsTimeStamp);
    DataObjectDesc obj2 = new EnvelopedXmlObject(objectContent, "text/xml", null).withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding").withDescription("Isto é uma descrição do elemento dentro do object").withDocumentationUri("http://doc3.txt").withDocumentationUri("http://doc4.txt").withIdentifier("http://elem.in.object")).withCommitmentType(commitment).withDataObjectTimeStamp(dataObjsTimeStamp);
    SignedDataObjects dataObjs = new SignedDataObjects(obj1, obj2).withCommitmentType(globalCommitment).withDataObjectsTimeStamp();
    signer.sign(dataObjs, elemToSign);
    outputDocument(doc1, "document.signed.bes.xml");
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) DataObjectFormatProperty(xades4j.properties.DataObjectFormatProperty) EnvelopedSignatureTransform(xades4j.algorithms.EnvelopedSignatureTransform) Document(org.w3c.dom.Document) DataObjectDesc(xades4j.properties.DataObjectDesc) AllDataObjsCommitmentTypeProperty(xades4j.properties.AllDataObjsCommitmentTypeProperty) AllDataObjsCommitmentTypeProperty(xades4j.properties.AllDataObjsCommitmentTypeProperty) CommitmentTypeProperty(xades4j.properties.CommitmentTypeProperty) IndividualDataObjsTimeStampProperty(xades4j.properties.IndividualDataObjsTimeStampProperty) Test(org.junit.Test)

Aggregations

DataObjectDesc (xades4j.properties.DataObjectDesc)16 Document (org.w3c.dom.Document)8 Reference (org.apache.xml.security.signature.Reference)7 Test (org.junit.Test)7 EnvelopedSignatureTransform (xades4j.algorithms.EnvelopedSignatureTransform)5 Element (org.w3c.dom.Element)4 DataObjectFormatProperty (xades4j.properties.DataObjectFormatProperty)4 ArrayList (java.util.ArrayList)3 ObjectContainer (org.apache.xml.security.signature.ObjectContainer)3 XMLSignature (org.apache.xml.security.signature.XMLSignature)3 IndividualDataObjsTimeStampProperty (xades4j.properties.IndividualDataObjsTimeStampProperty)3 XMLSignatureException (org.apache.xml.security.signature.XMLSignatureException)2 Transforms (org.apache.xml.security.transforms.Transforms)2 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)2 AllDataObjsCommitmentTypeProperty (xades4j.properties.AllDataObjsCommitmentTypeProperty)2 CommitmentTypeProperty (xades4j.properties.CommitmentTypeProperty)2 CounterSignatureProperty (xades4j.properties.CounterSignatureProperty)2 QualifyingProperties (xades4j.properties.QualifyingProperties)2 SignedSignatureProperty (xades4j.properties.SignedSignatureProperty)2 SignerRoleProperty (xades4j.properties.SignerRoleProperty)2