示例#1
0
        /// <summary>
        /// Creates a non-repudiation AS4 receipt that references a given <paramref name="includedUserMessage"/>.
        /// </summary>
        /// <param name="receiptMessageId"></param>
        /// <param name="includedUserMessage">The <see cref="Core.UserMessage"/> for which this receipt is created.</param>
        /// <param name="userMessageSecurityHeader">The security header to retrieve the signed references from to include in the receipt.</param>
        /// <param name="userMessageSendViaMultiHop">
        /// Whether or not the user message was send in a multi-hop fashion or not.
        /// Setting this on <c>true</c> will result in a receipt with the referencing user message included in a RoutingInput element.
        /// </param>
        /// <exception cref="ArgumentNullException">The <paramref name="includedUserMessage"/> should not be <c>null</c>.</exception>
        public static Receipt CreateFor(
            string receiptMessageId,
            UserMessage includedUserMessage,
            SecurityHeader userMessageSecurityHeader,
            bool userMessageSendViaMultiHop = false)
        {
            if (includedUserMessage == null)
            {
                throw new ArgumentNullException(nameof(includedUserMessage));
            }

            if (userMessageSecurityHeader != null)
            {
                IEnumerable <CryptoReference> signedReferences = userMessageSecurityHeader.GetReferences();

                if (signedReferences.Any())
                {
                    var nonRepudiation =
                        new NonRepudiationInformation(
                            signedReferences.Select(Reference.CreateFromReferenceElement));

                    return(userMessageSendViaMultiHop.ThenMaybe(UserMessageMap.ConvertToRouting(includedUserMessage))
                           .Select(routing => new Receipt(receiptMessageId, includedUserMessage?.MessageId, nonRepudiation, routing))
                           .GetOrElse(() => new Receipt(receiptMessageId, includedUserMessage?.MessageId, nonRepudiation, routedUserMessage: null)));
                }
            }

            return(CreateFor(receiptMessageId, includedUserMessage, userMessageSendViaMultiHop));
        }
        internal static async Task <IEnumerable <MessageUnit> > GetMessageUnitsFromMessagingHeader(
            XmlDocument envelopeDocument,
            Messaging messagingHeader)
        {
            if (messagingHeader.MessageUnits == null)
            {
                return(Enumerable.Empty <MessageUnit>());
            }

            Maybe <RoutingInputUserMessage> routing = await GetRoutingUserMessageFromXml(envelopeDocument);

            MessageUnit ToMessageUnitModel(object u)
            {
                switch (u)
                {
                case Xml.UserMessage um:
                    return(UserMessageMap.Convert(um));

                case Xml.SignalMessage s:
                    return(ConvertSignalMessageFromXml(s, routing));

                default:
                    throw new NotSupportedException(
                              $"AS4Message has unknown MessageUnit of type: {u.GetType()}");
                }
            }

            return(messagingHeader.MessageUnits.Select(ToMessageUnitModel));
        }
        private static Messaging CreateMessagingHeader(AS4Message message)
        {
            object ToGeneralMessageUnit(MessageUnit u)
            {
                switch (u)
                {
                case UserMessage um: return(UserMessageMap.Convert(um));

                case Receipt r: return(ReceiptMap.Convert(r));

                case Error e: return(ErrorMap.Convert(e));

                case PullRequest pr: return(PullRequestMap.Convert(pr));

                default:
                    throw new NotSupportedException(
                              $"AS4Message contains unkown MessageUnit of type: {u.GetType()}");
                }
            }

            var messagingHeader = new Messaging
            {
                SecurityId   = message.SigningId.HeaderSecurityId,
                MessageUnits = message.MessageUnits.Select(ToGeneralMessageUnit).ToArray()
            };

            if (message.IsMultiHopMessage)
            {
                messagingHeader.role                     = Constants.Namespaces.EbmsNextMsh;
                messagingHeader.mustUnderstand1          = true;
                messagingHeader.mustUnderstand1Specified = true;
            }

            return(messagingHeader);
        }
示例#4
0
 public static Arbitrary <Receipt> Receipt()
 {
     return(Gen.zip3(Arb.Generate <NonEmptyString>().Two(), GenNonRepudiation(), UserMessage().Generator)
            .Select(t => new Receipt(
                        t.Item1.Item1.Get,
                        t.Item1.Item2.Get,
                        t.Item2,
                        UserMessageMap.ConvertToRouting(t.Item3)))
            .ToArbitrary());
 }
        public Property Mapping_Routing_UserMessage_Back_And_Forth_Reverse_Sender_Receiver_Party(UserMessage userMessage)
        {
            // Act
            var result = UserMessageMap.ConvertFromRouting(UserMessageMap.ConvertToRouting(userMessage));

            // Assert
            return(userMessage.CollaborationInfo.Equals(result.CollaborationInfo).Label("equal collaboration")
                   .And(userMessage.Sender.Equals(result.Receiver).Label("equal reversed sender"))
                   .And(userMessage.Receiver.Equals(result.Sender).Label("equal reversed receiver"))
                   .And(userMessage.PayloadInfo.SequenceEqual(result.PayloadInfo).Label("equal part infos"))
                   .And(userMessage.MessageProperties.SequenceEqual(result.MessageProperties).Label("equal message properties")));
        }
        public Property Mapping_UserMessage_Back_And_Forth_Stays_The_Same(UserMessage userMessage)
        {
            // Act
            var result = UserMessageMap.Convert(UserMessageMap.Convert(userMessage));

            // Assert
            return(userMessage.CollaborationInfo.Equals(result.CollaborationInfo).Label("equal collaboration")
                   .And(userMessage.Sender.Equals(result.Sender).Label("equal sender"))
                   .And(userMessage.Receiver.Equals(result.Receiver).Label("equal receiver"))
                   .And(userMessage.PayloadInfo.SequenceEqual(result.PayloadInfo).Label("equal part infos"))
                   .And(userMessage.MessageProperties.SequenceEqual(result.MessageProperties).Label("equal message properties")));
        }
示例#7
0
 public static Arbitrary <Error> Error()
 {
     return(Gen.zip3(
                Arb.Generate <NonEmptyString>().Two(),
                UserMessage().Generator,
                ErrorLine().ListOf())
            .Select(t => new Error(
                        t.Item1.Item1.Get,
                        t.Item1.Item2.Get,
                        DateTimeOffset.Now,
                        t.Item3,
                        UserMessageMap.ConvertToRouting(t.Item2)))
            .ToArbitrary());
 }
示例#8
0
        /// <summary>
        /// Creates an AS4 receipt that references a given <paramref name="includedUserMessage"/>.
        /// </summary>
        /// <param name="receiptMessageId"></param>
        /// <param name="includedUserMessage">The <see cref="Core.UserMessage"/> for which this receipt is created.</param>
        /// <param name="userMessageSendViaMultiHop">
        ///     Whether or not the user message was send in a multi-hop fashion or not.
        ///     Setting this on <c>true</c> will result in a receipt with the referencing user message included in a RoutingInput element.
        /// </param>
        /// <exception cref="ArgumentNullException">The <paramref name="includedUserMessage"/> should not be <c>null</c>.</exception>
        public static Receipt CreateFor(
            string receiptMessageId,
            UserMessage includedUserMessage,
            bool userMessageSendViaMultiHop = false)
        {
            if (includedUserMessage == null)
            {
                throw new ArgumentNullException(nameof(includedUserMessage));
            }

            return(userMessageSendViaMultiHop.ThenMaybe(UserMessageMap.ConvertToRouting(includedUserMessage))
                   .Select(routing => new Receipt(receiptMessageId, includedUserMessage.MessageId, DateTimeOffset.Now, includedUserMessage, routing))
                   .GetOrElse(() => new Receipt(receiptMessageId, includedUserMessage.MessageId, DateTimeOffset.Now, includedUserMessage, routedUserMessage: null)));
        }
示例#9
0
        /// <summary>
        /// Creates an AS4 error referencing a given <paramref name="userMessage"/>.
        /// </summary>
        /// <param name="errorMessageId">The ebMS message identifier of this message unit.</param>
        /// <param name="userMessage">The AS4 user message to reference in the to be created error.</param>
        /// <param name="occurredError">The error that has happened during the step execution.</param>
        /// <param name="userMessageSendViaMultiHop">
        ///     Whether or not the user message was send in a multi-hop fashion or not.
        ///     Setting this on <c>true</c> will result in an error with the referencing user message included in a RoutingInput element.
        /// </param>
        public static Error CreateFor(
            string errorMessageId,
            UserMessage userMessage,
            ErrorResult occurredError,
            bool userMessageSendViaMultiHop = false)
        {
            if (userMessageSendViaMultiHop)
            {
                var routedUserMessage = UserMessageMap.ConvertToRouting(userMessage);
                return(occurredError == null
                    ? new Error(errorMessageId, userMessage?.MessageId, DateTimeOffset.Now, new ErrorLine[0], routedUserMessage)
                    : new Error(errorMessageId, userMessage?.MessageId, DateTimeOffset.Now, new [] { ErrorLine.FromErrorResult(occurredError) }, routedUserMessage));
            }

            return(occurredError == null
                ? new Error(errorMessageId, userMessage?.MessageId)
                : new Error(errorMessageId, userMessage?.MessageId, ErrorLine.FromErrorResult(occurredError)));
        }
        private static UserMessage GetUserMessageFromFirstMessageUnitOrRoutingInput(AS4Message as4Message)
        {
            // TODO: is this enough? should we explicitly check for multi-hop signals ?
            if (as4Message.HasUserMessage)
            {
                Logger.Trace("AS4Message contains UserMessages, so the incoming message itself will be used to match the right ReceivingPMode");
                return(as4Message.FirstUserMessage);
            }

            Logger.Debug("AS4Message should be a Multi-Hop SignalMessage, so the embeded Multi-Hop UserMessage will be used to match the right ReceivingPMode");
            Maybe <RoutingInputUserMessage> routedUserMessageM =
                as4Message.SignalMessages.FirstOrDefault(s => s.IsMultihopSignal)?.MultiHopRouting;

            if (routedUserMessageM != null)
            {
                return(UserMessageMap.ConvertFromRouting(routedUserMessageM.UnsafeGet));
            }

            throw new InvalidOperationException(
                      "Incoming message doesn't have a UserMessage either as message unit or as <RoutedInput/> in a SignalMessage. "
                      + "This message can therefore not be used to determine the ReceivingPMode");
        }
示例#11
0
 /// <summary>
 /// Assigns the parent properties.
 /// </summary>
 /// <param name="messageUnit">The MessageUnit from which the properties must be retrieved..</param>
 public void AssignAS4Properties(MessageUnit messageUnit)
 {
     if (messageUnit is UserMessage userMessage)
     {
         FromParty      = userMessage.Sender.PartyIds.First().Id;
         ToParty        = userMessage.Receiver.PartyIds.First().Id;
         Action         = userMessage.CollaborationInfo.Action;
         Service        = userMessage.CollaborationInfo.Service.Value;
         ConversationId = userMessage.CollaborationInfo.ConversationId;
         Mpc            = userMessage.Mpc;
         IsTest         = userMessage.IsTest;
         IsDuplicate    = userMessage.IsDuplicate;
         SoapEnvelope   = AS4XmlSerializer.ToString(UserMessageMap.Convert(userMessage));
     }
     else
     {
         if (messageUnit is SignalMessage signalMessage)
         {
             IsDuplicate = signalMessage.IsDuplicate;
             Mpc         = signalMessage.MultiHopRouting.Select(r => r.mpc).GetOrElse(Constants.Namespaces.EbmsDefaultMpc);
         }
     }
 }
        /// <summary>
        /// Asserts the SOAP envelope.
        /// </summary>
        /// <param name="expected">The expected.</param>
        /// <param name="actual">The actual.</param>
        public static void AssertSoapEnvelope(UserMessage expected, MessageEntity actual)
        {
            string xmlRepresentation = AS4XmlSerializer.ToString(UserMessageMap.Convert(expected));

            Assert.Equal(xmlRepresentation, actual.SoapEnvelope);
        }