Search in sources :

Example 1 with LoggingValidationEventHandler

use of com.helger.jaxb.validation.LoggingValidationEventHandler in project peppol-commons by phax.

the class SignedServiceMetadataTypeFuncTest method testReadValid.

@Test
public void testReadValid() throws Exception {
    final SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(true);
    aMarshaller.setValidationEventHandlerFactory(x -> new LoggingValidationEventHandler());
    final byte[] aBytes = StreamHelper.getAllBytes(new ClassPathResource("smp/signed-service-metadata2.xml"));
    assertNotNull(aBytes);
    final SignedServiceMetadataType aSSM = aMarshaller.read(aBytes);
    assertNotNull(aSSM);
    final Document aDocument = DOMReader.readXMLDOM(aBytes);
    assertNotNull(aDocument);
    final TrustStoreBasedX509KeySelector aKeySelector = new TrustStoreBasedX509KeySelector(SMPClientConfiguration.loadTrustStore());
    // Certificate expired 2021-03-01
    aKeySelector.setValidationDateTime(PDTFactory.createLocalDateTime(2021, Month.JANUARY, 1));
    final ESuccess eSuccess = SMPHttpResponseHandlerSigned.checkSignature(aDocument, aKeySelector);
    assertTrue(eSuccess.isSuccess());
}
Also used : ESuccess(com.helger.commons.state.ESuccess) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) TrustStoreBasedX509KeySelector(com.helger.smpclient.security.TrustStoreBasedX509KeySelector) LoggingValidationEventHandler(com.helger.jaxb.validation.LoggingValidationEventHandler) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) Test(org.junit.Test)

Example 2 with LoggingValidationEventHandler

use of com.helger.jaxb.validation.LoggingValidationEventHandler in project peppol-commons by phax.

the class SignedServiceMetadataTypeFuncTest method testReadC14NInclusive.

@Test
public void testReadC14NInclusive() throws Exception {
    final SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(true);
    aMarshaller.setValidationEventHandlerFactory(x -> new LoggingValidationEventHandler());
    final byte[] aBytes = StreamHelper.getAllBytes(new ClassPathResource("smp/signed-service-metadata3-c14n-inclusive.xml"));
    assertNotNull(aBytes);
    final SignedServiceMetadataType aSSM = aMarshaller.read(aBytes);
    assertNotNull(aSSM);
    final Document aDocument = DOMReader.readXMLDOM(aBytes);
    assertNotNull(aDocument);
    final TrustStoreBasedX509KeySelector aKeySelector = new TrustStoreBasedX509KeySelector(SMPClientConfiguration.loadTrustStore());
    // Certificate expired 2020-08-05
    aKeySelector.setValidationDateTime(PDTFactory.createLocalDateTime(2020, Month.AUGUST, 1));
    final ESuccess eSuccess = SMPHttpResponseHandlerSigned.checkSignature(aDocument, aKeySelector);
    assertTrue(eSuccess.isSuccess());
}
Also used : ESuccess(com.helger.commons.state.ESuccess) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) TrustStoreBasedX509KeySelector(com.helger.smpclient.security.TrustStoreBasedX509KeySelector) LoggingValidationEventHandler(com.helger.jaxb.validation.LoggingValidationEventHandler) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) Test(org.junit.Test)

Example 3 with LoggingValidationEventHandler

use of com.helger.jaxb.validation.LoggingValidationEventHandler in project peppol-commons by phax.

the class SignedServiceMetadataTypeFuncTest method testReadInvalid.

@Test
public void testReadInvalid() throws Exception {
    final SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(true);
    aMarshaller.setValidationEventHandlerFactory(x -> new LoggingValidationEventHandler());
    final byte[] aBytes = StreamHelper.getAllBytes(new ClassPathResource("smp/signed-service-metadata1.xml"));
    assertNotNull(aBytes);
    final SignedServiceMetadataType aSSM = aMarshaller.read(aBytes);
    assertNotNull(aSSM);
    final Document aDocument = DOMReader.readXMLDOM(aBytes);
    assertNotNull(aDocument);
    final TrustStoreBasedX509KeySelector aKeySelector = new TrustStoreBasedX509KeySelector(SMPClientConfiguration.loadTrustStore());
    // Certificate expired 2021-03-01
    aKeySelector.setValidationDateTime(PDTFactory.createLocalDateTime(2021, Month.JANUARY, 1));
    final ESuccess eSuccess = SMPHttpResponseHandlerSigned.checkSignature(aDocument, aKeySelector);
    assertTrue(eSuccess.isFailure());
}
Also used : ESuccess(com.helger.commons.state.ESuccess) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) TrustStoreBasedX509KeySelector(com.helger.smpclient.security.TrustStoreBasedX509KeySelector) LoggingValidationEventHandler(com.helger.jaxb.validation.LoggingValidationEventHandler) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) Test(org.junit.Test)

Aggregations

ClassPathResource (com.helger.commons.io.resource.ClassPathResource)3 ESuccess (com.helger.commons.state.ESuccess)3 LoggingValidationEventHandler (com.helger.jaxb.validation.LoggingValidationEventHandler)3 SMPMarshallerSignedServiceMetadataType (com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType)3 TrustStoreBasedX509KeySelector (com.helger.smpclient.security.TrustStoreBasedX509KeySelector)3 SignedServiceMetadataType (com.helger.xsds.peppol.smp1.SignedServiceMetadataType)3 Test (org.junit.Test)3 Document (org.w3c.dom.Document)3