Search in sources :

Example 1 with SignaturePropertiesCollector

use of xades4j.providers.SignaturePropertiesCollector in project xades4j by luisgoncalves.

the class SignerBESTest method testSignBESWithCounterSig.

@Test
public void testSignBESWithCounterSig() throws Exception {
    System.out.println("signBESWithCounterSig");
    Document doc = getTestDocument();
    Element elemToSign = doc.getDocumentElement();
    XadesBesSigningProfile profile = new XadesBesSigningProfile(keyingProviderMy);
    final XadesSigner counterSigner = profile.newSigner();
    profile.withSignaturePropertiesProvider(new SignaturePropertiesProvider() {

        @Override
        public void provideProperties(SignaturePropertiesCollector signedPropsCol) {
            signedPropsCol.addCounterSignature(new CounterSignatureProperty(counterSigner));
            signedPropsCol.setSignerRole(new SignerRoleProperty("CounterSignature maniac"));
        }
    });
    SignerBES signer = (SignerBES) profile.newSigner();
    DataObjectDesc obj1 = new DataObjectReference('#' + elemToSign.getAttribute("Id")).withTransform(new EnvelopedSignatureTransform());
    SignedDataObjects dataObjs = new SignedDataObjects().withSignedDataObject(obj1);
    signer.sign(dataObjs, elemToSign);
    outputDocument(doc, "document.signed.bes.cs.xml");
}
Also used : Element(org.w3c.dom.Element) SignerRoleProperty(xades4j.properties.SignerRoleProperty) SignaturePropertiesCollector(xades4j.providers.SignaturePropertiesCollector) EnvelopedSignatureTransform(xades4j.algorithms.EnvelopedSignatureTransform) Document(org.w3c.dom.Document) SignaturePropertiesProvider(xades4j.providers.SignaturePropertiesProvider) DataObjectDesc(xades4j.properties.DataObjectDesc) CounterSignatureProperty(xades4j.properties.CounterSignatureProperty) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 EnvelopedSignatureTransform (xades4j.algorithms.EnvelopedSignatureTransform)1 CounterSignatureProperty (xades4j.properties.CounterSignatureProperty)1 DataObjectDesc (xades4j.properties.DataObjectDesc)1 SignerRoleProperty (xades4j.properties.SignerRoleProperty)1 SignaturePropertiesCollector (xades4j.providers.SignaturePropertiesCollector)1 SignaturePropertiesProvider (xades4j.providers.SignaturePropertiesProvider)1