Пример #1
0
        public void CheckHandshake(HandshakingEvent ev)
        {
            // Based on the (client side) authentication Howto at http://cometd.org/documentation/howtos/authentication
            // If we have credentials, then they are transferred via "ext"
            // ext will be a Dictionary<string,object> with a key, "authentication"
            // authentication will be a Dictionary<string,object> with two keys, "user" and "credentials"

            var authenticationDictionary = ev.Handshake.GetExt <Dictionary <string, object> >("authentication");

            object user;
            object credentials;

            if (authenticationDictionary != null &&
                authenticationDictionary.TryGetValue("user", out user) &&
                authenticationDictionary.TryGetValue("credentials", out credentials))
            {
                if (user is string && credentials.Equals("password"))
                {
                    AuthenticatedClient authenticatedClient = (AuthenticatedClient)ev.Client;
                    authenticatedClient.Username = (string)user;
                    authenticatedClient.Password = (string)credentials;
                    return;
                }

                ev.CancellationReason = "Incorrect username or password";
            }
            else
            {
                ev.CancellationReason = "Credentials not supplied";
            }

            ev.Cancel = true;
            ev.Retry  = false;
        }
        public MessageHandlerResult HandleMessage(Message request)
        {
            IClient client = CreateClient();

            HandshakingEvent handshakingEvent = new HandshakingEvent(client, request);

            EventHub.Publish(handshakingEvent);

            if (handshakingEvent.Cancel)
            {
                return(new MessageHandlerResult
                {
                    Message = GetFailedHandshakeResponse(request, handshakingEvent.CancellationReason, handshakingEvent.Retry),
                    CanTreatAsLongPoll = false
                });
            }

            this.clientWorkflowManager.RegisterClient(client);

            HandshakenEvent handshakenEvent = new HandshakenEvent(client);

            EventHub.Publish(handshakenEvent);

            return(new MessageHandlerResult {
                Message = GetSuccessfulResponse(request, client), CanTreatAsLongPoll = false
            });
        }
Пример #3
0
        public MessageHandlerResult HandleMessage(Message request)
        {
            Client client = CreateClient();

            var handshakingEvent = new HandshakingEvent(client, request);

            EventHub.Publish(handshakingEvent);
            if (handshakingEvent.Cancel)
            {
                clientRepository.RemoveByID(client.ID);
                return(new MessageHandlerResult
                {
                    Message = GetFailedHandshakeResponse(request, handshakingEvent.CancellationReason, handshakingEvent.Retry),
                    ShouldWait = false
                });
            }

            var handshakenEvent = new HandshakenEvent(client);

            EventHub.Publish(handshakenEvent);

            return(new MessageHandlerResult {
                Message = GetSuccessfulResponse(request, client), ShouldWait = false
            });
        }
Пример #4
0
        public void CheckHandshake(HandshakingEvent ev)
        {
            // Based on the (client side) authentication Howto at http://cometd.org/documentation/howtos/authentication
            // If we have credentials, then they are transferred via "ext"
            // ext will be a Dictionary<string,object> with a key, "authentication"
            // authentication will be a Dictionary<string,object> with two keys, "user" and "credentials"

            // Note, the following lines could be collapsed in to one giant if() statement, but they are expanded for clarity
            if (ev.Handshake.ext is Dictionary <string, object> )
            {
                Dictionary <string, object> dictExt = (Dictionary <string, object>)ev.Handshake.ext;
                if (dictExt.ContainsKey("authentication") &&
                    dictExt["authentication"] is Dictionary <string, object> )
                {
                    Dictionary <string, object> dictAuth = (Dictionary <string, object>)dictExt["authentication"];
                    // Authenticate the client
                    if (dictAuth["user"] is string)
                    {
                        AuthenticatedClient authClient = (AuthenticatedClient)ev.Client;
                        authClient.username = (string)dictAuth["user"];
                        return;
                    }
                    else
                    {
                        ev.CancellationReason = "Incorrect username";
                    }
                }
            }

            // If we got this far, we couldn't authenticate
            if (ev.CancellationReason == null)
            {
                ev.CancellationReason = "Credentials not supplied";
            }
            ev.Cancel = true;
            ev.Retry  = false;
        }