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); } }
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; }
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); }
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); }
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); }
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); } } }
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); }
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); } }
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); }
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); } }
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); } }
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); } }
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); }
protected void OnClientJoin(IWampClientProxy <TMessage> wampClient, HelloDetails details) { WelcomeDetails welcomeDetails = GetWelcomeDetails(wampClient); wampClient.WelcomeDetails = welcomeDetails; wampClient.Realm.Hello(wampClient); wampClient.Welcome(wampClient.Session, welcomeDetails); }
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); }
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); }
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(); } } }
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); }
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); }
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); } }
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); } } }
public RemoteWampTopicSubscriber(long subscriptionId, IWampSubscriber subscriber) { mSubscriber = subscriber as IWampClientProxy; mSubscriptionId = subscriptionId; }
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); }