diff options
18 files changed, 114 insertions, 158 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/process/SingleThreadedDeliveryPipeline.java b/src/main/java/at/gv/egiz/moazs/backend/DeliveryRequestBackend.java index 445f386..06eba80 100644 --- a/src/main/java/at/gv/egiz/moazs/process/SingleThreadedDeliveryPipeline.java +++ b/src/main/java/at/gv/egiz/moazs/backend/DeliveryRequestBackend.java @@ -1,4 +1,4 @@ -package at.gv.egiz.moazs.process; +package at.gv.egiz.moazs.backend; import at.gv.egiz.moazs.MoaZSException; @@ -7,8 +7,6 @@ import at.gv.egiz.moazs.client.TnvzHelper; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.Mzs2MsgConverter; import at.gv.egiz.moazs.scheme.RequestStatusResponse; -import at.gv.egiz.moazs.verify.MsgResponseVerifier; -import at.gv.egiz.moazs.verify.SignatureVerifier; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import at.gv.zustellung.msg.xsd.App2ZusePort; import at.gv.zustellung.tnvz.xsd.TNVZServicePort; @@ -17,15 +15,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; +import java.util.function.Consumer; + import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder; import static at.gv.egiz.moazs.scheme.RequestStatusResponse.generateErrorFromException; import static java.lang.String.format; @Component @Profile("!cluster") -public class SingleThreadedDeliveryPipeline implements DeliveryPipeline { +public class DeliveryRequestBackend implements Consumer<String> { - private static final Logger log = Logger.getLogger(SingleThreadedDeliveryPipeline.class); + private static final Logger log = Logger.getLogger(DeliveryRequestBackend.class); private static final String MZS_PIPELINE_ERROR_MSG = "An error occured while processing the DeliveryRequest with AppDeliveryID=%s. "; @@ -33,23 +33,32 @@ public class SingleThreadedDeliveryPipeline implements DeliveryPipeline { private final TnvzHelper tnvzHelper; private final Mzs2MsgConverter converter; private final ClientFactory clientFactory; - private final SignatureVerifier verifier; + private final Consumer<byte[]> signatureVerifier; @Autowired - public SingleThreadedDeliveryPipeline(DeliveryRepository repository, - TnvzHelper tnvzHelper, - Mzs2MsgConverter converter, - ClientFactory clientFactory, - SignatureVerifier verifier) { + public DeliveryRequestBackend(DeliveryRepository repository, + TnvzHelper tnvzHelper, + Mzs2MsgConverter converter, + ClientFactory clientFactory, + Consumer<byte[]> signatureVerifier) { this.repository = repository; this.tnvzHelper = tnvzHelper; this.converter = converter; this.clientFactory = clientFactory; - this.verifier = verifier; + this.signatureVerifier = signatureVerifier; } + /** + * Performs all {@code DeliveryRequest}'s Back-End Tasks. + * + * Fetches {@code DeliveryRequest} referred by appDeliveryID from + * {@code DeliveryRepository}, makes sure that all necessary + * tasks (query tnvz, query msg, accept status) are executed and + * stores the response back to {@code DeliveryRepository}. + * @param appDeliveryID + */ @Override - public void processRequest(String appDeliveryID) { + public void accept(String appDeliveryID) { var exceptionBuilder = moaZSExceptionBuilder(); @@ -79,9 +88,9 @@ public class SingleThreadedDeliveryPipeline implements DeliveryPipeline { private void verifySignedStatus(String responseID, String appDeliveryID, MoaZSException.Builder exceptionBuilder) throws MoaZSException { try { var signedStatus = repository.retrieveBinaryResponse(responseID).get(); - verifier.verify(signedStatus); + signatureVerifier.accept(signedStatus); } catch (MoaZSException ex) { - throw exceptionBuilder.withMessage(format(MsgResponseVerifier.MOASP_SIGNATURE_INVALID_ERROR_MSG, appDeliveryID)) + throw exceptionBuilder.withMessage(format(MsgResponseBackend.MOASP_SIGNATURE_INVALID_ERROR_MSG, appDeliveryID)) .withErrorCode(MoaZSException.ERROR_MOASP_SIGNATURE_INVALID) .withCause(ex) .build(); diff --git a/src/main/java/at/gv/egiz/moazs/verify/MsgResponseVerifier.java b/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java index 9c8b17c..414c2dc 100644 --- a/src/main/java/at/gv/egiz/moazs/verify/MsgResponseVerifier.java +++ b/src/main/java/at/gv/egiz/moazs/backend/MsgResponseBackend.java @@ -1,4 +1,4 @@ -package at.gv.egiz.moazs.verify; +package at.gv.egiz.moazs.backend; import at.gv.egiz.moazs.MoaZSException; import at.gv.egiz.moazs.repository.DeliveryRepository; @@ -9,23 +9,44 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; +import java.util.function.Function; + import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder; import static java.lang.String.format; +import static java.util.concurrent.CompletableFuture.supplyAsync; @Component -public class MsgResponseVerifier { +public class MsgResponseBackend implements Consumer<String> { private static final Logger log = LoggerFactory.getLogger(MsgService.class); + public static final String MOASP_SIGNATURE_INVALID_ERROR_MSG = "Signature of Msg Response " + "with AppDeliveryID=%s is not valid."; private final DeliveryRepository repository; - private final SignatureVerifier verifier; + private final Consumer<byte[]> signatureVerifier; + private final Function<MsgResponse, CompletableFuture<Void>> sink; @Autowired - public MsgResponseVerifier(DeliveryRepository repository, SignatureVerifier verifier) { + public MsgResponseBackend(DeliveryRepository repository, + Consumer<byte[]> signatureVerifier, + Function<MsgResponse, CompletableFuture<Void>> sink) { this.repository = repository; - this.verifier = verifier; + this.signatureVerifier = signatureVerifier; + this.sink = sink; + } + + /** + * Performs all {@code MsgResponse}'s Back-End Tasks, such as verifying + * its signature and archiving the response. + * + * @param responseID refers to MsgResponse Object. + */ + @Override + public void accept(String responseID) { + supplyAsync(() -> verify(responseID)).thenAcceptAsync(sink::apply); } public MsgResponse verify(String responseID) { @@ -36,7 +57,7 @@ public class MsgResponseVerifier { var binaryResponse = repository.retrieveBinaryResponse(responseID).get(); try { - verifier.verify(binaryResponse); + signatureVerifier.accept(binaryResponse); return response; } catch (MoaZSException ex) { log.error(ex.getMessage(), ex); diff --git a/src/main/java/at/gv/egiz/moazs/process/SaveResponseToFileSink.java b/src/main/java/at/gv/egiz/moazs/backend/SaveResponseToFileSink.java index 09d8570..02771a9 100644 --- a/src/main/java/at/gv/egiz/moazs/process/SaveResponseToFileSink.java +++ b/src/main/java/at/gv/egiz/moazs/backend/SaveResponseToFileSink.java @@ -1,4 +1,4 @@ -package at.gv.egiz.moazs.process; +package at.gv.egiz.moazs.backend; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.Marshaller; @@ -15,6 +15,7 @@ import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.CompletableFuture; +import java.util.function.Function; import static at.gv.egiz.moazs.MoaZSException.moaZSException; import static java.lang.String.format; @@ -22,7 +23,7 @@ import static java.util.concurrent.CompletableFuture.allOf; import static java.util.concurrent.CompletableFuture.supplyAsync; @Component -public class SaveResponseToFileSink implements MsgResponseSink { +public class SaveResponseToFileSink implements Function<MsgResponse, CompletableFuture<Void>> { private static final Logger log = LoggerFactory.getLogger(SaveResponseToFileSink.class); private static final String SAVING_FAILED_MSG = "Could not save response with AppDeliveryId=%s."; @@ -41,7 +42,7 @@ public class SaveResponseToFileSink implements MsgResponseSink { } @Override - public CompletableFuture<Void> handle(MsgResponse response) { + public CompletableFuture<Void> apply(MsgResponse response) { var responseID = response.getResponseID(); @@ -84,4 +85,5 @@ public class SaveResponseToFileSink implements MsgResponseSink { throw moaZSException(e.getMessage(), e); } } + } diff --git a/src/main/java/at/gv/egiz/moazs/verify/MoaSPSSSignatureVerifier.java b/src/main/java/at/gv/egiz/moazs/backend/SignatureVerifier.java index 5220c3b..e9c5387 100644 --- a/src/main/java/at/gv/egiz/moazs/verify/MoaSPSSSignatureVerifier.java +++ b/src/main/java/at/gv/egiz/moazs/backend/SignatureVerifier.java @@ -1,4 +1,4 @@ -package at.gv.egiz.moazs.verify; +package at.gv.egiz.moazs.backend; import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.api.ISignatureVerificationService; import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.api.data.IXMLSignatureVerificationResponse; @@ -6,31 +6,36 @@ import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.exceptions.MOASigServ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.function.Consumer; + import static at.gv.egiz.moazs.MoaZSException.moaZSException; import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder; -import static java.lang.String.*; +import static java.lang.String.format; -public class MoaSPSSSignatureVerifier implements SignatureVerifier { +public class SignatureVerifier implements Consumer<byte[]> { - private static final Logger log = LoggerFactory.getLogger(MoaSPSSSignatureVerifier.class); + private static final Logger log = LoggerFactory.getLogger(SignatureVerifier.class); + private static final int OK_CODE = 0; private final ISignatureVerificationService service; - private final String trustProfile; - private final boolean isManifestCheckActive; - private static final int OK_CODE = 0; - - public MoaSPSSSignatureVerifier(ISignatureVerificationService service, + public SignatureVerifier(ISignatureVerificationService service, String trustProfile, boolean isManifestCheckActive) { this.service = service; this.trustProfile = trustProfile; this.isManifestCheckActive = isManifestCheckActive; } + /** + * Verifies the signature of a signed XML document. Throws a at.gv.egiz.moazs.MoaZSException exception + * if the validation fails. + * @param signedXMLdocument + * @throws at.gv.egiz.moazs.MoaZSException + */ @Override - public void verify(byte[] signedXMLdocument) { + public void accept(byte[] signedXMLdocument) { try { var response = service.verifyXMLSignature(signedXMLdocument, trustProfile); @@ -82,7 +87,7 @@ public class MoaSPSSSignatureVerifier implements SignatureVerifier { } } catch (MOASigServiceException e) { - throw moaZSExceptionBuilder("Could not verify the XML signature.") + throw moaZSExceptionBuilder("Could not accept the XML signature.") .withCause(e) .build(); } diff --git a/src/main/java/at/gv/egiz/moazs/config/MoaSigConfig.java b/src/main/java/at/gv/egiz/moazs/config/MoaSigConfig.java index 0b7bdc7..e02c11d 100644 --- a/src/main/java/at/gv/egiz/moazs/config/MoaSigConfig.java +++ b/src/main/java/at/gv/egiz/moazs/config/MoaSigConfig.java @@ -3,8 +3,7 @@ package at.gv.egiz.moazs.config; import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.api.ISignatureVerificationService; import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.impl.SignatureVerificationService; import at.gv.egiz.moazs.util.FileUtils; -import at.gv.egiz.moazs.verify.MoaSPSSSignatureVerifier; -import at.gv.egiz.moazs.verify.SignatureVerifier; +import at.gv.egiz.moazs.backend.SignatureVerifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -14,6 +13,7 @@ import org.springframework.context.annotation.Configuration; import java.io.File; import java.io.FileNotFoundException; +import java.util.function.Consumer; @Configuration @@ -62,8 +62,6 @@ public class MoaSigConfig { } } - - private void fallBackToSpringEnvForJavaxNetSSLStoreTypeProperty() { if (System.getProperty(JAVAX_SSL_TRUSTSTORE_TYPE_PROPERTY) == null) { log.info(SET_PROPERTY_MSG_TEMPLATE, JAVAX_SSL_TRUSTSTORE_TYPE_PROPERTY, trustStoreType); @@ -87,11 +85,11 @@ public class MoaSigConfig { } @Bean - public SignatureVerifier signatureVerifier(@Value("${moa.spss.is-active}") boolean isMoaSPSSActive, - @Value("${moa.spss.is-manifest-check-active}") boolean isManifestCheckActive) { + public Consumer<byte[]> signatureVerifier(@Value("${moa.spss.is-active}") boolean isMoaSPSSActive, + @Value("${moa.spss.is-manifest-check-active}") boolean isManifestCheckActive) { if (isMoaSPSSActive) { log.info("Moa SPSS is active. Signatures in SOAP Messages will be verified."); - return new MoaSPSSSignatureVerifier(moaSigVerifyService(), defaultTrustProfile, isManifestCheckActive); + return new SignatureVerifier(moaSigVerifyService(), defaultTrustProfile, isManifestCheckActive); } else { log.warn("Moa SPSS is not active. Signatures in SOAP Messages will not be verified."); return signedXMLdocument -> {}; diff --git a/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java b/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java index 76bfb30..29797dd 100644 --- a/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java +++ b/src/main/java/at/gv/egiz/moazs/config/PreprocessConfig.java @@ -21,15 +21,14 @@ public class PreprocessConfig { return generator.generate(); } - @Value("${verify-completeness-of-default-delivery-request-configuration:true}") - private boolean verifyCompletenessOfDefaultConfiguration; - @Bean @Autowired public ConfigProfileGenerator configProfileGenerator( SpringPropertiesFacade properties, MzsDeliveryRequestValidator validator, - ConfigUtil util) { + ConfigUtil util, + @Value("${verify-completeness-of-default-delivery-request-configuration:true}") + boolean verifyCompletenessOfDefaultConfiguration) { return configProfileGeneratorBuilder() .withProperties(properties) diff --git a/src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java b/src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java index 42019b1..c16dfd2 100644 --- a/src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java +++ b/src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java @@ -38,7 +38,8 @@ public class ServicesConfig { return new Zuse2AppPortService(); } - @Bean public App2Mzs app2mzs() { + @Bean + public App2Mzs app2mzs() { return new App2Mzs(); } diff --git a/src/main/java/at/gv/egiz/moazs/process/DeliveryPipeline.java b/src/main/java/at/gv/egiz/moazs/process/DeliveryPipeline.java deleted file mode 100644 index 506dd1f..0000000 --- a/src/main/java/at/gv/egiz/moazs/process/DeliveryPipeline.java +++ /dev/null @@ -1,17 +0,0 @@ -package at.gv.egiz.moazs.process; - - -public interface DeliveryPipeline { - - /** - * Performs all {@code DeliveryRequest}'s Back-End Tasks. - * - * Fetches {@code DeliveryRequest} referred by appDeliveryId from - * {@code DeliveryRepository}, makes sure that all necessary - * tasks (query tnvz, query msg, verify status) are executed and - * stores the response back to {@code DeliveryRepository}. - * @param appDeliveryId - */ - void processRequest(String appDeliveryId); - -} diff --git a/src/main/java/at/gv/egiz/moazs/process/MsgResponseHandler.java b/src/main/java/at/gv/egiz/moazs/process/MsgResponseHandler.java deleted file mode 100644 index 5a7d39b..0000000 --- a/src/main/java/at/gv/egiz/moazs/process/MsgResponseHandler.java +++ /dev/null @@ -1,7 +0,0 @@ -package at.gv.egiz.moazs.process; - -public interface MsgResponseHandler { - - void handle(String id); - -} diff --git a/src/main/java/at/gv/egiz/moazs/process/MsgResponseSink.java b/src/main/java/at/gv/egiz/moazs/process/MsgResponseSink.java deleted file mode 100644 index 67348fc..0000000 --- a/src/main/java/at/gv/egiz/moazs/process/MsgResponseSink.java +++ /dev/null @@ -1,11 +0,0 @@ -package at.gv.egiz.moazs.process; - -import at.gv.egiz.moazs.scheme.MsgResponse; - -import java.util.concurrent.CompletableFuture; - -public interface MsgResponseSink { - - CompletableFuture<Void> handle(MsgResponse response); - -} diff --git a/src/main/java/at/gv/egiz/moazs/process/SingleNodeResponseHandler.java b/src/main/java/at/gv/egiz/moazs/process/SingleNodeResponseHandler.java deleted file mode 100644 index 65f5eed..0000000 --- a/src/main/java/at/gv/egiz/moazs/process/SingleNodeResponseHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -package at.gv.egiz.moazs.process; - -import at.gv.egiz.moazs.verify.MsgResponseVerifier; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import static java.util.concurrent.CompletableFuture.supplyAsync; - -@Component -public class SingleNodeResponseHandler implements MsgResponseHandler { - - private final MsgResponseVerifier verifier; - private final MsgResponseSink sink; - - @Autowired - public SingleNodeResponseHandler(MsgResponseVerifier verifier, MsgResponseSink sink) { - this.verifier = verifier; - this.sink = sink; - } - - @Override - public void handle(String responseID) { - supplyAsync(() -> verifier.verify(responseID)) - .thenAcceptAsync(response -> sink.handle(response)); - } -} diff --git a/src/main/java/at/gv/egiz/moazs/service/MsgService.java b/src/main/java/at/gv/egiz/moazs/service/MsgService.java index 87644a0..9f94cb3 100644 --- a/src/main/java/at/gv/egiz/moazs/service/MsgService.java +++ b/src/main/java/at/gv/egiz/moazs/service/MsgService.java @@ -1,5 +1,4 @@ package at.gv.egiz.moazs.service; -import at.gv.egiz.moazs.process.MsgResponseHandler; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.MsgResponse; import at.gv.egiz.moazs.scheme.NameSpace; @@ -10,6 +9,8 @@ import org.apache.cxf.annotations.SchemaValidation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.function.Consumer; + import static at.gv.zustellung.msg.xsd.DeliveryNotificationACKType.deliveryNotificationACKTypeBuilder; import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusACKType.deliveryRequestStatusACKTypeBuilder; import static at.gv.zustellung.msg.xsd.GetVersionResponse.getVersionResponseBuilder; @@ -20,12 +21,12 @@ import static java.util.concurrent.CompletableFuture.runAsync; public class MsgService implements Zuse2AppPort { private final DeliveryRepository repository; - private final MsgResponseHandler handler; + private final Consumer<String> backend; @Autowired - public MsgService(DeliveryRepository repository, MsgResponseHandler handler) { + public MsgService(DeliveryRepository repository, Consumer<String> msgResponseBackend) { this.repository = repository; - this.handler = handler; + this.backend = msgResponseBackend; } @Override @@ -59,7 +60,7 @@ public class MsgService implements Zuse2AppPort { private void sendToWork(MsgResponse response) { runAsync(() -> repository.store(response)) - .thenRunAsync(() -> handler.handle(response.getResponseID())); + .thenRunAsync(() -> backend.accept(response.getResponseID())); } private DeliveryNotificationACKType notificationAck(String appDeliveryID, String zsDeliveryID) { diff --git a/src/main/java/at/gv/egiz/moazs/service/MzsService.java b/src/main/java/at/gv/egiz/moazs/service/MzsService.java index 2755a37..c8c0878 100644 --- a/src/main/java/at/gv/egiz/moazs/service/MzsService.java +++ b/src/main/java/at/gv/egiz/moazs/service/MzsService.java @@ -1,7 +1,6 @@ package at.gv.egiz.moazs.service; import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter; -import at.gv.egiz.moazs.process.DeliveryPipeline; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.Msg2MzsConverter; import at.gv.egiz.moazs.client.MzsClient; @@ -19,6 +18,7 @@ import org.springframework.stereotype.Service; import javax.jws.WebParam; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.function.Consumer; import static at.gv.egiz.moazs.MoaZSException.moaZSException; import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder; @@ -36,16 +36,16 @@ public class MzsService implements App2MzsPortType { private static final int TIMEOUT_FOR_ANWSER = 10; private final DeliveryRepository repository; - private final DeliveryPipeline pipeline; + private final Consumer<String> backend; private final MzsClient appClient; private final DeliveryRequestAugmenter augmenter; private final Msg2MzsConverter converter; @Autowired - public MzsService(DeliveryRepository repository, DeliveryPipeline pipeline, MzsClient appClient, + public MzsService(DeliveryRepository repository, Consumer<String> deliveryRequestBackend, MzsClient appClient, DeliveryRequestAugmenter augmenter, Msg2MzsConverter converter) { this.repository = repository; - this.pipeline = pipeline; + this.backend = deliveryRequestBackend; this.appClient = appClient; this.augmenter = augmenter; this.converter = converter; @@ -87,7 +87,7 @@ public class MzsService implements App2MzsPortType { logger.info("Receive request with appDeliveryID = {}.", appDeliveryID); repository.store(deliveryRequest); - pipeline.processRequest(appDeliveryID); + backend.accept(appDeliveryID); var statusId = RequestStatusResponse.getResponseID(appDeliveryID); var response = repository.retrieveResponse(statusId) diff --git a/src/main/java/at/gv/egiz/moazs/verify/SignatureVerifier.java b/src/main/java/at/gv/egiz/moazs/verify/SignatureVerifier.java deleted file mode 100644 index a31c4cf..0000000 --- a/src/main/java/at/gv/egiz/moazs/verify/SignatureVerifier.java +++ /dev/null @@ -1,13 +0,0 @@ -package at.gv.egiz.moazs.verify; - -@FunctionalInterface -public interface SignatureVerifier { - - /** - * Verifies the signature of a signed XML document. Throws a at.gv.egiz.moazs.MoaZSException exception - * if the validation fails. - * @param signedXMLdocument - * @throws at.gv.egiz.moazs.MoaZSException - */ - void verify(byte[] signedXMLdocument); -} diff --git a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java index e245eb1..ed63489 100644 --- a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java +++ b/src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java @@ -1,13 +1,12 @@ package at.gv.egiz.moazs; -import at.gv.egiz.moazs.process.DeliveryPipeline; -import at.gv.egiz.moazs.process.SingleThreadedDeliveryPipeline; -import at.gv.egiz.moazs.client.TnvzHelper; -import at.gv.egiz.moazs.scheme.*; import at.gv.egiz.moazs.client.ClientFactory; +import at.gv.egiz.moazs.client.TnvzHelper; +import at.gv.egiz.moazs.backend.DeliveryRequestBackend; +import at.gv.egiz.moazs.backend.SignatureVerifier; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.repository.InMemoryDeliveryRepository; -import at.gv.egiz.moazs.verify.MoaSPSSSignatureVerifier; +import at.gv.egiz.moazs.scheme.Mzs2MsgConverter; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import at.gv.zustellung.msg.xsd.App2ZusePort; import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; @@ -35,7 +34,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) -public class SingleThreadedDeliveryPipelineTest { +public class DeliveryRequestBackendTest { private DeliveryRepository repository = new InMemoryDeliveryRepository(100); @@ -55,14 +54,14 @@ public class SingleThreadedDeliveryPipelineTest { private Mzs2MsgConverter converter; @Mock - private MoaSPSSSignatureVerifier verifier; + private SignatureVerifier verifier; - private DeliveryPipeline pipeline; + private DeliveryRequestBackend pipeline; @Before public void setup() { - pipeline = new SingleThreadedDeliveryPipeline( + pipeline = new DeliveryRequestBackend( repository, tnvzHelper, converter, @@ -75,7 +74,7 @@ public class SingleThreadedDeliveryPipelineTest { var appDeliveryID = "no-tnvz-request"; var expectedStatus = setupMocks(appDeliveryID, false); - pipeline.processRequest(appDeliveryID); + pipeline.accept(appDeliveryID); verifyZeroInteractions(tnvzHelper); var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get(); @@ -91,7 +90,7 @@ public class SingleThreadedDeliveryPipelineTest { when(tnvzHelper.performQueryPersonRequest(any(), any(), any())) .thenThrow(buildMzsException("400", appDeliveryID)); - pipeline.processRequest(appDeliveryID); + pipeline.accept(appDeliveryID); var responseID = getResponseID(appDeliveryID); var response = repository.retrieveResponse(responseID).get(); @@ -108,7 +107,7 @@ public class SingleThreadedDeliveryPipelineTest { var appDeliveryID = "tnvz-request"; var expectedStatus = setupMocks(appDeliveryID, true); - pipeline.processRequest(appDeliveryID); + pipeline.accept(appDeliveryID); var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get(); var actualStatus = (DeliveryRequestStatusType) response.getResponse(); @@ -119,9 +118,9 @@ public class SingleThreadedDeliveryPipelineTest { public void rejectInvalidSignature() { var appDeliveryID = "invalid-signature"; setupMocks(appDeliveryID, true); - doThrow(moaZSException("Signature Invalid!")).when(verifier).verify(any()); + doThrow(moaZSException("Signature Invalid!")).when(verifier).accept(any()); - pipeline.processRequest(appDeliveryID); + pipeline.accept(appDeliveryID); var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get(); var status = (DeliveryRequestStatusType) response.getResponse(); var actualCode = status.getError().getErrorInfo().getCode(); diff --git a/src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java b/src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java index 2c6b978..34f4e1b 100644 --- a/src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java +++ b/src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java @@ -1,8 +1,7 @@ package at.gv.egiz.moazs; import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.api.ISignatureVerificationService; -import at.gv.egiz.moazs.verify.MoaSPSSSignatureVerifier; -import at.gv.egiz.moazs.verify.SignatureVerifier; +import at.gv.egiz.moazs.backend.SignatureVerifier; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +26,7 @@ import java.nio.file.Files; @Bean public SignatureVerifier verifier(@Autowired ISignatureVerificationService service){ - return new MoaSPSSSignatureVerifier(service, "test-trust-profile", true); + return new SignatureVerifier(service, "test-trust-profile", true); } } @@ -41,7 +40,7 @@ import java.nio.file.Files; var path = resourcesPath + "valid-signed-delivery-response.xml"; var signature = Files.readAllBytes(new File(path).toPath()); - verifier.verify(signature); + verifier.accept(signature); } @Test(expected = MoaZSException.class) @@ -50,7 +49,7 @@ import java.nio.file.Files; var path = resourcesPath + "invalid-signed-delivery-response.xml"; var signature = Files.readAllBytes(new File(path).toPath()); - verifier.verify(signature); + verifier.accept(signature); } } diff --git a/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java index a93c720..e9b4f70 100644 --- a/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java +++ b/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java @@ -1,12 +1,9 @@ package at.gv.egiz.moazs; -import at.gv.egiz.moazs.process.DeliveryPipeline; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.RequestStatusResponse; import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -25,6 +22,7 @@ import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.file.Paths; import java.util.GregorianCalendar; +import java.util.function.Consumer; import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Success.successBuilder; import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder; @@ -40,8 +38,6 @@ public class ITMzsServiceTest { private final String basePath = "src/test/resources/at/gv/egiz/moazs/ITMzsServiceTest/"; - private final static Logger logger = LoggerFactory.getLogger(ITMzsServiceTest.class); - @TestConfiguration public static class TestConfig { @@ -50,7 +46,7 @@ public class ITMzsServiceTest { @Bean @Primary - public DeliveryPipeline deliveryPipelineThatAlwaysSucceeds() { + public Consumer<String> deliveryPipelineThatAlwaysSucceeds() { return appDeliveryId -> { var success = successBuilder() diff --git a/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java b/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java index ca501c8..9ddd37e 100644 --- a/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java +++ b/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java @@ -1,6 +1,6 @@ package at.gv.egiz.moazs; -import at.gv.egiz.moazs.process.SaveResponseToFileSink; +import at.gv.egiz.moazs.backend.SaveResponseToFileSink; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.Marshaller; import at.gv.egiz.moazs.scheme.RequestStatusResponse; @@ -63,7 +63,7 @@ public class SaveResponseToFileSinkTest { var fileContent = "<xml>some content</xml>"; var status = setupMocks(fileContent); - sink.handle(status) + sink.apply(status) .thenRun(() -> assertFilesCreatedAndContentMatches(fileContent)); } |