public CreateSessionResponse CreateSession(CreateSessionRequest request) { string userName = request.Username; string password = request.Password; if (ValidateUserPassword(userName, password)) { SimpleSession session = sessions.Find(s => s.UserName == userName); if (session == null) { session = new SimpleSession(userName); sessions.Add(session); } else { if (!session.IsValid()) { sessions.Remove(session); session = new SimpleSession(userName); sessions.Add(session); } } session.Login(); return(new CreateSessionResponse { Session = session.GetSession() }); } throw new InvalidOperationException("Unable to login with username and password"); }
public RenewSessionResponse RenewSession(RenewSessionRequest request) { string userName = request.Session.User; string sessionId = request.Session.SessionID; SimpleSession session = sessions.Find(s => s.SessionId == sessionId) ?? sessions.Find(s => s.UserName == userName); if (session != null) { return(new RenewSessionResponse { Session = session.GetSession() }); } throw new InvalidOperationException("Unable to find user with session"); }
public ReleaseSessionResponse ReleaseSession(ReleaseSessionRequest request) { string userName = request.Session.User; string sessionId = request.Session.SessionID; SimpleSession session = sessions.Find(s => s.SessionId == sessionId) ?? sessions.Find(s => s.UserName == userName); if (session != null) { session.Logout(); if (!session.IsValid()) { sessions.Remove(session); } } return(new ReleaseSessionResponse()); }
public void CreateSessionDuplicateLogin() { SimpleSecurityWebServiceClient webServiceClient = new SimpleSecurityWebServiceClient("User"); CreateSessionRequest request = new CreateSessionRequest { Username = "******", Password = "******" }; webServiceClient.CreateSession(request); webServiceClient.CreateSession(request); Assert.That(webServiceClient.Sessions, Is.Not.Empty); Assert.That(webServiceClient.Sessions.Count, Is.EqualTo(1)); SimpleSession session = webServiceClient.Sessions[0]; Assert.That(session.IsValid(), Is.True); Assert.That(session.Count, Is.EqualTo(2)); }
public void CreateSessionBySession() { SimpleSecurityWebServiceClient webServiceClient = new SimpleSecurityWebServiceClient("User"); string sessionId = Guid.NewGuid().ToString(); Assert.That(webServiceClient.FindBySession(sessionId), Is.Null); webServiceClient.AddExistingSession("User"); Assert.That(webServiceClient.Sessions, Is.Not.Empty); Assert.That(webServiceClient.Sessions.Count, Is.EqualTo(1)); SimpleSession session = webServiceClient.Sessions[0]; Assert.That(session, Is.Not.Null); SimpleSession found = webServiceClient.FindBySession(session.SessionId); Assert.That(found, Is.Not.Null); }
public void CreateSession() { SimpleSecurityWebServiceClient webServiceClient = new SimpleSecurityWebServiceClient("User"); CreateSessionRequest request = new CreateSessionRequest { Username = "******", Password = "******" }; CreateSessionResponse response = webServiceClient.CreateSession(request); Assert.That(response, Is.Not.Null); Assert.That(response.Session, Is.Not.Null); Assert.That(response.Session.User, Is.EqualTo("User")); Assert.That(response.Session.SessionID, Is.Not.Empty); Assert.That(webServiceClient.Sessions, Is.Not.Empty); Assert.That(webServiceClient.Sessions.Count, Is.EqualTo(1)); SimpleSession session = webServiceClient.Sessions[0]; Assert.That(session.IsValid(), Is.True); Assert.That(session.Count, Is.EqualTo(1)); }
/// <summary> /// Finds any current sessions by session Id. /// </summary> /// <param name="sessionId">The session identifier.</param> /// <returns></returns> public SimpleSession FindBySession(string sessionId) { SimpleSession session = sessions.Find(s => s.SessionId == sessionId); return(session); }
/// <summary> /// Adds the existing session. /// </summary> /// <param name="userName">Name of the user.</param> public void AddExistingSession(string userName) { SimpleSession existingSession = new SimpleSession(userName); sessions.Add(existingSession); }