public void Welcome(long session, WelcomeDetails details) { mSession = session; Interlocked.CompareExchange(ref mIsConnected, 1, 0); mOpenTask.TrySetResult(true); OnConnectionEstablished(new WampSessionCreatedEventArgs (session, mSentDetails, details)); }
private void OnSessionCreated(object sender, WampSessionCreatedEventArgs e) { lock (mLock) { IWampSessionTerminator terminator = e.Terminator; WelcomeDetails welcomeDetails = e.WelcomeDetails; mSessionIdToDetails = mSessionIdToDetails.SetItem(e.SessionId, new SessionDetails(e.SessionId, e.WelcomeDetails, e.Terminator)); mAuthIdToTerminator = RecalculateAuthenticationDetails(mAuthIdToTerminator, welcomeDetails?.AuthenticationId, terminator); mAuthRoleToTerminator = RecalculateAuthenticationDetails(mAuthRoleToTerminator, welcomeDetails?.AuthenticationRole, terminator); } }
public override void Authenticate(string signature, AuthenticateExtraData extra) { if (signature == _mTicket) { IsAuthenticated = true; Authorizer = _authorizer; WelcomeDetails = new WelcomeDetails { AuthenticationProvider = "dynamic", AuthenticationRole = "user" }; } }
public override void Authenticate(string signature, AuthenticateExtraData extra) { if (_tokenValidator.Validate(signature)) { _sessionCache.AddSessionId(signature, _details.SessionId); IsAuthenticated = true; WelcomeDetails = new WelcomeDetails { AuthenticationRole = "Lykke client" }; Authorizer = TokenAuthorizer.Instance; } }
public override void Authenticate(string signature, AuthenticateExtraData extra) { if (_apiKeyValidator.ValidateAsync(signature).Result) { _sessionRepository.AddSessionId(signature, _details.SessionId); IsAuthenticated = true; WelcomeDetails = new WelcomeDetails { AuthenticationRole = "HFT client" }; Authorizer = TokenAuthorizer.Instance; } }
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); }
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); }
private void OnSessionCreated(object sender, WampSessionCreatedEventArgs e) { WelcomeDetails welcomeDetails = e.WelcomeDetails; WampSessionDetails sessionDetails = new WampSessionDetails() { Realm = mRealm.Name, Session = e.SessionId, AuthMethod = welcomeDetails.AuthenticationMethod ?? "anonymous", AuthId = welcomeDetails.AuthenticationId, AuthProvider = welcomeDetails.AuthenticationProvider, AuthRole = welcomeDetails.AuthenticationRole, TransportDetails = e.HelloDetails.TransportDetails }; ImmutableInterlocked.TryAdd(ref mSessionIdToDetails, e.SessionId, sessionDetails); mSubscriber.OnJoin(sessionDetails); }
private void OnSessionClosed(object sender, WampSessionCloseEventArgs e) { long sessionId = e.SessionId; lock (mLock) { if (mSessionIdToDetails.TryGetValue(sessionId, out var details)) { mSessionIdToDetails = mSessionIdToDetails.Remove(sessionId); WelcomeDetails welcomeDetails = details.WelcomeDetails; mAuthIdToTerminator = TryRemoveAuthData(mAuthIdToTerminator, welcomeDetails?.AuthenticationId, details.Terminator); mAuthRoleToTerminator = TryRemoveAuthData(mAuthRoleToTerminator, welcomeDetails?.AuthenticationRole, details.Terminator); } } }
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 void Hello(long session, HelloDetails helloDetails, WelcomeDetails welcomeDetails) { mRealmGate.Hello(session, helloDetails, welcomeDetails); }
public WelcomeDetailsInterceptor(WelcomeDetails welcomeDetails) { mWelcomeDetails = welcomeDetails; }
public void SetWelcomeDetails(WelcomeDetails welcomeDetails) { base.WelcomeDetails = welcomeDetails; }
public void WelcomeParametersArePassedToClient() { MockSessionAuthenticationFactory mockSessionAuthenticationFactory = new MockSessionAuthenticationFactory(); WampPendingClientDetails authenticatorFactoryParameters = null; mockSessionAuthenticationFactory.SetGetSessionAuthenticator ((clientDetails, transportAuthenticator) => { authenticatorFactoryParameters = clientDetails; MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator(); mockSessionAuthenticator.SetAuthenticationMethod("ticket"); mockSessionAuthenticator.SetAuthenticate((signature, extraData) => { mockSessionAuthenticator.SetAuthenticationId(clientDetails.HelloDetails.AuthenticationId); mockSessionAuthenticator.SetIsAuthenticated(true); mockSessionAuthenticator.SetWelcomeDetails(new MyWelcomeDetails() { AuthenticationProvider = "unittest", AuthenticationRole = "testee", Country = "United States of America" }); mockSessionAuthenticator.SetAuthorizer(new WampStaticAuthorizer(new List <WampUriPermissions>())); }); return(mockSessionAuthenticator); }); WampAuthenticationPlayground playground = new WampAuthenticationPlayground(mockSessionAuthenticationFactory); playground.Host.Open(); long? clientSessionId = null; WelcomeDetails clientWelcomeDetails = null; Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >(); clientMock.Setup(x => x.Welcome(It.IsAny <long>(), It.IsAny <WelcomeDetails>())) .Callback((long sessionId, WelcomeDetails details) => { clientSessionId = sessionId; clientWelcomeDetails = details; }); IWampServerProxy serverProxy = playground.CreateRawConnection(clientMock.Object); serverProxy.Hello("realm1", new HelloDetailsHack() { AuthenticationId = "joe", AuthenticationMethods = new string[] { "wampcra", "ticket" } }); serverProxy.Authenticate("Barack Hussein", new AuthenticateExtraData()); Assert.That(clientWelcomeDetails.AuthenticationMethod, Is.EqualTo("ticket")); Assert.That(clientWelcomeDetails.AuthenticationId, Is.EqualTo("joe")); Assert.That(clientWelcomeDetails.AuthenticationProvider, Is.EqualTo("unittest")); Assert.That(clientWelcomeDetails.AuthenticationRole, Is.EqualTo("testee")); Assert.That(clientSessionId, Is.EqualTo(authenticatorFactoryParameters.SessionId)); MyWelcomeDetails deserializedWelcomeDetails = clientWelcomeDetails.OriginalValue.Deserialize <MyWelcomeDetails>(); Assert.That(deserializedWelcomeDetails.Country, Is.EqualTo("United States of America")); }
public void Welcome(long session, WelcomeDetails details) { Send(mWelcome2, session, details); }
public WampSessionCreatedEventArgs(long sessionId, HelloDetails helloDetails, WelcomeDetails welcomeDetails, IWampSessionTerminator terminator) { SessionId = sessionId; HelloDetails = helloDetails; WelcomeDetails = welcomeDetails; Terminator = terminator; }
static async Task Main(string[] arguments) { DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(); IWampChannel channel = channelFactory.ConnectToRealm("realm1") .WebSocketTransport(new Uri("ws://127.0.0.1:8080/ws")) .JsonSerialization() .CraAuthentication("peter", "secret1") //.CraAuthentication("joe", "secret2") .Build(); channel.RealmProxy.Monitor.ConnectionEstablished += (sender, args) => { Console.WriteLine("connected session with ID " + args.SessionId); WelcomeDetails details = args.WelcomeDetails; Console.WriteLine($"authenticated using method '{details.AuthenticationMethod}' and provider '{details.AuthenticationProvider}'"); Console.WriteLine($"authenticated with authid '{details.AuthenticationId}' and authrole '{details.AuthenticationRole}'"); }; channel.RealmProxy.Monitor.ConnectionBroken += (sender, args) => { GoodbyeAbortDetails details = args.Details; Console.WriteLine($"disconnected {args.Reason} {details.Message}"); }; IWampRealmProxy realmProxy = channel.RealmProxy; await channel.Open().ConfigureAwait(false); // call a procedure we are allowed to call (so this should succeed) // IAdd2Service proxy = realmProxy.Services.GetCalleeProxy <IAdd2Service>(); try { var five = await proxy.Add2Async(2, 3); Console.WriteLine("call result {0}", five); } catch (Exception e) { Console.WriteLine("call error {0}", e); } // (try to) register a procedure where we are not allowed to (so this should fail) // Mul2Service service = new Mul2Service(); try { await realmProxy.Services.RegisterCallee(service) .ConfigureAwait(false); Console.WriteLine("huh, function registered!"); } catch (WampException ex) { Console.WriteLine("registration failed - this is expected: " + ex.ErrorUri); } // (try to) publish to some topics // string[] topics = { "com.example.topic1", "com.example.topic2", "com.foobar.topic1", "com.foobar.topic2" }; foreach (string topic in topics) { IWampTopicProxy topicProxy = realmProxy.TopicContainer.GetTopicByUri(topic); try { await topicProxy.Publish(new PublishOptions() { Acknowledge = true }, new object[] { "hello" }) .ConfigureAwait(false); Console.WriteLine("event published to topic " + topic); } catch (WampException ex) { Console.WriteLine("publication to topic " + topic + " failed: " + ex.ErrorUri); } } Console.ReadLine(); }
public void Hello(long sessionId, HelloDetails helloDetails, WelcomeDetails welcomeDetails) { RaiseSessionCreated(new WampSessionCreatedEventArgs(sessionId, helloDetails, welcomeDetails)); }
public void Welcome(long session, WelcomeDetails details) { SessionClient.Welcome(session, details); }
public SessionDetails(long session, WelcomeDetails welcomeDetails, IWampSessionTerminator terminator) { Terminator = terminator; Session = session; WelcomeDetails = welcomeDetails; }
public WampSessionCreatedEventArgs(long sessionId, HelloDetails helloDetails, WelcomeDetails welcomeDetails) { SessionId = sessionId; HelloDetails = helloDetails; mWelcomeDetails = welcomeDetails; }