Пример #1
0
        bool SendAccessControlMessage()
        {
            ClientAccessControl accessControl = AccessControl;

            if (accessControl == null)
            {
                return(true);
            }

            return(ToServer(accessControl.ObtainClientSideMessage(), null));
        }
Пример #2
0
        /// <summary>
        /// Is the supplied control under conditions of current control.
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public virtual bool IsAllowed(ClientAccessControl control)
        {
            if (string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(Password))
            {
                return(true);
            }

            if (control == null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(Username))
            {
                return(Password == control.Password);
            }

            return(Username == control.Username && Password == control.Password);
        }
Пример #3
0
        /// <summary>
        /// Is the supplied control under conditions of current control.
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public virtual bool IsAllowed(ClientAccessControl control)
        {
            if (string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(Password))
            {
                return true;
            }

            if (control == null)
            {
                return false;
            }

            if (string.IsNullOrEmpty(Username))
            {
                return Password == control.Password;
            }

            return Username == control.Username && Password == control.Password;
        }
Пример #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="nameAppending">Additional part to the default named bus (name is {endpoint} + "MessageBus.Proxy" + {appending}).</param>
        /// <param name="accessControl">Control acces to remote server (user and pass if required), pass null for no login.</param>
        public ClientMessageBus(IPEndPoint endpoint, string nameAppendix, ClientAccessControl accessControl)
            : base(endpoint.ToString() + " MessageBus.Proxy " + nameAppendix)
        {
            AccessControl = accessControl;

            _socketClient = new SocketMessageClient(endpoint, base.Serializer);

            _socketClient.ConnectedEvent         += new SocketCommunicator.HelperUpdateDelegate(_messageClient_ConnectedEvent);
            _socketClient.DisconnectedEvent      += new SocketCommunicator.HelperUpdateDelegate(_messageClient_DisconnectedEvent);
            _socketClient.MessageReceivedEvent   += new SocketCommunicator.MessageUpdateDelegate(_messageClient_MessageReceivedEvent);
            _socketClient.SendAsyncCompleteEvent += new SocketCommunicator.AsyncMessageSendDelegate(_messageClient_SendAsyncCompleteEvent);

            _socketClient.AutoReconnect = true;
            _socketClient.KeepAlive     = true;

            base.ClientAddedEvent   += new global::Matrix.Framework.MessageBus.Core.MessageBusClientUpdateDelegate(MessageBusNetClient_ClientAddedEvent);
            base.ClientRemovedEvent += new global::Matrix.Framework.MessageBus.Core.MessageBusClientRemovedDelegate(MessageBusNetClient_ClientRemovedEvent);

            ApplicationLifetimeHelper.ApplicationClosingEvent += new CommonHelper.DefaultDelegate(ApplicationLifetimeHelper_ApplicationClosingEvent);
        }
Пример #5
0
        ClientAccessControl ObtainClientAccessControl(int clientId)
        {
            if (clientId < 0)
            {
                return(null);
            }

            ClientAccessControl result;

            lock (_syncRoot)
            {
                if (_clientsAccessControl.TryGetValue(clientId, out result) == false)
                {
                    result = new ClientAccessControl();
                    _clientsAccessControl.Add(clientId, result);
                }
            }

            return(result);
        }
Пример #6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="nameAppending">Additional part to the default named bus (name is {endpoint} + "MessageBus.Proxy" + {appending}).</param>
        /// <param name="accessControl">Control acces to remote server (user and pass if required), pass null for no login.</param>
        public ClientMessageBus(IPEndPoint endpoint, string nameAppendix, ClientAccessControl accessControl)
            : base(endpoint.ToString() + " MessageBus.Proxy " + nameAppendix)
        {
            AccessControl = accessControl;

            _socketClient = new SocketMessageClient(endpoint, base.Serializer);

            _socketClient.ConnectedEvent += new SocketCommunicator.HelperUpdateDelegate(_messageClient_ConnectedEvent);
            _socketClient.DisconnectedEvent += new SocketCommunicator.HelperUpdateDelegate(_messageClient_DisconnectedEvent);
            _socketClient.MessageReceivedEvent += new SocketCommunicator.MessageUpdateDelegate(_messageClient_MessageReceivedEvent);
            _socketClient.SendAsyncCompleteEvent += new SocketCommunicator.AsyncMessageSendDelegate(_messageClient_SendAsyncCompleteEvent);

            _socketClient.AutoReconnect = true;
            _socketClient.KeepAlive = true;

            base.ClientAddedEvent += new global::Matrix.Framework.MessageBus.Core.MessageBusClientUpdateDelegate(MessageBusNetClient_ClientAddedEvent);
            base.ClientRemovedEvent += new global::Matrix.Framework.MessageBus.Core.MessageBusClientRemovedDelegate(MessageBusNetClient_ClientRemovedEvent);

            ApplicationLifetimeHelper.ApplicationClosingEvent += new CommonHelper.DefaultDelegate(ApplicationLifetimeHelper_ApplicationClosingEvent);
        }
Пример #7
0
        void _server_ClientMessageReceivedEvent(SocketMessageServer server, SocketCommunicatorEx client, object message)
        {
            ServerAccessControl accessControl = AccessControl;

            // Check security first.
            if (accessControl != null && message is AccessMessage == false)
            {
                if (accessControl.IsAllowed(ObtainClientAccessControl(client.Id)) == false)
                {
#if Matrix_Diagnostics
                    InstanceMonitor.Info("Message [" + message.ToString() + "] from client [" + client.ToString() + "] not allowed due to access control.", TracerItem.PriorityEnum.Medium);
#endif
                    return;
                }
            }

            if (message is EnvelopeMessage)
            {// Envelope user message.
                EnvelopeMessage envelopeMessage = (EnvelopeMessage)message;

                // Remove the remote message bus index association.
                envelopeMessage.Sender.LocalMessageBusIndex = ClientId.InvalidMessageBusClientIndex;

                foreach (ClientId id in envelopeMessage.Receivers)
                {
                    // Assign the id as local id, if it is, otherwise skip it.
                    id.LocalMessageBusIndex = base.GetClientIndexByGuid(id.Guid);
                    if (id.IsMessageBusIndexValid)
                    {
                        id.MessageBus = this;
                        if (DoSendToClient(envelopeMessage.Sender, id, envelopeMessage.Envelope, null) != SendToClientResultEnum.Success)
                        {
#if Matrix_Diagnostics
                            InstanceMonitor.OperationError(string.Format("Failed to accept envelope message [{0}].", envelopeMessage.ToString()));
#endif
                        }
                    }
                    else
                    {
#if Matrix_Diagnostics
                        InstanceMonitor.OperationError(string.Format("Failed to accept envelope message [{0}] due unrecognized receiver id.", envelopeMessage.ToString()));
#endif
                    }
                }
            }
            else if (message is ClientsListMessage)
            {// Message bus system message.
                ClientsListMessage updateMessage = (ClientsListMessage)message;
                for (int i = 0; i < updateMessage.Ids.Count; i++)
                {
                    RegisterClientId(client.Id, updateMessage.Ids[i], updateMessage.Types[i], updateMessage.SourcesTypes[i]);
                }
            }
            else if (message is RequestClientListUpdateMessage)
            {
                SendClientsUpdate(client.Id);
            }
            else if (message is ClientUpdateMessage)
            {
                ClientUpdateMessage updateMessage = (ClientUpdateMessage)message;

                bool validClient;
                lock (_syncRoot)
                {
                    validClient = _remoteClientNetId.ContainsKey(updateMessage.ClientId);
                }

                if (validClient)
                {
                    RaiseClientAddedEvent(updateMessage.ClientId);
                }
                else
                {
#if Matrix_Diagnostics
                    InstanceMonitor.OperationError(string.Format("Failed to raise update event for client [{0}], since client not found.", updateMessage.ClientId.ToString()));
#endif
                }
            }
            else if (message is AccessMessage)
            {
                ClientAccessControl control = ObtainClientAccessControl(client.Id);
                if (control != null)
                {
                    control.Update(message as AccessMessage);
                }
            }
            else if (message is StateUpdateMessage)
            {
                RaiseCounterPartyUpdateEvent("Client:" + client.Id.ToString(), ((StateUpdateMessage)message).State.ToString());
            }
            else
            {
#if Matrix_Diagnostics
                InstanceMonitor.Warning(string.Format("Message [{0}] not recognized.", message.GetType().Name));
#endif
            }
        }
Пример #8
0
        ClientAccessControl ObtainClientAccessControl(int clientId)
        {
            if (clientId < 0)
            {
                return null;
            }

            ClientAccessControl result;
            lock (_syncRoot)
            {
                if (_clientsAccessControl.TryGetValue(clientId, out result) == false)
                {
                    result = new ClientAccessControl();
                    _clientsAccessControl.Add(clientId, result);
                }
            }

            return result;
        }