From 4b6ce58f339d69c70ef746ceecae78bf7ed0f0ba Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 2 Jul 2019 16:42:43 +0200 Subject: Handle tnvz Query Edge Cases by Improving Validation TnvzHelper Fixes - Handle additional edge cases. - Mzs:Schema Change: Eliminate PreAdviceNote redundancy by removing it from mzs:DeliveryRequest/TnvzMetaData; PreadviceNote is already in the Receiver element. Update TnvzHelper accordingly. - Implement and integrate tnvz completeness check into DeliveryRequestAugmenter to ensure that, after augmentation, tnvz can be performed. Refactor mzs:DeliveryRequest Validation: - Before: Validating, merging and generatig ConfigType in ConfigUtil. - Change: Need to add validation of DeliveryRequest (Reason: For performing Tnvz Requests, the DeliveryRequest needs to be in a consistent state). - Problem: DeliveryRequest validation does not fit into ConfigUtil. - Solution: Put validation of DeliveryRequest and Config into new Component "MzsValidation". --- .../moazs/preprocess/ConfigProfileGenerator.java | 17 ++++++-- .../at/gv/egiz/moazs/preprocess/ConfigUtil.java | 51 ---------------------- .../moazs/preprocess/DeliveryRequestAugmenter.java | 35 ++++++++++----- 3 files changed, 38 insertions(+), 65 deletions(-) (limited to 'src/main/java/at/gv/egiz/moazs/preprocess') diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java index fa1ccd6..c2f2415 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigProfileGenerator.java @@ -1,6 +1,7 @@ package at.gv.egiz.moazs.preprocess; import at.gv.egiz.moazs.MoaZSException; +import at.gv.egiz.moazs.mzs.MzsValidator; import at.gv.egiz.moazs.util.StringUtils; import at.gv.zustellung.app2mzs.xsd.ConfigType; import org.slf4j.Logger; @@ -29,6 +30,7 @@ public class ConfigProfileGenerator { private final SpringPropertiesFacade properties; private final ConfigUtil util; + private final MzsValidator validator; private final boolean verifyCompletenessOfDefaultConfiguration; private final String profilePrefix; private final String defaultConfigKey; @@ -40,11 +42,12 @@ public class ConfigProfileGenerator { private ConfigProfileGenerator( SpringPropertiesFacade properties, ConfigUtil util, - boolean verifyCompletenessOfDefaultConfiguration, + MzsValidator validator, boolean verifyCompletenessOfDefaultConfiguration, String profilePrefix, String defaultConfigKey) { this.util = util; this.properties = properties; + this.validator = validator; this.verifyCompletenessOfDefaultConfiguration = verifyCompletenessOfDefaultConfiguration; this.profilePrefix = profilePrefix; this.defaultConfigKey = defaultConfigKey; @@ -68,7 +71,7 @@ public class ConfigProfileGenerator { var defaultProfile = profiles.get(defaultConfigKey); - if (!util.isComplete(defaultProfile)) { + if (!validator.isConfigProfileComplete(defaultProfile)) { if (verifyCompletenessOfDefaultConfiguration) throw MoaZSException.moaZSException(PROFILE_NOT_COMPLETE_ERROR_MESSAGE); else { @@ -110,6 +113,7 @@ public class ConfigProfileGenerator { public static class ConfigProfileGeneratorBuilder { private SpringPropertiesFacade properties; private ConfigUtil util; + private MzsValidator validator; private boolean verify = true; private String profilePrefix = "delivery-request-configuration-profiles"; private String defaultConfigKey = "default"; @@ -124,6 +128,11 @@ public class ConfigProfileGenerator { return this; } + public ConfigProfileGeneratorBuilder withValidator(MzsValidator validator) { + this.validator = validator; + return this; + } + public ConfigProfileGeneratorBuilder withVerifyCompletenessOfDefaultConfiguration( boolean verify) { this.verify = verify; @@ -141,10 +150,10 @@ public class ConfigProfileGenerator { } public ConfigProfileGenerator build() { - if (properties == null || util == null || profilePrefix == null || defaultConfigKey == null) + if (properties == null || util == null || profilePrefix == null || defaultConfigKey == null || validator == null) throw new IllegalArgumentException("Cannot build ConfigProfileGenerator: " + "One or more arguments are null."); - return new ConfigProfileGenerator(properties, util, verify, profilePrefix, defaultConfigKey); + return new ConfigProfileGenerator(properties, util, validator, verify, profilePrefix, defaultConfigKey); } } } diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java index 6c9d264..68f833e 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java @@ -5,7 +5,6 @@ import at.gv.zustellung.app2mzs.xsd.ClientType; import at.gv.zustellung.app2mzs.xsd.ConfigType; import at.gv.zustellung.app2mzs.xsd.KeyStoreType; import at.gv.zustellung.app2mzs.xsd.SSLType; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; import java.math.BigInteger; @@ -215,54 +214,4 @@ public class ConfigUtil { } - /** - * Check if all mandatory fields are set. - * - * @param profile - * @return true if all mandatory fields are set - */ - public boolean isComplete(@Nullable ConfigType profile) { - return profile != null - && profile.isPerformQueryPersonRequest() != null - && isTVNZClientConfigured(profile.getTNVZClient(), profile.isPerformQueryPersonRequest()) - && isMSGClientConfigured(profile.getMSGClient()); - } - - private boolean isTVNZClientConfigured(ClientType tnvzClient, Boolean isPerformQueryPersonRequest) { - return !isPerformQueryPersonRequest || (tnvzClient != null - && tnvzClient.getURL() != null - && tnvzClient.getReceiveTimeout() != null - && tnvzClient.getConnectionTimeout() != null - && isSSLConfigured(tnvzClient)); - } - - private boolean isMSGClientConfigured(ClientType msgClientParams) { - return msgClientParams != null - && msgClientParams.getURL() != null - && isSSLConfigured(msgClientParams) - && msgClientParams.getReceiveTimeout() != null - && msgClientParams.getConnectionTimeout() != null; - } - - private boolean isSSLConfigured(ClientType clientParams) { - return !clientParams.getURL().startsWith("https") || (clientParams.getSSL() != null - && clientParams.getSSL().isTrustAll() != null - && clientParams.getSSL().isLaxHostNameVerification() != null - && isKeyStoreConfigured(clientParams.getSSL().getKeyStore()) - && isTrustStoreConfigured(clientParams.getSSL().getTrustStore())); - } - - private boolean isKeyStoreConfigured(KeyStoreType keyStore) { - return keyStore == null || (keyStore.getPassword() != null - && keyStore.getFileType() != null - && keyStore.getFileName() != null); - } - - private boolean isTrustStoreConfigured(KeyStoreType trustStore) { - return trustStore == null || (trustStore.getPassword() != null - && "JKS".equals(trustStore.getFileType()) - && trustStore.getFileName() != null); - } - - } diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java index aea01bb..37dbdc5 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/DeliveryRequestAugmenter.java @@ -1,5 +1,6 @@ package at.gv.egiz.moazs.preprocess; +import at.gv.egiz.moazs.mzs.MzsValidator; import at.gv.zustellung.app2mzs.xsd.ConfigType; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import org.springframework.beans.factory.annotation.Autowired; @@ -15,7 +16,10 @@ public class DeliveryRequestAugmenter { private final ConfigUtil util; private final Map configs; + private final MzsValidator validator; + private static final String INCOMPLETE_TNVZ_ERROR_MESSAGE = "mzs:DeliveryRequest is incomplete because mandatory " + + "fields for sending a tnvz:QueryPersonRequest are missing."; private static final String INCOMPLETE_CONFIG_ERROR_MESSAGE = "Could not find a profile for " + "the delivery request configuration, and the configuration attached to mzs:DeliveryRequest is incomplete."; private static final String INCOMPLETE_MERGED_CONFIG_ERROR_MESSAGE = "I merged parameters from " + @@ -23,9 +27,10 @@ public class DeliveryRequestAugmenter { "configuration is incomplete."; @Autowired - public DeliveryRequestAugmenter(Map deliveryRequestConfigs, ConfigUtil util) { + public DeliveryRequestAugmenter(Map deliveryRequestConfigs, ConfigUtil util, MzsValidator validator) { this.configs = deliveryRequestConfigs; this.util = util; + this.validator = validator; } /** @@ -33,7 +38,7 @@ public class DeliveryRequestAugmenter { * * @param request * @throws at.gv.egiz.moazs.MoaZSException - * @return augmented request + * @return augmented request and validated */ public DeliveryRequestType augment(DeliveryRequestType request) { @@ -43,10 +48,13 @@ public class DeliveryRequestAugmenter { if (fallbackConfig == null) { - if (util.isComplete(requestConfig)) - return request; - else + if (!validator.isConfigProfileComplete(request.getConfig())) { throw moaZSException(INCOMPLETE_CONFIG_ERROR_MESSAGE); + } else if (!validator.isTnvzComplete(request)) { + throw moaZSException(INCOMPLETE_TNVZ_ERROR_MESSAGE); + } else { + return request; + } } else { @@ -54,13 +62,20 @@ public class DeliveryRequestAugmenter { ? fallbackConfig : util.merge(requestConfig, fallbackConfig); - if (util.isComplete(mergedConfig)) { - return deliveryRequestTypeBuilder(request) - .withConfig(mergedConfig) - .build(); - } else { + if (!validator.isConfigProfileComplete(mergedConfig)) { throw moaZSException(INCOMPLETE_MERGED_CONFIG_ERROR_MESSAGE, fallbackProfileId); } + + var mergedRequest = deliveryRequestTypeBuilder(request) + .withConfig(mergedConfig) + .build(); + + if (!validator.isTnvzComplete(mergedRequest)) { + throw moaZSException(INCOMPLETE_TNVZ_ERROR_MESSAGE); + } + + return mergedRequest; + } } -- cgit v1.2.3