Skip to content

Commit 8036bd9

Browse files
committed
Added a consistency check, that AS4 IDs match SBDH IDs
1 parent 38b0e03 commit 8036bd9

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

phase4-peppol-servlet/src/main/java/com/helger/phase4/peppol/servlet/Phase4PeppolServletMessageProcessorSPI.java

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.helger.base.io.stream.StreamHelper;
4747
import com.helger.base.spi.ServiceLoaderHelper;
4848
import com.helger.base.string.StringHelper;
49+
import com.helger.collection.CollectionFind;
4950
import com.helger.collection.commons.CommonsArrayList;
5051
import com.helger.collection.commons.ICommonsList;
5152
import com.helger.datetime.xml.XMLOffsetDateTime;
@@ -63,6 +64,8 @@
6364
import com.helger.peppolid.IParticipantIdentifier;
6465
import com.helger.peppolid.IProcessIdentifier;
6566
import com.helger.peppolid.factory.IIdentifierFactory;
67+
import com.helger.peppolid.factory.PeppolIdentifierFactory;
68+
import com.helger.peppolid.peppol.participant.PeppolParticipantIdentifier;
6669
import com.helger.phase4.CAS4;
6770
import com.helger.phase4.attachment.AS4DecompressException;
6871
import com.helger.phase4.attachment.EAS4CompressionMode;
@@ -767,6 +770,60 @@ public AS4MessageProcessorResult processAS4UserMessage (@NonNull final IAS4Incom
767770
return AS4MessageProcessorResult.createFailure ();
768771
}
769772

773+
// Compare C1 ID from SBDH with the one of AS4
774+
{
775+
// Theoretically the MessageProperties must be present, but if someone disables the phase4
776+
// PMode Validation it may be null
777+
final Ebms3Property aOriginalSender = aUserMessage.getMessageProperties () == null ? null
778+
: CollectionFind.findFirst (aUserMessage.getMessageProperties ()
779+
.getProperty (),
780+
x -> CAS4.ORIGINAL_SENDER.equals (x.getName ()));
781+
final PeppolParticipantIdentifier aSBDHC1PID = aOriginalSender == null ? null
782+
: PeppolIdentifierFactory.INSTANCE.createParticipantIdentifier (aOriginalSender.getType (),
783+
aOriginalSender.getValue ());
784+
if (!aPeppolSBDH.getSenderAsIdentifier ().hasSameContent (aSBDHC1PID))
785+
{
786+
final String sMsg = "The AS4 originalSender (" +
787+
(aSBDHC1PID == null ? "not provided" : aSBDHC1PID.getURIEncoded ()) +
788+
" ) is different from the SBDH Sender Identifier (" +
789+
aPeppolSBDH.getSenderAsIdentifier ().getURIEncoded () +
790+
")";
791+
LOGGER.error (sLogPrefix + sMsg);
792+
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.errorBuilder (aDisplayLocale)
793+
.refToMessageInError (aState.getMessageID ())
794+
.errorDetail (sMsg)
795+
.build ());
796+
return AS4MessageProcessorResult.createFailure ();
797+
}
798+
}
799+
800+
// Compare C4 ID from SBDH with the one of AS4
801+
{
802+
// Theoretically the MessageProperties must be present, but if someone disables the phase4
803+
// PMode Validation it may be null
804+
final Ebms3Property aFinalRecipient = aUserMessage.getMessageProperties () == null ? null
805+
: CollectionFind.findFirst (aUserMessage.getMessageProperties ()
806+
.getProperty (),
807+
x -> CAS4.FINAL_RECIPIENT.equals (x.getName ()));
808+
final PeppolParticipantIdentifier aSBDHC4PID = aFinalRecipient == null ? null
809+
: PeppolIdentifierFactory.INSTANCE.createParticipantIdentifier (aFinalRecipient.getType (),
810+
aFinalRecipient.getValue ());
811+
if (!aPeppolSBDH.getReceiverAsIdentifier ().hasSameContent (aSBDHC4PID))
812+
{
813+
final String sMsg = "The AS4 finalRecipient (" +
814+
(aSBDHC4PID == null ? "not provided" : aSBDHC4PID.getURIEncoded ()) +
815+
" ) is different from the SBDH Sender Identifier (" +
816+
aPeppolSBDH.getReceiverAsIdentifier ().getURIEncoded () +
817+
")";
818+
LOGGER.error (sLogPrefix + sMsg);
819+
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.errorBuilder (aDisplayLocale)
820+
.refToMessageInError (aState.getMessageID ())
821+
.errorDetail (sMsg)
822+
.build ());
823+
return AS4MessageProcessorResult.createFailure ();
824+
}
825+
}
826+
770827
// If the receiver checks are activated, run them now
771828
if (aReceiverCheckData.isReceiverCheckEnabled ())
772829
{
@@ -817,7 +874,7 @@ public AS4MessageProcessorResult processAS4UserMessage (@NonNull final IAS4Incom
817874
LOGGER.error (sLogPrefix + sMsg, ex);
818875

819876
final int nHttpStatusCode = ex instanceof final Phase4IncomingException pix ? pix.getHttpStatusCode ()
820-
: CAS4.HTTP_STATUS_UNDEFINED;
877+
: CAS4.HTTP_STATUS_UNDEFINED;
821878

822879
aProcessingErrorMessages.add (AS4Error.builder ()
823880
.ebmsError (EEbmsError.EBMS_OTHER.errorBuilder (aDisplayLocale)
@@ -875,7 +932,7 @@ public AS4MessageProcessorResult processAS4UserMessage (@NonNull final IAS4Incom
875932
LOGGER.error (sLogPrefix + sDetails, ex);
876933

877934
final int nHttpStatusCode = ex instanceof final Phase4IncomingException pix ? pix.getHttpStatusCode ()
878-
: CAS4.HTTP_STATUS_UNDEFINED;
935+
: CAS4.HTTP_STATUS_UNDEFINED;
879936

880937
aProcessingErrorMessages.add (AS4Error.builder ()
881938
.ebmsError (EEbmsError.EBMS_OTHER.errorBuilder (aDisplayLocale)

0 commit comments

Comments
 (0)