Search in sources :

Example 1 with IAS4ProfileValidator

use of com.helger.phase4.profile.IAS4ProfileValidator in project phase4 by phax.

the class AS4ENTSOGProfileRegistarSPI method registerAS4Profile.

public void registerAS4Profile(@Nonnull final IAS4ProfileRegistrar aRegistrar) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Registering phase4 profile '" + AS4_PROFILE_ID + "'");
    final Supplier<? extends IAS4ProfileValidator> aProfileValidatorProvider = ENTSOGCompatibilityValidator::new;
    final IAS4ProfilePModeProvider aDefaultPModeProvider = (i, r, a) -> ENTSOGPMode.createENTSOGPMode(i, r, a, PMODE_ID_PROVIDER, true);
    final AS4Profile aProfile = new AS4Profile(AS4_PROFILE_ID, AS4_PROFILE_NAME, aProfileValidatorProvider, aDefaultPModeProvider, PMODE_ID_PROVIDER, false);
    aRegistrar.registerProfile(aProfile);
}
Also used : Logger(org.slf4j.Logger) AS4Profile(com.helger.phase4.profile.AS4Profile) IAS4ProfileRegistrar(com.helger.phase4.profile.IAS4ProfileRegistrar) LoggerFactory(org.slf4j.LoggerFactory) IAS4ProfilePModeProvider(com.helger.phase4.profile.IAS4ProfilePModeProvider) Supplier(java.util.function.Supplier) Nonnull(javax.annotation.Nonnull) IsSPIImplementation(com.helger.commons.annotation.IsSPIImplementation) IAS4ProfileValidator(com.helger.phase4.profile.IAS4ProfileValidator) IPModeIDProvider(com.helger.phase4.model.pmode.IPModeIDProvider) IAS4ProfileRegistrarSPI(com.helger.phase4.profile.IAS4ProfileRegistrarSPI) IAS4ProfilePModeProvider(com.helger.phase4.profile.IAS4ProfilePModeProvider) AS4Profile(com.helger.phase4.profile.AS4Profile)

Example 2 with IAS4ProfileValidator

use of com.helger.phase4.profile.IAS4ProfileValidator in project phase4 by phax.

the class AS4PeppolProfileRegistarSPI method registerAS4Profile.

public void registerAS4Profile(@Nonnull final IAS4ProfileRegistrar aRegistrar) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Registering phase4 profile '" + AS4_PROFILE_ID + "'");
    final Supplier<? extends IAS4ProfileValidator> aProfileValidatorProvider = PeppolCompatibilityValidator::new;
    final IAS4ProfilePModeProvider aDefaultPModeProvider = (i, r, a) -> PeppolPMode.createPeppolPMode(i, r, a, PMODE_ID_PROVIDER, true);
    final AS4Profile aProfile = new AS4Profile(AS4_PROFILE_ID, AS4_PROFILE_NAME, aProfileValidatorProvider, aDefaultPModeProvider, PMODE_ID_PROVIDER, false);
    aRegistrar.registerProfile(aProfile);
    aRegistrar.setDefaultProfile(aProfile);
}
Also used : Logger(org.slf4j.Logger) AS4Profile(com.helger.phase4.profile.AS4Profile) IAS4ProfileRegistrar(com.helger.phase4.profile.IAS4ProfileRegistrar) LoggerFactory(org.slf4j.LoggerFactory) IAS4ProfilePModeProvider(com.helger.phase4.profile.IAS4ProfilePModeProvider) Supplier(java.util.function.Supplier) Nonnull(javax.annotation.Nonnull) IsSPIImplementation(com.helger.commons.annotation.IsSPIImplementation) IAS4ProfileValidator(com.helger.phase4.profile.IAS4ProfileValidator) IPModeIDProvider(com.helger.phase4.model.pmode.IPModeIDProvider) IAS4ProfileRegistrarSPI(com.helger.phase4.profile.IAS4ProfileRegistrarSPI) IAS4ProfilePModeProvider(com.helger.phase4.profile.IAS4ProfilePModeProvider) AS4Profile(com.helger.phase4.profile.AS4Profile)

Example 3 with IAS4ProfileValidator

use of com.helger.phase4.profile.IAS4ProfileValidator in project phase4 by phax.

the class AS4IncomingHandler method processEbmsMessage.

@Nonnull
public static IAS4MessageState processEbmsMessage(@Nonnull @WillNotClose final AS4ResourceHelper aResHelper, @Nonnull final Locale aLocale, @Nonnull final SOAPHeaderElementProcessorRegistry aRegistry, @Nonnull final HttpHeaderMap aHttpHeaders, @Nonnull final Document aSoapDocument, @Nonnull final ESoapVersion eSoapVersion, @Nonnull final ICommonsList<WSS4JAttachment> aIncomingAttachments, @Nonnull final IAS4IncomingProfileSelector aAS4ProfileSelector, @Nonnull final ICommonsList<Ebms3Error> aErrorMessagesTarget) throws Phase4Exception {
    ValueEnforcer.notNull(aResHelper, "ResHelper");
    ValueEnforcer.notNull(aLocale, "Locale");
    ValueEnforcer.notNull(aHttpHeaders, "HttpHeaders");
    ValueEnforcer.notNull(aSoapDocument, "SoapDocument");
    ValueEnforcer.notNull(eSoapVersion, "SoapVersion");
    ValueEnforcer.notNull(aIncomingAttachments, "IncomingAttachments");
    ValueEnforcer.notNull(aAS4ProfileSelector, "AS4ProfileSelector");
    ValueEnforcer.notNull(aErrorMessagesTarget, "aErrorMessagesTarget");
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Received the following SOAP " + eSoapVersion.getVersion() + " document:");
        LOGGER.debug(AS4XMLHelper.serializeXML(aSoapDocument));
        if (aIncomingAttachments.isEmpty()) {
            LOGGER.debug("Without any incoming attachments");
        } else {
            LOGGER.debug("Including the following " + aIncomingAttachments.size() + " attachments:");
            LOGGER.debug(aIncomingAttachments.toString());
        }
    }
    // This is where all data from the SOAP headers is stored to
    final AS4MessageState aState = new AS4MessageState(eSoapVersion, aResHelper, aLocale);
    // Handle all headers - modifies the state
    _processSoapHeaderElements(aRegistry, aSoapDocument, aIncomingAttachments, aState, aErrorMessagesTarget);
    // Remember if header processing was successful or not
    final boolean bSoapHeaderElementProcessingSuccess = aErrorMessagesTarget.isEmpty();
    aState.setSoapHeaderElementProcessingSuccessful(bSoapHeaderElementProcessingSuccess);
    if (bSoapHeaderElementProcessingSuccess) {
        // Every message can only contain 1 User message or 1 pull message
        // aUserMessage can be null on incoming Pull-Message!
        final Ebms3UserMessage aEbmsUserMessage = aState.getEbmsUserMessage();
        final Ebms3Error aEbmsError = aState.getEbmsError();
        final Ebms3PullRequest aEbmsPullRequest = aState.getEbmsPullRequest();
        final Ebms3Receipt aEbmsReceipt = aState.getEbmsReceipt();
        // Check payload consistency
        final int nCountData = (aEbmsUserMessage != null ? 1 : 0) + (aEbmsPullRequest != null ? 1 : 0) + (aEbmsReceipt != null ? 1 : 0) + (aEbmsError != null ? 1 : 0);
        if (nCountData != 1) {
            LOGGER.error("Expected a UserMessage(" + (aEbmsUserMessage != null ? 1 : 0) + "), a PullRequest(" + (aEbmsPullRequest != null ? 1 : 0) + "), a Receipt(" + (aEbmsReceipt != null ? 1 : 0) + ") or an Error(" + (aEbmsError != null ? 1 : 0) + ")");
            // send EBMS:0001 error back
            aErrorMessagesTarget.add(EEbmsError.EBMS_VALUE_NOT_RECOGNIZED.getAsEbms3Error(aLocale, aState.getMessageID()));
        }
        // Determine AS4 profile ID (since 0.13.0)
        final String sProfileID = aAS4ProfileSelector.getAS4ProfileID(aState);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Determined AS4 profile ID '" + sProfileID + "' for current message");
        aState.setProfileID(sProfileID);
        final IPMode aPMode = aState.getPMode();
        final PModeLeg aEffectiveLeg = aState.getEffectivePModeLeg();
        if (aEbmsUserMessage != null) {
            // User message requires PMode
            if (aPMode == null)
                throw new Phase4Exception("No AS4 P-Mode configuration found for user-message!");
            // Only check leg if the message is a usermessage
            if (aEffectiveLeg == null)
                throw new Phase4Exception("No AS4 P-Mode leg could be determined!");
            // Only do profile checks if a profile is set
            if (StringHelper.hasText(sProfileID)) {
                // Resolve profile ID
                final IAS4Profile aProfile = MetaAS4Manager.getProfileMgr().getProfileOfID(sProfileID);
                if (aProfile == null)
                    throw new IllegalStateException("The configured AS4 profile '" + sProfileID + "' does not exist.");
                // Profile Checks gets set when started with Server
                final IAS4ProfileValidator aValidator = aProfile.getValidator();
                if (aValidator != null) {
                    if (aAS4ProfileSelector.validateAgainstProfile()) {
                        final ErrorList aErrorList = new ErrorList();
                        aValidator.validatePMode(aPMode, aErrorList);
                        aValidator.validateUserMessage(aEbmsUserMessage, aErrorList);
                        if (aErrorList.isNotEmpty()) {
                            throw new Phase4Exception("Error validating incoming AS4 message with the profile " + aProfile.getDisplayName() + "\n Following errors are present: " + aErrorList.getAllErrors().getAllTexts(aLocale));
                        }
                    } else {
                        LOGGER.warn("The AS4 profile '" + sProfileID + "' has a validation configured, but the usage was disabled using the AS4ProfileSelector");
                    }
                }
            } else {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("AS4 state contains no AS4 profile ID - therefore no consistency checks are performed");
            }
            // Ensure the decrypted attachments are used
            final ICommonsList<WSS4JAttachment> aDecryptedAttachments = aState.hasDecryptedAttachments() ? aState.getDecryptedAttachments() : aState.getOriginalAttachments();
            // Decompress attachments (if compressed)
            // Result is directly in the decrypted attachments list!
            _decompressAttachments(aDecryptedAttachments, aEbmsUserMessage, aState);
        } else {
            // Pull-request also requires PMode
            if (aEbmsPullRequest != null && aPMode == null)
                throw new Phase4Exception("No AS4 P-Mode configuration found for pull-request!");
        }
        final boolean bUseDecryptedSOAP = aState.hasDecryptedSoapDocument();
        final Document aRealSOAPDoc = bUseDecryptedSOAP ? aState.getDecryptedSoapDocument() : aSoapDocument;
        assert aRealSOAPDoc != null;
        // Find SOAP body (mandatory according to SOAP XSD)
        final Node aBodyNode = XMLHelper.getFirstChildElementOfName(aRealSOAPDoc.getDocumentElement(), eSoapVersion.getNamespaceURI(), eSoapVersion.getBodyElementName());
        if (aBodyNode == null)
            throw new Phase4Exception((bUseDecryptedSOAP ? "Decrypted" : "Original") + " SOAP document is missing a Body element");
        aState.setSoapBodyPayloadNode(aBodyNode.getFirstChild());
        final boolean bIsPingMessage = AS4Helper.isPingMessage(aPMode);
        aState.setPingMessage(bIsPingMessage);
        if (bIsPingMessage)
            LOGGER.info("Received an AS4 Ping message - meaning it will NOT be handled by the custom handlers.");
    }
    return aState;
}
Also used : Ebms3Receipt(com.helger.phase4.ebms3header.Ebms3Receipt) IAS4Profile(com.helger.phase4.profile.IAS4Profile) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) Node(org.w3c.dom.Node) Ebms3Error(com.helger.phase4.ebms3header.Ebms3Error) Document(org.w3c.dom.Document) Phase4Exception(com.helger.phase4.util.Phase4Exception) ErrorList(com.helger.commons.error.list.ErrorList) Ebms3PullRequest(com.helger.phase4.ebms3header.Ebms3PullRequest) IPMode(com.helger.phase4.model.pmode.IPMode) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) IAS4ProfileValidator(com.helger.phase4.profile.IAS4ProfileValidator) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Nonnull(javax.annotation.Nonnull)

Example 4 with IAS4ProfileValidator

use of com.helger.phase4.profile.IAS4ProfileValidator in project phase4 by phax.

the class AS4CEFProfileRegistarSPI method registerAS4Profile.

public void registerAS4Profile(@Nonnull final IAS4ProfileRegistrar aRegistrar) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Registering phase4 profile '" + AS4_PROFILE_ID + "'");
    final Supplier<? extends IAS4ProfileValidator> aProfileValidatorProvider = CEFCompatibilityValidator::new;
    final IAS4ProfilePModeProvider aDefaultPModeProvider = (i, r, a) -> CEFPMode.createCEFPMode(i, r, a, PMODE_ID_PROVIDER, true);
    final AS4Profile aProfile = new AS4Profile(AS4_PROFILE_ID, AS4_PROFILE_NAME, aProfileValidatorProvider, aDefaultPModeProvider, PMODE_ID_PROVIDER, false);
    aRegistrar.registerProfile(aProfile);
    aRegistrar.setDefaultProfile(aProfile);
}
Also used : Logger(org.slf4j.Logger) AS4Profile(com.helger.phase4.profile.AS4Profile) IAS4ProfileRegistrar(com.helger.phase4.profile.IAS4ProfileRegistrar) LoggerFactory(org.slf4j.LoggerFactory) IAS4ProfilePModeProvider(com.helger.phase4.profile.IAS4ProfilePModeProvider) Supplier(java.util.function.Supplier) Nonnull(javax.annotation.Nonnull) IsSPIImplementation(com.helger.commons.annotation.IsSPIImplementation) IAS4ProfileValidator(com.helger.phase4.profile.IAS4ProfileValidator) IPModeIDProvider(com.helger.phase4.model.pmode.IPModeIDProvider) IAS4ProfileRegistrarSPI(com.helger.phase4.profile.IAS4ProfileRegistrarSPI) IAS4ProfilePModeProvider(com.helger.phase4.profile.IAS4ProfilePModeProvider) AS4Profile(com.helger.phase4.profile.AS4Profile)

Aggregations

IAS4ProfileValidator (com.helger.phase4.profile.IAS4ProfileValidator)4 Nonnull (javax.annotation.Nonnull)4 IsSPIImplementation (com.helger.commons.annotation.IsSPIImplementation)3 IPModeIDProvider (com.helger.phase4.model.pmode.IPModeIDProvider)3 AS4Profile (com.helger.phase4.profile.AS4Profile)3 IAS4ProfilePModeProvider (com.helger.phase4.profile.IAS4ProfilePModeProvider)3 IAS4ProfileRegistrar (com.helger.phase4.profile.IAS4ProfileRegistrar)3 IAS4ProfileRegistrarSPI (com.helger.phase4.profile.IAS4ProfileRegistrarSPI)3 Supplier (java.util.function.Supplier)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 ErrorList (com.helger.commons.error.list.ErrorList)1 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)1 Ebms3Error (com.helger.phase4.ebms3header.Ebms3Error)1 Ebms3PullRequest (com.helger.phase4.ebms3header.Ebms3PullRequest)1 Ebms3Receipt (com.helger.phase4.ebms3header.Ebms3Receipt)1 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)1 IPMode (com.helger.phase4.model.pmode.IPMode)1 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)1 IAS4Profile (com.helger.phase4.profile.IAS4Profile)1