public override void Authenticate(IWampSessionClient client, string signature, AuthenticateExtraData extra)
        {
            IWampClientProxy <TMessage> wampClient = client as IWampClientProxy <TMessage>;

            IWampSessionAuthenticator authenticator = wampClient.Authenticator;

            try
            {
                authenticator.Authenticate(signature, extra);

                if (authenticator.IsAuthenticated)
                {
                    OnClientAuthenticated(wampClient, wampClient.HelloDetails);
                }
                else
                {
                    SendAbort(client,
                              new WampAuthenticationException(new AbortDetails(),
                                                              WampErrors.AuthorizationFailed));
                }
            }
            catch (WampAuthenticationException ex)
            {
                SendAbort(client, ex);
            }
        }
Beispiel #2
0
        public void Hello(IWampClientProxy <TMessage> session)
        {
            IWampSessionTerminator terminator =
                new WampSessionClientTerminator <TMessage>(session);

            mRealmGate.Hello(session.Session, session.HelloDetails, session.WelcomeDetails, terminator);
        }
            public RemoteObserver(IWampRawClient client)
            {
                mClient = client;
                IWampClientProxy casted = mClient as IWampClientProxy;

                mSessionId = casted.Session;
            }
Beispiel #4
0
        public IWampClientProxy <TMessage> Create(IMessagePlayer <TMessage> player,
                                                  IMessageRecorder <TMessage> recorder,
                                                  WampMessage <TMessage> welcomeMessage)
        {
            ProxyGenerationOptions options =
                new ProxyGenerationOptions();

            options.Selector = new MockClientInterceptorSelector();

            IWampFormatter <TMessage> formatter = mBinding.Formatter;

            long           sessionId      = formatter.Deserialize <long>(welcomeMessage.Arguments[0]);
            WelcomeDetails welcomeDetails = formatter.Deserialize <WelcomeDetails>(welcomeMessage.Arguments[1]);


            IWampClientProxy <TMessage> result =
                mGenerator.CreateInterfaceProxyWithoutTarget
                    (typeof(IWampClientProxy),
                    new[]
            {
                typeof(IWampClientProxy <TMessage>),
                typeof(IWampConnectionMonitor)
            },
                    options,
                    new RecordAndPlayRawInterceptor <TMessage>(player, recorder, mBinding),
                    new RecordAndPlayInterceptor <TMessage>
                        (mOutgoingSerializer, player, recorder, mBinding),
                    new SessionPropertyInterceptor(sessionId),
                    new WelcomeDetailsInterceptor(welcomeDetails))
                as IWampClientProxy <TMessage>;

            return(result);
        }
Beispiel #5
0
        private static MockClient <IWampClientProxy <MockRaw> > GetPublisher(Type scenario, WampMockClientBuilder <MockRaw> builder, IEnumerable <WampMessage <MockRaw> > calls)
        {
            WampMessage <MockRaw> welcome =
                GetCalls(scenario, Channel.BrokerToPublisher,
                         new WampMessageType[] { WampMessageType.v2Welcome })
                .FirstOrDefault();

            long sessionId = (long)welcome.Arguments[0].Value;

            NullPlayer <MockRaw> nullPlayer =
                new NullPlayer <MockRaw>();

            IMessageRecorder <MockRaw> recorder =
                new ResponsiveMessageRecorder(calls,
                                              new Dictionary <WampMessageType, string>()
            {
                { WampMessageType.v2Published, "publicationId" }
            });

            IWampClientProxy <MockRaw> built =
                builder.Create(nullPlayer,
                               recorder,
                               welcome);

            MockClient <IWampClientProxy <MockRaw> > result =
                new MockClient <IWampClientProxy <MockRaw> >(built, recorder);

            return(result);
        }
Beispiel #6
0
        private static MockClient <IWampClientProxy <MockRaw> > GetSubscriber(Type scenario, WampMockClientBuilder <MockRaw> clientBuilder, IWampIncomingMessageHandler <MockRaw, IWampClientProxy <MockRaw> > handler, IEnumerable <WampMessage <MockRaw> > calls)
        {
            WampMessage <MockRaw> welcome =
                GetCalls(scenario, Channel.BrokerToSubscriber,
                         new WampMessageType[] { WampMessageType.v2Welcome })
                .FirstOrDefault();

            // TODO: After enough events unsubscribe.
            NullPlayer <MockRaw> nullPlayer =
                new NullPlayer <MockRaw>();

            IMessageRecorder <MockRaw> recorder =
                new ResponsiveMessageRecorder(calls,
                                              new Dictionary <WampMessageType, string>()
            {
                { WampMessageType.v2Subscribed, "subscriptionId" }
            });

            IWampClientProxy <MockRaw> built =
                clientBuilder.Create(nullPlayer,
                                     recorder,
                                     welcome);

            MockClient <IWampClientProxy <MockRaw> > result =
                new MockClient <IWampClientProxy <MockRaw> >(built, recorder);

            return(result);
        }
Beispiel #7
0
            private void RemoveAuthenticationData(IWampClientProxy <TMessage> client)
            {
                WelcomeDetails welcomeDetails = client.Authenticator?.WelcomeDetails;

                if (welcomeDetails != null)
                {
                    string       authenticationId   = welcomeDetails.AuthenticationId;
                    string       authenticationRole = welcomeDetails.AuthenticationRole;
                    Subscription subscription       = new Subscription(mRawTopic, client, null);

                    if (authenticationId != null)
                    {
                        RemoveIdToSubscription(ref mAuthenticationIdToSubscription,
                                               authenticationId,
                                               subscription);
                    }

                    if (authenticationRole != null)
                    {
                        RemoveIdToSubscription(ref mAuthenticationRoleToSubscription,
                                               authenticationRole,
                                               subscription);
                    }
                }
            }
Beispiel #8
0
 public void OnClientDisconnect(IWampClientProxy <TMessage> client)
 {
     if ((client.Realm != null) && !client.GoodbyeSent)
     {
         client.Realm.SessionLost(client.Session);
     }
 }
        private MockClient <IWampClientProxy <MockRaw> > GetCallee(Type scenario, WampMockClientBuilder <MockRaw> clientBuilder, IWampIncomingMessageHandler <MockRaw, IWampClientProxy <MockRaw> > handler)
        {
            WampMessage <MockRaw> welcome =
                GetCalls(scenario, Channel.DealerToCallee,
                         new WampMessageType[] { WampMessageType.v2Welcome })
                .FirstOrDefault();

            IEnumerable <WampMessage <MockRaw> > calls =
                GetCalls(scenario, Channel.CalleeToDealer, MessageTypes.Rpc).Concat
                    (GetCalls(scenario, Channel.DealerToCallee, MessageTypes.Rpc)).ToList();

            CalleeMessagePlayer player =
                new CalleeMessagePlayer(calls,
                                        new[] { WampMessageType.v2Invocation },
                                        handler);

            IMessageRecorder <MockRaw> recorder =
                new ResponsiveMessageRecorder(calls,
                                              new Dictionary <WampMessageType, string>()
            {
                { WampMessageType.v2Registered, "registrationId" }
            });

            IWampClientProxy <MockRaw> built =
                clientBuilder.Create(player,
                                     recorder,
                                     welcome);

            player.Client = built;

            MockClient <IWampClientProxy <MockRaw> > result =
                new MockClient <IWampClientProxy <MockRaw> >(built, recorder);

            return(result);
        }
        private void OnClientAuthenticated(IWampClientProxy <TMessage> wampClient, HelloDetails details)
        {
            if (wampClient.Authorizer == null)
            {
                throw new ArgumentException("Authenticator.Authorizer not set.");
            }

            OnClientJoin(wampClient, details);
        }
Beispiel #11
0
        public virtual void Goodbye(IWampSessionClient client, GoodbyeDetails details, string reason)
        {
            IWampClientProxy <TMessage> wampClient = client as IWampClientProxy <TMessage>;

            if (!wampClient.GoodbyeSent)
            {
                wampClient.SendGoodbye(details, WampErrors.CloseNormal);
            }
        }
Beispiel #12
0
            public bool Unsubscribe(IWampClientProxy <TMessage> client)
            {
                bool result;

                ImmutableHashSetInterlocked.Remove(ref mRemoteObservers, new RemoteObserver(client));
                result = ImmutableInterlocked.TryRemove(ref mSessionIdToSubscription, client.Session, out Subscription subscription);
                RemoveAuthenticationData(client);
                return(result);
            }
Beispiel #13
0
 public static void SendGoodbye <TMessage>(this IWampClientProxy <TMessage> clientProxy, GoodbyeDetails details, string reason)
 {
     using (clientProxy as IDisposable)
     {
         clientProxy.GoodbyeSent = true;
         clientProxy.Goodbye(details, reason);
         clientProxy.Realm.Goodbye(clientProxy.Session, details, reason);
     }
 }
Beispiel #14
0
        public virtual void Abort(IWampSessionClient client, AbortDetails details, string reason)
        {
            using (IDisposable disposable = client as IDisposable)
            {
                IWampClientProxy <TMessage> wampClient = client as IWampClientProxy <TMessage>;

                wampClient.GoodbyeSent = true;
                wampClient.Realm.Abort(wampClient.Session, details, reason);
            }
        }
Beispiel #15
0
        protected override void OnNewConnection(IWampConnection <TMessage> connection)
        {
            base.OnNewConnection(connection);

            IWampClientProxy <TMessage> client = ClientContainer.GetClient(connection);

            mLogger.DebugFormat("Client connected, session id: {SessionId}", client.Session);

            mSessionHandler.OnNewClient(client);
        }
        public virtual void Goodbye(IWampSessionClient client, GoodbyeDetails details, string reason)
        {
            using (IDisposable disposable = client as IDisposable)
            {
                client.Goodbye(details, WampErrors.CloseNormal);

                IWampClientProxy <TMessage> wampClient = client as IWampClientProxy <TMessage>;
                wampClient.GoodbyeSent = true;
                wampClient.Realm.Goodbye(wampClient.Session, details, reason);
            }
        }
Beispiel #17
0
        protected override object GetInstance(IWampClientProxy <TMessage> client, WampSharp.Core.Message.WampMessage <TMessage> message, WampMethodInfo method)
        {
            IWampBindedRealm <TMessage> realm = client.Realm;

            if (realm == null)
            {
                return(base.GetInstance(client, message, method));
            }

            return(realm.Server);
        }
Beispiel #18
0
        protected void OnClientJoin(IWampClientProxy <TMessage> wampClient,
                                    HelloDetails details)
        {
            WelcomeDetails welcomeDetails = GetWelcomeDetails(wampClient);

            wampClient.WelcomeDetails = welcomeDetails;

            wampClient.Realm.Hello(wampClient);

            wampClient.Welcome(wampClient.Session, welcomeDetails);
        }
Beispiel #19
0
        protected IWampClientProxy <TMessage> GetWampClient(IWampSessionClient client, string realm, HelloDetails details)
        {
            IWampClientProxy <TMessage> wampClient = client as IWampClientProxy <TMessage>;

            IWampBindedRealm <TMessage> bindedRealm = RealmContainer.GetRealmByName(realm);

            wampClient.HelloDetails = details;

            details.TransportDetails = wampClient.TransportDetails;

            wampClient.Realm = bindedRealm;

            return(wampClient);
        }
        protected override WelcomeDetails GetWelcomeDetails(IWampClientProxy <TMessage> wampClient)
        {
            WelcomeDetails welcomeDetails =
                base.GetWelcomeDetails(wampClient);

            IWampSessionAuthenticator authenticator = wampClient.Authenticator;

            WelcomeDetails result =
                authenticator.WelcomeDetails ?? welcomeDetails;

            result.Roles = welcomeDetails.Roles;
            result.AuthenticationMethod = authenticator.AuthenticationMethod;
            result.AuthenticationId     = authenticator.AuthenticationId;

            return(result);
        }
Beispiel #21
0
        private PublishOptions GetPublishOptions(IWampPublisher publisher, string topicUri, PublishOptions options)
        {
            IWampClientProxy casted = publisher as IWampClientProxy;

            PublishOptionsExtended result = new PublishOptionsExtended(options);

            result.PublisherId = casted.Session;

            WelcomeDetails welcomeDetails = casted.WelcomeDetails;

            result.AuthenticationId   = welcomeDetails.AuthenticationId;
            result.AuthenticationRole = welcomeDetails.AuthenticationRole;

            result.TopicUri = topicUri;

            return(result);
        }
Beispiel #22
0
        public void Unsubscribe(IUnsubscribeRequest <TMessage> request)
        {
            IWampClientProxy <TMessage> client = request.Client;

            if (mSubscriberBook.Unsubscribe(client))
            {
                this.RaiseSubscriptionRemoving(client.Session);

                request.Unsubscribed();

                this.RaiseSubscriptionRemoved(client.Session);

                if (!this.HasSubscribers)
                {
                    this.RaiseTopicEmpty();
                }
            }
        }
Beispiel #23
0
        private InvocationDetails GetInvocationOptions(IWampCaller caller, CallOptions options, string procedureUri)
        {
            IWampClientProxy wampCaller = caller as IWampClientProxy;

            InvocationDetailsExtended result = new InvocationDetailsExtended
            {
                CallerSession = wampCaller.Session,
                CallerOptions = options,
                ProcedureUri  = procedureUri
            };

            WelcomeDetails welcomeDetails = wampCaller.WelcomeDetails;

            result.AuthenticationId   = welcomeDetails.AuthenticationId;
            result.AuthenticationRole = welcomeDetails.AuthenticationRole;

            return(result);
        }
Beispiel #24
0
            public RemoteObserver Subscribe(IWampClientProxy <TMessage> client)
            {
                Subscription subscription;

                if (!mSessionIdToSubscription.TryGetValue(client.Session, out subscription))
                {
                    RemoteObserver result = new RemoteObserver(client);

                    ImmutableHashSetInterlocked.Add(ref mRemoteObservers, result);

                    subscription = new Subscription(mRawTopic, client, result);

                    ImmutableInterlocked.TryAdd(ref mSessionIdToSubscription, client.Session, subscription);

                    subscription.Open();
                }

                return(subscription.Observer);
            }
        public override void Hello(IWampSessionClient client, string realm, HelloDetails details)
        {
            IWampClientProxy <TMessage> wampClient = GetWampClient(client, realm, details);

            WampPendingClientDetails clientDetails = new WampPendingClientDetails()
            {
                HelloDetails = details,
                Realm        = realm,
                SessionId    = wampClient.Session
            };

            try
            {
                IWampSessionAuthenticator authenticator =
                    mSessionAuthenticatorFactory.GetSessionAuthenticator
                        (clientDetails,
                        wampClient.Authenticator);

                if (authenticator == null)
                {
                    throw new Exception("Get null authenticator.");
                }

                wampClient.Authenticator = authenticator;

                bool authenticated = authenticator.IsAuthenticated;

                if (authenticated)
                {
                    OnClientAuthenticated(wampClient, details);
                }
                else
                {
                    wampClient.Challenge(authenticator.AuthenticationMethod,
                                         authenticator.ChallengeDetails);
                }
            }
            catch (WampAuthenticationException ex)
            {
                SendAbort(client, ex);
            }
        }
        private static MockClient <IWampClientProxy <MockRaw> > GetCaller(Type scenario, WampMockClientBuilder <MockRaw> builder)
        {
            WampMessage <MockRaw> welcome =
                GetCalls(scenario, Channel.DealerToCaller,
                         new WampMessageType[] { WampMessageType.v2Welcome })
                .FirstOrDefault();

            NullPlayer <MockRaw> nullPlayer =
                new NullPlayer <MockRaw>();

            IMessageRecorder <MockRaw> messageRecorder =
                new MessageRecorder <MockRaw>();

            IWampClientProxy <MockRaw> built =
                builder.Create(nullPlayer,
                               messageRecorder,
                               welcome);

            MockClient <IWampClientProxy <MockRaw> > result =
                new MockClient <IWampClientProxy <MockRaw> >(built, messageRecorder);

            return(result);
        }
Beispiel #27
0
        public void Subscribe(ISubscribeRequest <TMessage> request, SubscribeOptions options)
        {
            RemoteWampTopicSubscriber remoteSubscriber =
                new RemoteWampTopicSubscriber(this.SubscriptionId,
                                              request.Client as IWampSubscriber);

            IWampClientProxy <TMessage> client = request.Client;

            RemoteObserver observer = mSubscriberBook.Subscribe(client);

            if (!observer.IsOpen)
            {
                this.RaiseSubscriptionAdding(remoteSubscriber, options);
            }

            request.Subscribed(this.SubscriptionId);

            if (!observer.IsOpen)
            {
                observer.Open();

                this.RaiseSubscriptionAdded(remoteSubscriber, options);
            }
        }
Beispiel #28
0
            private void AddAuthenticationData(IWampClientProxy <TMessage> client, Subscription subscription)
            {
                WelcomeDetails welcomeDetails = client.Authenticator?.WelcomeDetails;

                if (welcomeDetails != null)
                {
                    string authenticationId   = welcomeDetails.AuthenticationId;
                    string authenticationRole = welcomeDetails.AuthenticationRole;

                    if (authenticationId != null)
                    {
                        MapIdToSubscription(ref mAuthenticationIdToSubscription,
                                            authenticationId,
                                            subscription);
                    }

                    if (authenticationRole != null)
                    {
                        MapIdToSubscription(ref mAuthenticationRoleToSubscription,
                                            authenticationRole,
                                            subscription);
                    }
                }
            }
Beispiel #29
0
 public RemoteWampTopicSubscriber(long subscriptionId, IWampSubscriber subscriber)
 {
     mSubscriber     = subscriber as IWampClientProxy;
     mSubscriptionId = subscriptionId;
 }
Beispiel #30
0
 public void Error(IWampClientProxy client, int requestType, long requestId, TMessage details, string error, TMessage[] arguments,
                   TMessage argumentsKeywords)
 {
     mHandler.Error(client, requestId, details, error, arguments, argumentsKeywords);
 }