|
46 | 46 | import com.helger.base.io.stream.StreamHelper; |
47 | 47 | import com.helger.base.spi.ServiceLoaderHelper; |
48 | 48 | import com.helger.base.string.StringHelper; |
| 49 | +import com.helger.collection.CollectionFind; |
49 | 50 | import com.helger.collection.commons.CommonsArrayList; |
50 | 51 | import com.helger.collection.commons.ICommonsList; |
51 | 52 | import com.helger.datetime.xml.XMLOffsetDateTime; |
|
63 | 64 | import com.helger.peppolid.IParticipantIdentifier; |
64 | 65 | import com.helger.peppolid.IProcessIdentifier; |
65 | 66 | import com.helger.peppolid.factory.IIdentifierFactory; |
| 67 | +import com.helger.peppolid.factory.PeppolIdentifierFactory; |
| 68 | +import com.helger.peppolid.peppol.participant.PeppolParticipantIdentifier; |
66 | 69 | import com.helger.phase4.CAS4; |
67 | 70 | import com.helger.phase4.attachment.AS4DecompressException; |
68 | 71 | import com.helger.phase4.attachment.EAS4CompressionMode; |
@@ -767,6 +770,60 @@ public AS4MessageProcessorResult processAS4UserMessage (@NonNull final IAS4Incom |
767 | 770 | return AS4MessageProcessorResult.createFailure (); |
768 | 771 | } |
769 | 772 |
|
| 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 | + |
770 | 827 | // If the receiver checks are activated, run them now |
771 | 828 | if (aReceiverCheckData.isReceiverCheckEnabled ()) |
772 | 829 | { |
@@ -817,7 +874,7 @@ public AS4MessageProcessorResult processAS4UserMessage (@NonNull final IAS4Incom |
817 | 874 | LOGGER.error (sLogPrefix + sMsg, ex); |
818 | 875 |
|
819 | 876 | final int nHttpStatusCode = ex instanceof final Phase4IncomingException pix ? pix.getHttpStatusCode () |
820 | | - : CAS4.HTTP_STATUS_UNDEFINED; |
| 877 | + : CAS4.HTTP_STATUS_UNDEFINED; |
821 | 878 |
|
822 | 879 | aProcessingErrorMessages.add (AS4Error.builder () |
823 | 880 | .ebmsError (EEbmsError.EBMS_OTHER.errorBuilder (aDisplayLocale) |
@@ -875,7 +932,7 @@ public AS4MessageProcessorResult processAS4UserMessage (@NonNull final IAS4Incom |
875 | 932 | LOGGER.error (sLogPrefix + sDetails, ex); |
876 | 933 |
|
877 | 934 | final int nHttpStatusCode = ex instanceof final Phase4IncomingException pix ? pix.getHttpStatusCode () |
878 | | - : CAS4.HTTP_STATUS_UNDEFINED; |
| 935 | + : CAS4.HTTP_STATUS_UNDEFINED; |
879 | 936 |
|
880 | 937 | aProcessingErrorMessages.add (AS4Error.builder () |
881 | 938 | .ebmsError (EEbmsError.EBMS_OTHER.errorBuilder (aDisplayLocale) |
|
0 commit comments