Search in sources :

Example 21 with PModeLeg

use of com.helger.phase4.model.pmode.leg.PModeLeg in project phase4 by phax.

the class CEFCompatibilityValidatorTwoWayFuncTest method testValidatePModeErrorHandlingReportProcessErrorNotifyConsumerWrongValue.

@Test
public void testValidatePModeErrorHandlingReportProcessErrorNotifyConsumerWrongValue() {
    final PModeLegErrorHandling aErrorHandler = PModeLegErrorHandling.createUndefined();
    aErrorHandler.setReportProcessErrorNotifyConsumer(false);
    m_aPMode.setLeg2(new PModeLeg(PModeLegProtocol.createForDefaultSoapVersion("http://test.example.org"), null, aErrorHandler, null, null));
    VALIDATOR.validatePMode(m_aPMode, m_aErrorList);
    assertTrue(m_aErrorList.containsAny(x -> x.getErrorText(LOCALE).contains("ErrorHandling.Report.ProcessErrorNotifyConsumer should be 'true'")));
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) PModeLegSecurity(com.helger.phase4.model.pmode.leg.PModeLegSecurity) MessageHelperMethods(com.helger.phase4.messaging.domain.MessageHelperMethods) EMEP(com.helger.phase4.model.EMEP) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) ESoapVersion(com.helger.phase4.soap.ESoapVersion) Assert.assertNotSame(org.junit.Assert.assertNotSame) EPModeSendReceiptReplyPattern(com.helger.phase4.model.pmode.leg.EPModeSendReceiptReplyPattern) ECryptoAlgorithmSign(com.helger.phase4.crypto.ECryptoAlgorithmSign) Locale(java.util.Locale) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) PMode(com.helger.phase4.model.pmode.PMode) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) ClassRule(org.junit.ClassRule) PModeLegErrorHandling(com.helger.phase4.model.pmode.leg.PModeLegErrorHandling) PhotonAppWebTestRule(com.helger.photon.app.mock.PhotonAppWebTestRule) Before(org.junit.Before) Ebms3PartyId(com.helger.phase4.ebms3header.Ebms3PartyId) PModeLegProtocol(com.helger.phase4.model.pmode.leg.PModeLegProtocol) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) ECryptoAlgorithmSignDigest(com.helger.phase4.crypto.ECryptoAlgorithmSignDigest) EWSSVersion(com.helger.phase4.wss.EWSSVersion) Assert.assertTrue(org.junit.Assert.assertTrue) EMEPBinding(com.helger.phase4.model.EMEPBinding) Test(org.junit.Test) Ebms3To(com.helger.phase4.ebms3header.Ebms3To) ECryptoAlgorithmCrypt(com.helger.phase4.crypto.ECryptoAlgorithmCrypt) Ebms3From(com.helger.phase4.ebms3header.Ebms3From) Ignore(org.junit.Ignore) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) IPModeIDProvider(com.helger.phase4.model.pmode.IPModeIDProvider) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) PModeLegErrorHandling(com.helger.phase4.model.pmode.leg.PModeLegErrorHandling) Test(org.junit.Test)

Example 22 with PModeLeg

use of com.helger.phase4.model.pmode.leg.PModeLeg in project phase4 by phax.

the class ENTSOGCompatibilityValidator method _checkIfLegIsValid.

private static void _checkIfLegIsValid(@Nonnull final ErrorList aErrorList, @Nonnull final PModeLeg aPModeLeg, @Nonnull @Nonempty final String sFieldPrefix) {
    final PModeLegProtocol aLegProtocol = aPModeLeg.getProtocol();
    if (aLegProtocol == null) {
        aErrorList.add(_createError(sFieldPrefix + "Protocol is missing"));
    } else {
        // PROTOCOL Address only https allowed
        final String sAddressProtocol = aLegProtocol.getAddressProtocol();
        if (StringHelper.hasText(sAddressProtocol)) {
            if (sAddressProtocol.equalsIgnoreCase("http") || sAddressProtocol.equalsIgnoreCase("https")) {
            // Always okay
            } else {
                // Other protocol
                aErrorList.add(_createError(sFieldPrefix + "AddressProtocol '" + sAddressProtocol + "' is unsupported"));
            }
        } else {
            // Empty address protocol
            aErrorList.add(_createError(sFieldPrefix + "AddressProtocol is missing"));
        }
        final ESoapVersion eSOAPVersion = aLegProtocol.getSoapVersion();
        if (!eSOAPVersion.isAS4Default()) {
            aErrorList.add(_createError(sFieldPrefix + "SoapVersion '" + eSOAPVersion.getVersion() + "' is unsupported"));
        }
    }
    // Only check the security features if a Security Leg is currently present
    final PModeLegSecurity aPModeLegSecurity = aPModeLeg.getSecurity();
    if (aPModeLegSecurity != null) {
        // Check Certificate
        if (aPModeLegSecurity.getX509SignatureCertificate() == null) {
            aErrorList.add(_createError(sFieldPrefix + "Security.X509SignatureCertificate is missing"));
        }
        // Check Signature Algorithm
        if (aPModeLegSecurity.getX509SignatureAlgorithm() == null) {
            aErrorList.add(_createError(sFieldPrefix + "Security.X509SignatureAlgorithm is missing"));
        } else if (!aPModeLegSecurity.getX509SignatureAlgorithm().equals(ECryptoAlgorithmSign.RSA_SHA_256)) {
            aErrorList.add(_createError(sFieldPrefix + "Security.X509SignatureAlgorithm must use the value '" + ECryptoAlgorithmSign.RSA_SHA_256.getID() + "'"));
        }
        // Check Hash Function
        if (aPModeLegSecurity.getX509SignatureHashFunction() == null) {
            aErrorList.add(_createError(sFieldPrefix + "Security.X509SignatureHashFunction is missing"));
        } else if (!aPModeLegSecurity.getX509SignatureHashFunction().equals(ECryptoAlgorithmSignDigest.DIGEST_SHA_256)) {
            aErrorList.add(_createError(sFieldPrefix + "Securoty.X509SignatureHashFunction must use the value '" + ECryptoAlgorithmSignDigest.DIGEST_SHA_256.getID() + "'"));
        }
        // Check Encrypt algorithm
        if (aPModeLegSecurity.getX509EncryptionAlgorithm() == null) {
            aErrorList.add(_createError(sFieldPrefix + "Security.X509EncryptionAlgorithm is missing"));
        } else if (!aPModeLegSecurity.getX509EncryptionAlgorithm().equals(ECryptoAlgorithmCrypt.AES_128_GCM)) {
            aErrorList.add(_createError(sFieldPrefix + "Securoty.X509EncryptionAlgorithm must use the value '" + ECryptoAlgorithmCrypt.AES_128_GCM.getID() + "' instead of '" + aPModeLegSecurity.getX509EncryptionAlgorithm().getID() + "'"));
        }
        // Check WSS Version = 1.1.1
        if (aPModeLegSecurity.getWSSVersion() != null) {
            // Check for WSS - Version if there is one present
            if (!aPModeLegSecurity.getWSSVersion().equals(EWSSVersion.WSS_111))
                aErrorList.add(_createError(sFieldPrefix + "Security.WSSVersion must use the value " + EWSSVersion.WSS_111 + " instead of " + aPModeLegSecurity.getWSSVersion()));
        }
        if (aPModeLegSecurity.isUsernameTokenCreatedDefined() || aPModeLegSecurity.isUsernameTokenDigestDefined() || aPModeLegSecurity.isUsernameTokenNonceDefined() || aPModeLegSecurity.hasUsernameTokenPassword() || aPModeLegSecurity.hasUsernameTokenUsername()) {
            aErrorList.add(_createError(sFieldPrefix + "Username nor it's part MUST NOT be set"));
        }
        // PModeAuthorize
        if (aPModeLegSecurity.isPModeAuthorizeDefined()) {
            if (aPModeLegSecurity.isPModeAuthorize())
                aErrorList.add(_createError(sFieldPrefix + "Security.PModeAuthorize must be set to 'false'"));
        } else {
            aErrorList.add(_createError(sFieldPrefix + "Security.PModeAuthorize is missing"));
        }
        // SEND RECEIPT TRUE/FALSE when false don't send receipts anymore
        if (aPModeLegSecurity.isSendReceiptDefined()) {
            if (aPModeLegSecurity.isSendReceipt()) {
                // set response required
                if (!aPModeLegSecurity.isSendReceiptNonRepudiation())
                    aErrorList.add(_createError(sFieldPrefix + "SendReceiptNonRepudiation must be set to 'true'"));
                if (aPModeLegSecurity.getSendReceiptReplyPattern() != EPModeSendReceiptReplyPattern.RESPONSE)
                    aErrorList.add(_createError(sFieldPrefix + "Security.SendReceiptReplyPattern must use the value " + EPModeSendReceiptReplyPattern.RESPONSE + " instead of " + aPModeLegSecurity.getSendReceiptReplyPattern()));
            }
        }
    } else {
        aErrorList.add(_createError(sFieldPrefix + "Security is missing"));
    }
    // Error Handling
    final PModeLegErrorHandling aErrorHandling = aPModeLeg.getErrorHandling();
    if (aErrorHandling != null) {
        if (aErrorHandling.isReportAsResponseDefined()) {
            if (!aErrorHandling.isReportAsResponse())
                aErrorList.add(_createError(sFieldPrefix + "ErrorHandling.Report.AsResponse must be 'true'"));
        } else {
            aErrorList.add(_createError(sFieldPrefix + "ErrorHandling.Report.AsResponse is missing"));
        }
        if (aErrorHandling.isReportProcessErrorNotifyConsumerDefined()) {
            if (!aErrorHandling.isReportProcessErrorNotifyConsumer())
                aErrorList.add(_createWarn(sFieldPrefix + "ErrorHandling.Report.ProcessErrorNotifyConsumer should be 'true'"));
        } else {
            aErrorList.add(_createError(sFieldPrefix + "ErrorHandling.Report.ProcessErrorNotifyConsumer is missing"));
        }
        if (aErrorHandling.isReportProcessErrorNotifyProducerDefined()) {
            if (!aErrorHandling.isReportProcessErrorNotifyProducer())
                aErrorList.add(_createWarn(sFieldPrefix + "ErrorHandling.Report.ProcessErrorNotifyProducer should be 'true'"));
        } else {
            aErrorList.add(_createError(sFieldPrefix + "ErrorHandling.Report.ProcessErrorNotifyProducer is missing"));
        }
        if (aErrorHandling.getReportSenderErrorsTo() != null && aErrorHandling.getReportSenderErrorsTo().addresses() != null && aErrorHandling.getReportSenderErrorsTo().addresses().isNotEmpty()) {
            aErrorList.add(_createError(sFieldPrefix + "ReportSenderErrorsTo must not be set"));
        }
    } else {
        aErrorList.add(_createError(sFieldPrefix + "ErrorHandling is missing"));
    }
}
Also used : ESoapVersion(com.helger.phase4.soap.ESoapVersion) PModeLegErrorHandling(com.helger.phase4.model.pmode.leg.PModeLegErrorHandling) PModeLegProtocol(com.helger.phase4.model.pmode.leg.PModeLegProtocol) PModeLegSecurity(com.helger.phase4.model.pmode.leg.PModeLegSecurity)

Example 23 with PModeLeg

use of com.helger.phase4.model.pmode.leg.PModeLeg in project phase4 by phax.

the class ENTSOGPMode method createENTSOGPMode.

/**
 * One-Way Version of the CEF pmode uses one-way push
 *
 * @param sInitiatorID
 *        Initiator ID
 * @param sResponderID
 *        Responder ID
 * @param sResponderAddress
 *        Responder URL
 * @param aPModeIDProvider
 *        PMode ID provider
 * @param bPersist
 *        <code>true</code> to persist the PMode in the PModeManager,
 *        <code>false</code> to have it only in memory.
 * @return New PMode
 */
@Nonnull
public static PMode createENTSOGPMode(@Nonnull @Nonempty final String sInitiatorID, @Nonnull @Nonempty final String sResponderID, @Nullable final String sResponderAddress, @Nonnull final IPModeIDProvider aPModeIDProvider, final boolean bPersist) {
    final PModeParty aInitiator = new PModeParty(ENTSOG_PARTY_ID_TYPE, sInitiatorID, CAS4.DEFAULT_INITIATOR_URL, null, null);
    final PModeParty aResponder = new PModeParty(ENTSOG_PARTY_ID_TYPE, sResponderID, CAS4.DEFAULT_RESPONDER_URL, null, null);
    final PMode aPMode = new PMode(aPModeIDProvider.getPModeID(sInitiatorID, sResponderID), aInitiator, aResponder, DEFAULT_AGREEMENT_ID, EMEP.ONE_WAY, EMEPBinding.PUSH, generatePModeLeg(sResponderAddress), (PModeLeg) null, generatePModePayloadSevice(), generatePModeReceptionAwareness());
    if (bPersist) {
        // Ensure it is stored
        MetaAS4Manager.getPModeMgr().createOrUpdatePMode(aPMode);
    }
    return aPMode;
}
Also used : PModeParty(com.helger.phase4.model.pmode.PModeParty) PMode(com.helger.phase4.model.pmode.PMode) Nonnull(javax.annotation.Nonnull)

Example 24 with PModeLeg

use of com.helger.phase4.model.pmode.leg.PModeLeg in project phase4 by phax.

the class ENTSOGCompatibilityValidatorTest method testValidatePModeErrorHandlingReportProcessErrorNotifyConsumerMandatory.

@Test
public void testValidatePModeErrorHandlingReportProcessErrorNotifyConsumerMandatory() {
    final PModeLegErrorHandling aErrorHandler = PModeLegErrorHandling.createUndefined();
    m_aPMode.setLeg1(new PModeLeg(PModeLegProtocol.createForDefaultSoapVersion("http://test.example.org"), null, aErrorHandler, null, null));
    VALIDATOR.validatePMode(m_aPMode, m_aErrorList);
    assertTrue(m_aErrorList.containsAny(x -> x.getErrorText(LOCALE).contains("ErrorHandling.Report.ProcessErrorNotifyConsumer is missing")));
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) PModeLegSecurity(com.helger.phase4.model.pmode.leg.PModeLegSecurity) MessageHelperMethods(com.helger.phase4.messaging.domain.MessageHelperMethods) EMEP(com.helger.phase4.model.EMEP) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) ESoapVersion(com.helger.phase4.soap.ESoapVersion) Assert.assertNotSame(org.junit.Assert.assertNotSame) EPModeSendReceiptReplyPattern(com.helger.phase4.model.pmode.leg.EPModeSendReceiptReplyPattern) ECryptoAlgorithmSign(com.helger.phase4.crypto.ECryptoAlgorithmSign) Locale(java.util.Locale) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) PMode(com.helger.phase4.model.pmode.PMode) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) ClassRule(org.junit.ClassRule) PModeLegErrorHandling(com.helger.phase4.model.pmode.leg.PModeLegErrorHandling) PhotonAppWebTestRule(com.helger.photon.app.mock.PhotonAppWebTestRule) Before(org.junit.Before) Ebms3PartyId(com.helger.phase4.ebms3header.Ebms3PartyId) PModeLegProtocol(com.helger.phase4.model.pmode.leg.PModeLegProtocol) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) ECryptoAlgorithmSignDigest(com.helger.phase4.crypto.ECryptoAlgorithmSignDigest) EWSSVersion(com.helger.phase4.wss.EWSSVersion) Assert.assertTrue(org.junit.Assert.assertTrue) EMEPBinding(com.helger.phase4.model.EMEPBinding) Test(org.junit.Test) Ebms3To(com.helger.phase4.ebms3header.Ebms3To) ECryptoAlgorithmCrypt(com.helger.phase4.crypto.ECryptoAlgorithmCrypt) Ebms3From(com.helger.phase4.ebms3header.Ebms3From) Ignore(org.junit.Ignore) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) IPModeIDProvider(com.helger.phase4.model.pmode.IPModeIDProvider) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) PModeLegErrorHandling(com.helger.phase4.model.pmode.leg.PModeLegErrorHandling) Test(org.junit.Test)

Example 25 with PModeLeg

use of com.helger.phase4.model.pmode.leg.PModeLeg in project phase4 by phax.

the class ENTSOGCompatibilityValidatorTest method testValidatePModeErrorHandlingMandatory.

// Error Handling
@Test
public void testValidatePModeErrorHandlingMandatory() {
    m_aPMode.setLeg1(new PModeLeg(PModeLegProtocol.createForDefaultSoapVersion("http://test.example.org"), null, null, null, null));
    VALIDATOR.validatePMode(m_aPMode, m_aErrorList);
    assertTrue(m_aErrorList.containsAny(x -> x.getErrorText(LOCALE).contains("PMode.Leg[1].ErrorHandling is missing")));
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) PModeLegSecurity(com.helger.phase4.model.pmode.leg.PModeLegSecurity) MessageHelperMethods(com.helger.phase4.messaging.domain.MessageHelperMethods) EMEP(com.helger.phase4.model.EMEP) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) ESoapVersion(com.helger.phase4.soap.ESoapVersion) Assert.assertNotSame(org.junit.Assert.assertNotSame) EPModeSendReceiptReplyPattern(com.helger.phase4.model.pmode.leg.EPModeSendReceiptReplyPattern) ECryptoAlgorithmSign(com.helger.phase4.crypto.ECryptoAlgorithmSign) Locale(java.util.Locale) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) PMode(com.helger.phase4.model.pmode.PMode) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) ClassRule(org.junit.ClassRule) PModeLegErrorHandling(com.helger.phase4.model.pmode.leg.PModeLegErrorHandling) PhotonAppWebTestRule(com.helger.photon.app.mock.PhotonAppWebTestRule) Before(org.junit.Before) Ebms3PartyId(com.helger.phase4.ebms3header.Ebms3PartyId) PModeLegProtocol(com.helger.phase4.model.pmode.leg.PModeLegProtocol) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) ECryptoAlgorithmSignDigest(com.helger.phase4.crypto.ECryptoAlgorithmSignDigest) EWSSVersion(com.helger.phase4.wss.EWSSVersion) Assert.assertTrue(org.junit.Assert.assertTrue) EMEPBinding(com.helger.phase4.model.EMEPBinding) Test(org.junit.Test) Ebms3To(com.helger.phase4.ebms3header.Ebms3To) ECryptoAlgorithmCrypt(com.helger.phase4.crypto.ECryptoAlgorithmCrypt) Ebms3From(com.helger.phase4.ebms3header.Ebms3From) Ignore(org.junit.Ignore) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) IPModeIDProvider(com.helger.phase4.model.pmode.IPModeIDProvider) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) Test(org.junit.Test)

Aggregations

PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)99 PMode (com.helger.phase4.model.pmode.PMode)91 PModeLegSecurity (com.helger.phase4.model.pmode.leg.PModeLegSecurity)89 EMEP (com.helger.phase4.model.EMEP)88 EMEPBinding (com.helger.phase4.model.EMEPBinding)88 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)87 PModeLegErrorHandling (com.helger.phase4.model.pmode.leg.PModeLegErrorHandling)87 PModeLegProtocol (com.helger.phase4.model.pmode.leg.PModeLegProtocol)86 ESoapVersion (com.helger.phase4.soap.ESoapVersion)86 Before (org.junit.Before)86 Ebms3SignalMessage (com.helger.phase4.ebms3header.Ebms3SignalMessage)85 Locale (java.util.Locale)85 ErrorList (com.helger.commons.error.list.ErrorList)84 ECryptoAlgorithmSign (com.helger.phase4.crypto.ECryptoAlgorithmSign)84 ECryptoAlgorithmSignDigest (com.helger.phase4.crypto.ECryptoAlgorithmSignDigest)84 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)84 Ebms3PartyId (com.helger.phase4.ebms3header.Ebms3PartyId)84 Ignore (org.junit.Ignore)84 Test (org.junit.Test)84 ETriState (com.helger.commons.state.ETriState)83