public void HelloParametersArePassedToAuthenticationFactory() { MockSessionAuthenticationFactory mockSessionAuthenticationFactory = new MockSessionAuthenticationFactory(); WampPendingClientDetails authenticatorFactoryParameters = null; mockSessionAuthenticationFactory.SetGetSessionAuthenticator ((clientDetails, transportAuthenticator) => { authenticatorFactoryParameters = clientDetails; IWampSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator(); return(mockSessionAuthenticator); }); WampAuthenticationPlayground playground = new WampAuthenticationPlayground(mockSessionAuthenticationFactory); playground.Host.Open(); IWampServerProxy serverProxy = playground.CreateRawConnection(new Mock <IWampClient <JToken> >().Object); serverProxy.Hello("realm1", new HelloDetailsHack() { AuthenticationId = "joe", AuthenticationMethods = new string[] { "wampcra", "ticket" } }); Assert.That(authenticatorFactoryParameters.Realm, Is.EqualTo("realm1")); Assert.That(authenticatorFactoryParameters.HelloDetails.AuthenticationMethods, Is.EquivalentTo(new[] { "wampcra", "ticket" })); Assert.That(authenticatorFactoryParameters.HelloDetails.AuthenticationId, Is.EqualTo("joe")); }
public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator) { if (details.HelloDetails.AuthenticationMethods.Contains(AuthMethods.Ticket)) { return(new TicketSessionAuthenticator(details, _apiKeyValidator, _sessionRepository)); } return(new AnonymousWampSessionAuthenticator()); }
public void ExceptionOnAuthenticateRaisesAbort() { MockSessionAuthenticationFactory mockSessionAuthenticationFactory = new MockSessionAuthenticationFactory(); WampPendingClientDetails authenticatorFactoryParameters = null; mockSessionAuthenticationFactory.SetGetSessionAuthenticator ((clientDetails, transportAuthenticator) => { authenticatorFactoryParameters = clientDetails; MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator(); mockSessionAuthenticator.SetAuthenticationMethod("ticket"); mockSessionAuthenticator.SetAuthenticate((signature, extraData) => throw new WampAuthenticationException(new MyAbortDetails() { Message = "aborted!", Year = 2015 }, "com.myapp.abortreason")); return(mockSessionAuthenticator); }); WampAuthenticationPlayground playground = new WampAuthenticationPlayground(mockSessionAuthenticationFactory); playground.Host.Open(); string clientReason = null; AbortDetails clientAbortDetails = null; Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >(); clientMock.Setup(x => x.Abort(It.IsAny <AbortDetails>(), It.IsAny <string>())) .Callback((AbortDetails details, string reason) => { clientReason = reason; clientAbortDetails = 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(clientReason, Is.EqualTo("com.myapp.abortreason")); Assert.That(clientAbortDetails.Message, Is.EqualTo("aborted!")); var deserialized = clientAbortDetails.OriginalValue.Deserialize <MyAbortDetails>(); Assert.That(deserialized.Year, Is.EqualTo(2015)); }
public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator) { if (!transportAuthenticator.IsAuthenticated) { throw new WampAuthenticationException("Cookie wasn't present"); } return(transportAuthenticator); }
public TicketSessionAuthenticator( [NotNull] WampPendingClientDetails details, [NotNull] ITokenValidator sessionService, [NotNull] ISessionCache sessionCache) { _details = details ?? throw new ArgumentNullException(nameof(details)); _tokenValidator = sessionService ?? throw new ArgumentNullException(nameof(sessionService)); _sessionCache = sessionCache ?? throw new ArgumentNullException(nameof(sessionCache)); AuthenticationId = details.HelloDetails.AuthenticationId; }
public TicketSessionAuthenticator( [NotNull] WampPendingClientDetails details, [NotNull] IApiKeyValidator apiKeyValidator, [NotNull] ISessionRepository sessionRepository) { _details = details ?? throw new ArgumentNullException(nameof(details)); _apiKeyValidator = apiKeyValidator ?? throw new ArgumentNullException(nameof(apiKeyValidator)); _sessionRepository = sessionRepository ?? throw new ArgumentNullException(nameof(sessionRepository)); AuthenticationId = details.HelloDetails.AuthenticationId; }
public void ChallengeParametersArePassedToClient() { MockSessionAuthenticationFactory mockSessionAuthenticationFactory = new MockSessionAuthenticationFactory(); WampPendingClientDetails authenticatorFactoryParameters = null; mockSessionAuthenticationFactory.SetGetSessionAuthenticator ((clientDetails, transportAuthenticator) => { authenticatorFactoryParameters = clientDetails; MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator(); mockSessionAuthenticator.SetAuthenticationMethod("ticket"); mockSessionAuthenticator.SetChallengeDetails (new MyChallenge { President = "Obama" }); return(mockSessionAuthenticator); }); WampAuthenticationPlayground playground = new WampAuthenticationPlayground(mockSessionAuthenticationFactory); playground.Host.Open(); string clientAuthMethod = null; ChallengeDetails clientChallengeDetails = null; Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >(); clientMock.Setup(x => x.Challenge(It.IsAny <string>(), It.IsAny <ChallengeDetails>())) .Callback((string authMethod, ChallengeDetails details) => { clientAuthMethod = authMethod; clientChallengeDetails = details; }); IWampServerProxy serverProxy = playground.CreateRawConnection(clientMock.Object); serverProxy.Hello("realm1", new HelloDetailsHack() { AuthenticationId = "joe", AuthenticationMethods = new string[] { "wampcra", "ticket" } }); MyChallenge deserializedChallengeDetails = clientChallengeDetails.OriginalValue.Deserialize <MyChallenge>(); Assert.That(deserializedChallengeDetails.President, Is.EqualTo("Obama")); Assert.That(clientAuthMethod, Is.EqualTo("ticket")); }
public IWampSessionAuthenticator GetSessionAuthenticator (WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator) { IWampSessionAuthenticator result = mSessionAuthenticationFactory.GetSessionAuthenticator (details, transportAuthenticator); if (result == null) { return(null); } return(new RestrictedSessionAuthenticator(result)); }
public IWampSessionAuthenticator GetSessionAuthenticator( WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator) { if (details.Realm != _realm) { throw new WampAuthenticationException(new AbortDetails { Message = "unknown realm" }); } if (details.HelloDetails.AuthenticationMethods != null && details.HelloDetails.AuthenticationMethods.Contains(AuthMethods.Ticket)) { return(new TicketSessionAuthenticator(details, _tokenValidator, _sessionCache)); } return(new AnonymousWampSessionAuthenticator()); }
public void NotAuthenticatedRaisesAbort() { 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(false); }); return(mockSessionAuthenticator); }); WampAuthenticationPlayground playground = new WampAuthenticationPlayground(mockSessionAuthenticationFactory); playground.Host.Open(); Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >(); IWampServerProxy serverProxy = playground.CreateRawConnection(clientMock.Object); serverProxy.Hello("realm1", new HelloDetailsHack() { AuthenticationId = "joe", AuthenticationMethods = new string[] { "wampcra", "ticket" } }); serverProxy.Authenticate("Barack Hussein", new AuthenticateExtraData()); clientMock.Verify(x => x.Abort(It.IsAny <AbortDetails>(), It.IsAny <string>())); }
public IWampSessionAuthenticator GetSessionAuthenticator( WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator) { // todo: change hardcoded realm name into realm collection resolving if (details.Realm != "prices") { throw new WampAuthenticationException(new AbortDetails { Message = "unknown realm" }); } if (details.HelloDetails.AuthenticationMethods != null && details.HelloDetails.AuthenticationMethods.Contains(AuthMethods.Ticket)) { return(new TicketSessionAuthenticator(details, _tokenValidator, _sessionCache)); } return(new AnonymousWampSessionAuthenticator()); }
public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator) { HelloDetails helloDetails = details.HelloDetails; if (helloDetails.AuthenticationMethods?.Contains("ticket") != true) { throw new WampAuthenticationException("supports only 'ticket' authentication"); } string user = helloDetails.AuthenticationId; if (user == null || !_mUserToTicket.TryGetValue(user, out string ticket)) { throw new WampAuthenticationException($"no user with authid '{user}' in user database"); } return(new TicketSessionAuthenticator(user, ticket, new BackendStaticAuthorizer(new string[0]))); }
public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator) { return(mGetSessionAuthenticator(details, transportAuthenticator)); }
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 IWampSessionAuthenticator GetSessionAuthenticator (WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator) { return(new AnonymousWampSessionAuthenticator()); }