Search in sources :

Example 1 with XAdESSignatureProperties

use of org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties in project camel by apache.

the class XAdESSignaturePropertiesTest method testExceptionSigPolicyDigestMissing.

private void testExceptionSigPolicyDigestMissing(String value) throws InterruptedException, Exception {
    MockEndpoint mock = getMockEndpoint("mock:exception");
    mock.expectedMessageCount(1);
    XmlSignerEndpoint endpoint = getSignerEndpoint();
    XAdESSignatureProperties props = (XAdESSignatureProperties) endpoint.getProperties();
    props.setSignaturePolicyDigestValue(value);
    sendBody("direct:enveloping", payload, Collections.<String, Object>emptyMap());
    assertMockEndpointsSatisfied();
    checkThrownException(mock, XmlSignatureException.class, "The XAdES-EPES confguration is invalid. The digest value for the signature policy is missing.", null);
}
Also used : XAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties) DefaultXAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.DefaultXAdESSignatureProperties) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 2 with XAdESSignatureProperties

use of org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties in project camel by apache.

the class XAdESSignaturePropertiesTest method noSigningCertificate.

@Test
public void noSigningCertificate() throws Exception {
    XmlSignerEndpoint endpoint = getSignerEndpoint();
    XAdESSignatureProperties newProps = new XAdESSignatureProperties();
    newProps.setAddSigningTime(true);
    endpoint.setProperties(newProps);
    Document doc = testEnveloping();
    Map<String, String> prefix2Namespace = getPrefix2NamespaceMap();
    String pathToSignatureProperties = getPathToSignatureProperties();
    checkNode(doc, pathToSignatureProperties + "etsi:SigningTime", prefix2Namespace, true);
    checkNode(doc, pathToSignatureProperties + "etsi:SigningCertificate", prefix2Namespace, false);
}
Also used : XAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties) DefaultXAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.DefaultXAdESSignatureProperties) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 3 with XAdESSignatureProperties

use of org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties in project camel by apache.

the class XAdESSignaturePropertiesTest method prefixAndNamespace.

@Test
public void prefixAndNamespace() throws Exception {
    XmlSignerEndpoint endpoint = getSignerEndpoint();
    XAdESSignatureProperties props = (XAdESSignatureProperties) endpoint.getProperties();
    props.setPrefix("p");
    props.setNamespace(XAdESSignatureProperties.HTTP_URI_ETSI_ORG_01903_V1_1_1);
    props.setCommitmentTypeIdDescription(null);
    props.setCommitmentTypeIdDocumentationReferences(Collections.<String>emptyList());
    props.setCommitmentTypeIdQualifier(null);
    props.setDataObjectFormatIdentifierDescription(null);
    props.setDataObjectFormatIdentifierDocumentationReferences(Collections.<String>emptyList());
    props.setDataObjectFormatIdentifierQualifier(null);
    props.setSigPolicyIdDescription(null);
    props.setSigPolicyIdDocumentationReferences(Collections.<String>emptyList());
    props.setSigPolicyIdQualifier(null);
    // the following lists must be set to empty because otherwise they would contain XML fragments with a wrong namespace
    props.setSigPolicyQualifiers(Collections.<String>emptyList());
    props.setSignerClaimedRoles(Collections.<String>emptyList());
    props.setCommitmentTypeQualifiers(Collections.<String>emptyList());
    Document doc = testEnveloping();
    Map<String, String> prefix2Namespace = new TreeMap<String, String>();
    prefix2Namespace.put("ds", XMLSignature.XMLNS);
    prefix2Namespace.put("etsi", XAdESSignatureProperties.HTTP_URI_ETSI_ORG_01903_V1_1_1);
    XPathExpression expr = getXpath("/ds:Signature/ds:Object/etsi:QualifyingProperties", prefix2Namespace);
    Object result = expr.evaluate(doc, XPathConstants.NODE);
    assertNotNull(result);
    Node node = (Node) result;
    assertEquals("p", node.getPrefix());
    assertEquals(XAdESSignatureProperties.HTTP_URI_ETSI_ORG_01903_V1_1_1, node.getNamespaceURI());
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) XAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties) DefaultXAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.DefaultXAdESSignatureProperties) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 4 with XAdESSignatureProperties

use of org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties in project camel by apache.

the class XAdESSignaturePropertiesTest method headers.

@Test
public void headers() throws Exception {
    Map<String, Object> header = new TreeMap<String, Object>();
    header.put(XmlSignatureConstants.HEADER_XADES_PREFIX, "ns1");
    header.put(XmlSignatureConstants.HEADER_XADES_NAMESPACE, XAdESSignatureProperties.HTTP_URI_ETSI_ORG_01903_V1_2_2);
    header.put(XmlSignatureConstants.HEADER_XADES_QUALIFYING_PROPERTIES_ID, "QualId");
    header.put(XmlSignatureConstants.HEADER_XADES_SIGNED_DATA_OBJECT_PROPERTIES_ID, "ObjId");
    header.put(XmlSignatureConstants.HEADER_XADES_SIGNED_SIGNATURE_PROPERTIES_ID, "SigId");
    header.put(XmlSignatureConstants.HEADER_XADES_DATA_OBJECT_FORMAT_ENCODING, "base64");
    XmlSignerEndpoint endpoint = getSignerEndpoint();
    XAdESSignatureProperties props = (XAdESSignatureProperties) endpoint.getProperties();
    // the following lists must be set to empty because otherwise they would contain XML fragments with a wrong namespace
    props.setSigPolicyQualifiers(Collections.<String>emptyList());
    props.setSignerClaimedRoles(Collections.<String>emptyList());
    props.setCommitmentTypeQualifiers(Collections.<String>emptyList());
    Document doc = testEnveloping("direct:enveloping", header);
    Map<String, String> prefix2Namespace = new TreeMap<String, String>();
    prefix2Namespace.put("ds", XMLSignature.XMLNS);
    prefix2Namespace.put("etsi", XAdESSignatureProperties.HTTP_URI_ETSI_ORG_01903_V1_2_2);
    XPathExpression expr = getXpath("/ds:Signature/ds:Object/etsi:QualifyingProperties", prefix2Namespace);
    Object result = expr.evaluate(doc, XPathConstants.NODE);
    assertNotNull(result);
    Node node = (Node) result;
    assertEquals("ns1", node.getPrefix());
    assertEquals(XAdESSignatureProperties.HTTP_URI_ETSI_ORG_01903_V1_2_2, node.getNamespaceURI());
    checkXpath(doc, "/ds:Signature/ds:Object/etsi:QualifyingProperties/@Id", prefix2Namespace, "QualId");
    checkXpath(doc, "/ds:Signature/ds:Object/etsi:QualifyingProperties/etsi:SignedProperties/etsi:SignedDataObjectProperties/@Id", prefix2Namespace, "ObjId");
    checkXpath(doc, "/ds:Signature/ds:Object/etsi:QualifyingProperties/etsi:SignedProperties/etsi:SignedSignatureProperties/@Id", prefix2Namespace, "SigId");
    checkXpath(doc, "/ds:Signature/ds:Object/etsi:QualifyingProperties/etsi:SignedProperties/etsi:SignedDataObjectProperties/etsi:DataObjectFormat/etsi:Encoding/text()", prefix2Namespace, "base64");
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) XAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties) DefaultXAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.DefaultXAdESSignatureProperties) Node(org.w3c.dom.Node) TreeMap(java.util.TreeMap) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 5 with XAdESSignatureProperties

use of org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties in project camel by apache.

the class XAdESSignaturePropertiesTest method policyImplied.

@Test
public void policyImplied() throws Exception {
    XmlSignerEndpoint endpoint = getSignerEndpoint();
    XAdESSignatureProperties props = (XAdESSignatureProperties) endpoint.getProperties();
    props.setSignaturePolicy(XAdESSignatureProperties.SIG_POLICY_IMPLIED);
    Document doc = testEnveloping();
    String pathToSignatureProperties = getPathToSignatureProperties();
    checkNode(doc, pathToSignatureProperties + "etsi:SignaturePolicyIdentifier/etsi:SignaturePolicyId", getPrefix2NamespaceMap(), false);
    checkNode(doc, pathToSignatureProperties + "etsi:SignaturePolicyIdentifier/etsi:SignaturePolicyImplied", getPrefix2NamespaceMap(), true);
}
Also used : XAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties) DefaultXAdESSignatureProperties(org.apache.camel.component.xmlsecurity.api.DefaultXAdESSignatureProperties) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

DefaultXAdESSignatureProperties (org.apache.camel.component.xmlsecurity.api.DefaultXAdESSignatureProperties)15 XAdESSignatureProperties (org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties)15 Test (org.junit.Test)12 Document (org.w3c.dom.Document)8 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)7 TreeMap (java.util.TreeMap)2 XPathExpression (javax.xml.xpath.XPathExpression)2 Node (org.w3c.dom.Node)2