From afffefdf7ed41007071639ac204f7df368995e29 Mon Sep 17 00:00:00 2001 From: Philip Helger Date: Tue, 31 Oct 2023 23:09:15 +0100 Subject: [PATCH] Some #187 follow-up --- .../bdew/BDEWCompatibilityValidator.java | 71 ++++++++++--------- .../helger/phase4/profile/bdew/BDEWPMode.java | 25 +++++-- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/phase4-profile-bdew/src/main/java/com/helger/phase4/profile/bdew/BDEWCompatibilityValidator.java b/phase4-profile-bdew/src/main/java/com/helger/phase4/profile/bdew/BDEWCompatibilityValidator.java index f0b0624c1..41cec349f 100644 --- a/phase4-profile-bdew/src/main/java/com/helger/phase4/profile/bdew/BDEWCompatibilityValidator.java +++ b/phase4-profile-bdew/src/main/java/com/helger/phase4/profile/bdew/BDEWCompatibilityValidator.java @@ -16,6 +16,16 @@ */ package com.helger.phase4.profile.bdew; +import java.security.cert.X509Certificate; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import org.bouncycastle.asn1.x500.RDN; +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.asn1.x500.style.BCStyle; +import org.bouncycastle.asn1.x500.style.IETFUtils; + import com.helger.commons.ValueEnforcer; import com.helger.commons.annotation.Nonempty; import com.helger.commons.error.IError; @@ -52,14 +62,6 @@ import com.helger.phase4.profile.IAS4ProfileValidator; import com.helger.phase4.soap.ESoapVersion; import com.helger.phase4.wss.EWSSVersion; -import org.bouncycastle.asn1.x500.RDN; -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x500.style.BCStyle; -import org.bouncycastle.asn1.x500.style.IETFUtils; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.security.cert.X509Certificate; /** * Validate certain requirements imposed by the BDEW project. @@ -118,21 +120,21 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList, aErrorList.add (_createError (sFieldPrefix + "AddressProtocol is missing")); } - final PModeLegBusinessInformation aBusinessInfo = aPModeLeg.getBusinessInfo(); + final PModeLegBusinessInformation aBusinessInfo = aPModeLeg.getBusinessInfo (); if (aBusinessInfo == null) { - aErrorList.add (_createError ("BusinessInfo is missing")); + aErrorList.add (_createError (sFieldPrefix + "BusinessInfo is missing")); } else { - String sService = aBusinessInfo.getService(); - if (sService == null || !BDEWPMode.getServices ().contains (sService)) + final String sService = aBusinessInfo.getService (); + if (sService == null || !BDEWPMode.containsService (sService)) { aErrorList.add (_createError (sFieldPrefix + "BusinessInfo.Service '" + sService + "' is unsupported")); } - String sAction = aBusinessInfo.getAction (); - if (sAction == null || !BDEWPMode.getActions ().contains (sAction)) + final String sAction = aBusinessInfo.getAction (); + if (sAction == null || !BDEWPMode.containsAction (sAction)) { aErrorList.add (_createError (sFieldPrefix + "BusinessInfo.Action '" + sAction + "' is unsupported")); } @@ -194,20 +196,22 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList, } else { - if (!aPModeLegSecurity.getX509EncryptionAlgorithm().equals(ECryptoAlgorithmCrypt.AES_128_GCM)) { - aErrorList.add(_createError(sFieldPrefix + - "Security.X509EncryptionAlgorithm must use the value '" + - ECryptoAlgorithmCrypt.AES_128_GCM.getID() + - "' instead of '" + - aPModeLegSecurity.getX509EncryptionAlgorithm().getID() + - "'")); + if (!aPModeLegSecurity.getX509EncryptionAlgorithm ().equals (ECryptoAlgorithmCrypt.AES_128_GCM)) + { + aErrorList.add (_createError (sFieldPrefix + + "Security.X509EncryptionAlgorithm must use the value '" + + ECryptoAlgorithmCrypt.AES_128_GCM.getID () + + "' instead of '" + + aPModeLegSecurity.getX509EncryptionAlgorithm ().getID () + + "'")); } } - final Integer nEncryptionMinimumStrength = aPModeLegSecurity.getX509EncryptionMinimumStrength (); - if (nEncryptionMinimumStrength == null || !nEncryptionMinimumStrength.equals(128)) + final Integer aEncryptionMinimumStrength = aPModeLegSecurity.getX509EncryptionMinimumStrength (); + if (aEncryptionMinimumStrength == null || aEncryptionMinimumStrength.intValue () != 128) { - aErrorList.add (_createError (sFieldPrefix + "Security.X509Encryption.MinimalStrength must be defined and set to 128")); + aErrorList.add (_createError (sFieldPrefix + + "Security.X509Encryption.MinimalStrength must be defined and set to 128")); } // Check WSS Version = 1.1.1 @@ -242,7 +246,8 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList, aErrorList.add (_createError (sFieldPrefix + "Security.PModeAuthorize is missing")); } - if (!aPModeLegSecurity.isSendReceiptDefined () || !aPModeLegSecurity.isSendReceipt ()) { + if (!aPModeLegSecurity.isSendReceiptDefined () || !aPModeLegSecurity.isSendReceipt ()) + { aErrorList.add (_createError (sFieldPrefix + "Security.SendReceipt must be defined and set to 'true'")); } else @@ -257,7 +262,7 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList, EPModeSendReceiptReplyPattern.RESPONSE + " instead of " + aPModeLegSecurity.getSendReceiptReplyPattern ())); - } + } } else { @@ -355,7 +360,7 @@ public void validatePMode (@Nonnull final IPMode aPMode, @Nonnull final ErrorLis } final PModeParty aResponderParty = aPMode.getResponder (); - if (aResponderParty != null && !aResponderParty.getRole().equals (CAS4.DEFAULT_RESPONDER_URL)) + if (aResponderParty != null && !aResponderParty.getRole ().equals (CAS4.DEFAULT_RESPONDER_URL)) { aErrorList.add (_createError ("PMode.Responder.Role must be set to '" + CAS4.DEFAULT_RESPONDER_URL + "'")); } @@ -398,19 +403,21 @@ public void validatePMode (@Nonnull final IPMode aPMode, @Nonnull final ErrorLis final PModeReceptionAwareness aPModeReceptionAwareness = aPMode.getReceptionAwareness (); if (aPModeReceptionAwareness != null) { - if (!aPModeReceptionAwareness.isReceptionAwarenessDefined () || !aPModeReceptionAwareness.isReceptionAwareness ()) { - aErrorList.add(_createError("PMode[1].ReceptionAwareness must be defined and set to 'true'")); + if (!aPModeReceptionAwareness.isReceptionAwarenessDefined () || !aPModeReceptionAwareness.isReceptionAwareness ()) + { + aErrorList.add (_createError ("PMode[1].ReceptionAwareness must be defined and set to 'true'")); } else { if (!aPModeReceptionAwareness.isRetryDefined () || !aPModeReceptionAwareness.isRetry ()) { - aErrorList.add(_createError("PMode[1].ReceptionAwareness.Retry must be defined and set to 'true'")); + aErrorList.add (_createError ("PMode[1].ReceptionAwareness.Retry must be defined and set to 'true'")); } - if (!aPModeReceptionAwareness.isDuplicateDetectionDefined () || !aPModeReceptionAwareness.isDuplicateDetection ()) + if (!aPModeReceptionAwareness.isDuplicateDetectionDefined () || + !aPModeReceptionAwareness.isDuplicateDetection ()) { - aErrorList.add(_createError("PMode[1].ReceptionAwareness.DuplicateDetection must be defined and set to 'true'")); + aErrorList.add (_createError ("PMode[1].ReceptionAwareness.DuplicateDetection must be defined and set to 'true'")); } } } diff --git a/phase4-profile-bdew/src/main/java/com/helger/phase4/profile/bdew/BDEWPMode.java b/phase4-profile-bdew/src/main/java/com/helger/phase4/profile/bdew/BDEWPMode.java index a885d5612..2b907bf49 100644 --- a/phase4-profile-bdew/src/main/java/com/helger/phase4/profile/bdew/BDEWPMode.java +++ b/phase4-profile-bdew/src/main/java/com/helger/phase4/profile/bdew/BDEWPMode.java @@ -21,6 +21,8 @@ import javax.annotation.concurrent.Immutable; import com.helger.commons.annotation.Nonempty; +import com.helger.commons.collection.impl.CommonsHashSet; +import com.helger.commons.collection.impl.ICommonsSet; import com.helger.commons.state.ETriState; import com.helger.phase4.CAS4; import com.helger.phase4.attachment.EAS4CompressionMode; @@ -44,8 +46,6 @@ import com.helger.phase4.model.pmode.leg.PModeLegSecurity; import com.helger.phase4.wss.EWSSVersion; -import java.util.Set; - /** * PMode creation code. * @@ -75,6 +75,18 @@ public final class BDEWPMode public static final String ACTION_REQUEST_SWITCH = "https://www.bdew.de/as4/communication/actions/requestSwitch"; public static final String ACTION_CONFIRM_SWITCH = "https://www.bdew.de/as4/communication/actions/confirmSwitch"; + private static final ICommonsSet ALL_SERVICES = new CommonsHashSet <> (SERVICE_TEST, + SERVICE_PATH_SWITCH, + SERVICE_MARKTPROZESSE, + SERVICE_FAHRPLAN, + SERVICE_REDISPATCH_2_0, + SERVICE_KWEP, + SERVICE_SOGL); + private static final ICommonsSet ALL_ACTIONS = new CommonsHashSet <> (ACTION_DEFAULT, + ACTION_TEST_SERVICE, + ACTION_REQUEST_SWITCH, + ACTION_CONFIRM_SWITCH); + private BDEWPMode () {} @@ -215,14 +227,13 @@ public static PMode createBDEWPMode (@Nonnull @Nonempty final String sInitiatorI return aPMode; } - public static Set getServices () + public static boolean containsService (@Nonnull final String sService) { - return Set.of(SERVICE_TEST, SERVICE_PATH_SWITCH, SERVICE_MARKTPROZESSE, SERVICE_FAHRPLAN, - SERVICE_REDISPATCH_2_0, SERVICE_KWEP, SERVICE_SOGL); + return ALL_SERVICES.contains (sService); } - public static Set getActions () + public static boolean containsAction (@Nonnull final String sAction) { - return Set.of(ACTION_DEFAULT, ACTION_TEST_SERVICE, ACTION_REQUEST_SWITCH, ACTION_CONFIRM_SWITCH); + return ALL_ACTIONS.contains (sAction); } }