示例#1
0
        static void TransportTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            if (!ConfigureClaimFlow.Flow) return;
            if (!e.Message.Headers.ContainsKey(SecurityTokenKey)) return;

            var serializedToken = e.Message.Headers[SecurityTokenKey];
            var certificate = ExtractCertificate(serializedToken);
            var handler = new Saml2SecurityTokenHandler(new SamlSecurityTokenRequirement());
            var tokens = new List<SecurityToken> {new X509SecurityToken(certificate)};
            var resolver = SecurityTokenResolver.CreateDefaultSecurityTokenResolver(tokens.AsReadOnly(), false);
            handler.Configuration = new SecurityTokenHandlerConfiguration
            {
                IssuerTokenResolver = resolver,
                IssuerNameRegistry = new InternalIssuerNameRegistry(),
                CertificateValidator = X509CertificateValidator.None
            };
            using (var reader = XmlReader.Create(new StringReader(serializedToken)))
            {
                var bootstrapToken = handler.ReadToken(reader);
                handler.Configuration.AudienceRestriction.AudienceMode = AudienceUriMode.Never;
                handler.Configuration.MaxClockSkew = TimeSpan.MaxValue;
                var collection = handler.ValidateToken(bootstrapToken);
                Thread.CurrentPrincipal = new ClaimsPrincipal(collection);
            }
        }
示例#2
0
        void AuditMessageQueueTransport_TransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            var message = e.Message;

            // Get the xml content of the message in the audit Q that's being stored.
            var doc = new XmlDocument();
            doc.Load(new MemoryStream(message.Body));
            var messageBodyXml = doc.InnerXml;

            // Get the header list as a key value dictionary...
            Dictionary<string, string> headerDictionary = message.Headers.ToDictionary(k => k.Key, v => v.Value);

            var enclosedMessageType = headerDictionary["NServiceBus.EnclosedMessageTypes"];
            string messageType = enclosedMessageType;
            if (!String.IsNullOrWhiteSpace(enclosedMessageType))
            {
                messageType = enclosedMessageType.Split(new char[] { ',' }, StringSplitOptions.None)[0];
            }

            AuditMessage messageToStore = new AuditMessage
            {
                MessageId = message.Id,
                OriginalMessageId = message.GetOriginalId(),
                Body = messageBodyXml,
                Headers = headerDictionary,
                MessageType = messageType,
                ReceivedTime = DateTime.ParseExact(headerDictionary["NServiceBus.TimeSent"], "yyyy-MM-dd HH:mm:ss:ffffff Z", System.Globalization.CultureInfo.InvariantCulture)
            };

            // Save the message
            Console.WriteLine("Saving {0}", messageType);
            Persister.Persist(messageToStore);
        }
        static void Transport_TransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            if (!ConfigureImpersonation.Impersonate)
                return;

            if (!e.Message.Headers.ContainsKey(Headers.WindowsIdentityName))
                return;

            var name = e.Message.Headers[Headers.WindowsIdentityName];

            if (name == null)
                return;

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(name), new string[0]);
        }
示例#4
0
        void OnTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            var transportMessage = e.Message;

            //send first so that we get the new id that we can use for retries
            MessageSender.Send(transportMessage,errorLogAddress);

            var message = new ProcessFaultMessage
            {
                FaultEnvelopeId = transportMessage.Id,
                Headers = transportMessage.Headers,
                Body = Encoding.UTF8.GetString(transportMessage.Body)//wil only work for text serialization
            };

            BackendUploader.Upload(message);
        }
示例#5
0
        void OnTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            var transportMessage = e.Message;
            var message = new ProcessAuditMessage
                              {
                                  MessageId = transportMessage.IdForCorrelation,
                                  Headers = transportMessage.Headers,
                                  AdditionalInformation = new Dictionary<string, string>()
                              };

            message.AdditionalInformation["MessageIntent"] = transportMessage.MessageIntent.ToString();
            message.AdditionalInformation["CorrelationId"] = transportMessage.CorrelationId;

            if (includeMessageBody)
                message.Body = transportMessage.Body;

            BackendUploader.Upload(message);
        }
示例#6
0
        void OnTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            var messageToDispatch = e.Message;

            var destinationSites = GetDestinationSitesFor(messageToDispatch);

            //if there is more than 1 destination we break it up into multiple messages
            if (destinationSites.Count() > 1)
            {
                foreach (var destinationSite in destinationSites)
                    CloneAndSendLocal(messageToDispatch, destinationSite);

                return;
            }

            var destination = destinationSites.FirstOrDefault();

            if (destination == null)
                throw new InvalidOperationException("No destination found for message");

            SendToSite(messageToDispatch, destination);
        }
示例#7
0
        void ExternalTransportTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            if (e.Message.MessageIntent == MessageIntentEnum.Publish)
            {
                if(!e.Message.Headers.ContainsKey(EnclosedMessageTypesMutator.EnclosedMessageTypes))
                    throw new InvalidOperationException("Enclosed message type header was not found in message");

                var types = e.Message.Headers[EnclosedMessageTypesMutator.EnclosedMessageTypes].Split(';');

                var subs = Subscribers.GetSubscriberAddressesForMessage(types.Select(s=> new MessageType(s)));

                Logger.Debug("Received notification from " + RemoteServer + ".");

                foreach(var s in subs)
                    InternalMessageSender.Send(e.Message, s);
            }
            else
            {
                ProxyData data = null;

                if (e.Message.CorrelationId != null)
                    data = Storage.GetAndRemove(e.Message.CorrelationId);

                if (data == null)
                    return;

                e.Message.CorrelationId = data.CorrelationId;

                Logger.Debug("Received response from " + RemoteServer + ".");

                InternalMessageSender.Send(e.Message, data.ClientAddress);
            }
        }
 static void Transport_TransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
 {
     if (ConfigureImpersonation.Impersonate)
         if (e.Message.Headers.ContainsKey(WindowsIdentityName))
             Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(e.Message.Headers[WindowsIdentityName]), new string[0]);
 }
示例#9
0
 void HandleMessageReceived(object sender, TransportMessageReceivedEventArgs e, ISatellite satellite)
 {
     try
     {
         satellite.Handle(e.Message);
     }
     catch (Exception ex)
     {
         Logger.ErrorFormat("{0} could not handle message. Exception: {1}", satellite.GetType().Name, ex.Message);
         throw;
     }
 }
示例#10
0
        void InternalTransportTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            if (UnicastBus.HandledSubscriptionMessage(e.Message, Subscribers, null))
            {
                e.Message.ReplyToAddress = ExternalAddress;
                ExternalMessageSender.Send(e.Message, RemoteServer);

                Logger.Debug("Received subscription message.");
                return;
            }

            var data = new ProxyData
                           {
                               Id = GenerateId(),
                               ClientAddress = e.Message.ReplyToAddress,
                               CorrelationId = e.Message.IdForCorrelation
                           };

            Storage.Save(data);

            Logger.Debug("Forwarding request to " + RemoteServer + ".");

            e.Message.IdForCorrelation = data.Id;
            e.Message.ReplyToAddress = ExternalAddress;

            ExternalMessageSender.Send(e.Message, RemoteServer);
        }
示例#11
0
        /// <summary>
        /// Handles reciept of a message on the bus to distribute for.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// This method checks whether a worker is available to handle the message and
        /// forwards it if one is found.
        /// </remarks>
        private void messageBusTransport_TransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            if (disabled)
                Rollback();

            var destination = WorkerManager.PopAvailableWorker();

            if (destination == null)
                Rollback();
            else
            {
                logger.Debug("Sending message to: " + destination);
                MessageSender.Send(e.Message, destination);
            }
        }
示例#12
0
        void ExternalTransportTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            if (e.Message.MessageIntent == MessageIntentEnum.Publish)
            {
                string val = null;
                foreach (var header in e.Message.Headers)
                    if (header.Key == UnicastBus.EnclosedMessageTypes)
                        val = header.Value;

                var types = UnicastBus.DeserializeEnclosedMessageTypes(val);

                var subs = Subscribers.GetSubscriberAddressesForMessage(types);

                Logger.Debug("Received notification from " + remoteServer + ".");

                foreach(var s in subs)
                    InternalMessageSender.Send(e.Message, s);
            }
            else
            {
                ProxyData data = null;

                if (e.Message.CorrelationId != null)
                    data = Storage.GetAndRemove(e.Message.CorrelationId);

                if (data == null)
                    return;

                e.Message.CorrelationId = data.CorrelationId;

                Logger.Debug("Received response from " + remoteServer + ".");

                InternalMessageSender.Send(e.Message, data.ClientAddress);
            }
        }
示例#13
0
        void AuditMessageQueueTransport_TransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            var message = e.Message;

            var messageBodyXml = System.Text.Encoding.UTF8.GetString(message.Body);
            RavenJObject jsonBody;

            if (messageBodyXml.StartsWith("["))
            {
                jsonBody = (RavenJObject) RavenJArray.Load(new JsonTextReader(new StreamReader(new MemoryStream(message.Body)))).Values().First();
            }
            else
            {
                var doc = new XmlDocument();
                doc.Load(new MemoryStream(message.Body));
                var firstMessageNode = doc.DocumentElement.ChildNodes.Cast<XmlNode>().First();
                var convertedJson = JsonConvert.SerializeXmlNode(firstMessageNode, Formatting.Indented, true);
                jsonBody = convertedJson != "null" ? RavenJObject.Parse(convertedJson) : null;
            }

            // Get the header list as a key value dictionary...
            Dictionary<string, string> headerDictionary = message.Headers.ToDictionary(k => k.Key, v => v.Value);

            var enclosedMessageType = headerDictionary["NServiceBus.EnclosedMessageTypes"];
            string messageType = enclosedMessageType;
            if (!String.IsNullOrWhiteSpace(enclosedMessageType))
            {
                messageType = enclosedMessageType.Split(new char[] { ',' }, StringSplitOptions.None)[0];
            }

            AuditMessage messageToStore = new AuditMessage
            {
                MessageId = message.Id,
                OriginalMessageId = message.GetOriginalId(),
                OriginalBody = messageBodyXml,
                Body = jsonBody,
                Headers = headerDictionary,
                ReplyToAddress = message.ReplyToAddress.ToString(),
                MessageType = messageType,
                ReceivedTime = DateTime.ParseExact(headerDictionary["NServiceBus.TimeSent"], "yyyy-MM-dd HH:mm:ss:ffffff Z", System.Globalization.CultureInfo.InvariantCulture)
            };

            // Save the message
            Console.WriteLine("Saving {0}", messageType);
            Persister.Persist(messageToStore);
        }
示例#14
0
        private void OnTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            dynamic response = new ExpandoObject();

            XmlMessageSerializer serializer = new XmlMessageSerializer(new MessageMapper());
            var message = serializer.Deserialize(new MemoryStream(e.Message.Body)).First();

            response.Endpoint = bus.InputAddress.Queue;
            response.Time = DateTime.UtcNow;
            response.type = message.GetType().ToString();
            response.body = message;
            response.headers = e.Message.Headers;


            _monitor.Invoke("MessageReceived", response);
        }
 void Transport_TransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
 {
     if (e.Message.Headers.ContainsKey(WINDOWSIDENTITYNAME))
         Thread.CurrentPrincipal = ConfigureImpersonation.Impersonate ? new GenericPrincipal(new GenericIdentity(e.Message.Headers[WINDOWSIDENTITYNAME]), new string[0]) : null;
 }
 void TransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
 {
     var message = e.Message.Body[0];
     _bus.SendLocal(message);
 }
示例#17
0
        void ErrorMessageTransport_TransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            var message = e.Message;

            // Forward this message to the storage queue.
            MessageForwarder.Send(message, errorStorageQueueAddress);

            // Get the xml content of the message that failed
            var doc = new XmlDocument();
            doc.Load(new MemoryStream(message.Body));
            var messageBodyXml = doc.InnerXml;

            // Get the header list as a key value dictionary...
            Dictionary<string, string> headerDictionary = message.Headers.ToDictionary(k => k.Key, v => v.Value);

            var processingFailedAddress = headerDictionary["NServiceBus.FailedQ"];
            var windowsIdentity = headerDictionary["WinIdName"];
            var originalId = headerDictionary["NServiceBus.OriginalId"];

            // Promoting the Processing Failed address, Windows Identity and the OriginalId from the dictionary
            // to the main interface to provide more clarity about the error.
            headerDictionary.Remove("NServiceBus.FailedQ");
            headerDictionary.Remove("WinIdName");
            headerDictionary.Remove("NServiceBus.OriginalId");

            var exceptionInfo = string.Format("{0} - {1} {2}", headerDictionary["NServiceBus.ExceptionInfo.ExceptionType"],
                headerDictionary["NServiceBus.ExceptionInfo.Message"],
                headerDictionary["NServiceBus.ExceptionInfo.StackTrace"]);

            ErrorMessageReceived errorEvent = Bus.CreateInstance<ErrorMessageReceived>(m =>
            {
                m.FailedMessageId = message.Id;
                m.OriginalMessageId = originalId;
                m.Headers = message.Headers;
                m.ProcessingFailedAddress = processingFailedAddress;
                m.ErrorReceivedTime = DateTime.ParseExact(headerDictionary["NServiceBus.TimeSent"], "yyyy-MM-dd HH:mm:ss:ffffff Z", System.Globalization.CultureInfo.InvariantCulture);
                m.Identity = windowsIdentity;
                m.Body = messageBodyXml;
                m.ExceptionInformation = exceptionInfo;
            });

            // Save the error in the persistent store
            ErrorPersister.SaveErrorMessage(errorEvent);

            // Publish event
            Bus.Publish(errorEvent);
        }