コード例 #1
0
        /// <summary>
        /// Login an Ampla user using session
        /// </summary>
        /// <param name="session"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public AmplaUser SessionLogin(string session, out string message)
        {
            message = null;
            AmplaUser user = amplaUserStore.GetUserBySession(session);

            if (user != null)
            {
                user = Renew(user);
            }

            if (user == null)
            {
                RenewSessionRequest request = new RenewSessionRequest {
                    Session = new Session {
                        SessionID = session, User = ""
                    }
                };

                Exception            exception;
                RenewSessionResponse response = CatchExceptions(() => securityWebService.RenewSession(request), out exception);
                if (response != null)
                {
                    user = new AmplaUser(response.Session.User, response.Session.SessionID, false, "AmplaSession");
                    amplaUserStore.StoreUser(user);
                }
                if (user == null)
                {
                    message = exception.Message;
                }
            }

            return(user);
        }
コード例 #2
0
        public void LoginTwice()
        {
            string    message;
            AmplaUser user = amplaUserService.SimpleLogin("User", "password", out message);

            Assert.That(user, Is.Not.Null);

            Assert.That(webServiceClient.Sessions, Is.Not.Empty);

            Assert.That(user.UserName, Is.EqualTo("User"));
            Assert.That(user.Session, Is.Not.Empty);
            Assert.That(user.Session, Is.EqualTo(webServiceClient.Sessions[0].SessionId));
            Assert.That(message, Is.Null.Or.Empty);

            // login again
            user = amplaUserService.SimpleLogin("User", "password", out message);
            Assert.That(user, Is.Not.Null);

            Assert.That(webServiceClient.Sessions, Is.Not.Empty);
            Assert.That(webServiceClient.Sessions.Count, Is.EqualTo(1));

            Assert.That(user.UserName, Is.EqualTo("User"));
            Assert.That(user.Session, Is.Not.Empty);
            Assert.That(user.Session, Is.EqualTo(webServiceClient.Sessions[0].SessionId));
            Assert.That(message, Is.Null.Or.Empty);
        }
コード例 #3
0
        /// <summary>
        /// Login an Ampla users using username and password
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public AmplaUser SimpleLogin(string userName, string password, out string message)
        {
            message = null;
            AmplaUser user = amplaUserStore.GetUserByName(userName);

            if (user != null)
            {
                user = Renew(user);
            }

            if (user == null)
            {
                CreateSessionRequest request = new CreateSessionRequest {
                    Username = userName, Password = password
                };

                Exception             exception;
                CreateSessionResponse response = CatchExceptions(() => securityWebService.CreateSession(request), out exception);
                if (response != null)
                {
                    user = new AmplaUser(response.Session.User, response.Session.SessionID, true, "Username/Password");
                    amplaUserStore.StoreUser(user);
                }

                if (user == null)
                {
                    message = exception.Message;
                }
            }

            return(user);
        }
コード例 #4
0
        private AmplaUser Renew(AmplaUser user)
        {
            AmplaUser renewedUser = null;

            if (user != null)
            {
                RenewSessionRequest request = new RenewSessionRequest {
                    Session = new Session {
                        User = user.UserName, SessionID = user.Session
                    }
                };

                Exception            exception;
                RenewSessionResponse response = CatchExceptions(() => securityWebService.RenewSession(request), out exception);
                if (response != null)
                {
                    renewedUser = user;
                    renewedUser.UpdateActivityDate();
                }
                else
                {
                    amplaUserStore.RemoveUser(user);
                }
            }
            return(renewedUser);
        }
コード例 #5
0
        public AmplaUser IntegratedLogin(out string message)
        {
            message = null;
            AmplaUser user = FindCurrentUser();

            if (user != null)
            {
                user = Renew(user);
            }

            if (user == null)
            {
                CreateSessionRequest request = new CreateSessionRequest();

                Exception             exception;
                CreateSessionResponse response = CatchExceptions(() => securityWebService.CreateSession(request), out exception);
                if (response != null)
                {
                    user = new AmplaUser(response.Session.User, response.Session.SessionID, true, "Integrated");
                    amplaUserStore.StoreUser(user);
                }

                if (user == null)
                {
                    message = exception.Message;
                }
            }

            return(user);
        }
コード例 #6
0
        public void LoginInvalid()
        {
            string    message;
            AmplaUser user = amplaUserService.SimpleLogin("Invalid", "password", out message);

            Assert.That(user, Is.Null);

            Assert.That(webServiceClient.Sessions, Is.Empty);
            Assert.That(message, Is.Not.Empty);
            Assert.That(message, Is.StringContaining("password"));
        }
コード例 #7
0
ファイル: AmplaUserStore.cs プロジェクト: braim/Ampla-Data
        public void StoreUser(AmplaUser user)
        {
            string lowerName = user.UserName.ToLower();
            string sessionId = user.Session;

            lock (dictionaryLock)
            {
                validatedUserDictionary[lowerName]    = user;
                validatedSessionDictionary[sessionId] = user;
            }
        }
コード例 #8
0
        /// <summary>
        /// Renew the session
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        public AmplaUser RenewSession(string session)
        {
            AmplaUser user = amplaUserStore.GetUserBySession(session);

            if (user != null)
            {
                user = Renew(user);
            }

            return(user);
        }
コード例 #9
0
ファイル: AmplaUserStore.cs プロジェクト: braim/Ampla-Data
 public void RemoveUser(AmplaUser user)
 {
     if (user != null)
     {
         string lowerName = user.UserName.ToLower();
         string sessionId = user.Session;
         lock (dictionaryLock)
         {
             validatedUserDictionary.Remove(lowerName);
             validatedSessionDictionary.Remove(sessionId);
         }
     }
 }
コード例 #10
0
        public void LoginUsingSession()
        {
            webServiceClient.AddExistingSession("Admin");
            Assert.That(webServiceClient.Sessions, Is.Not.Empty);

            string session = webServiceClient.Sessions[0].SessionId;

            string    message;
            AmplaUser user = amplaUserService.SessionLogin(session, out message);

            Assert.That(user, Is.Not.Null);

            Assert.That(user.UserName, Is.EqualTo("Admin"));
            Assert.That(user.Session, Is.Not.Empty);
            Assert.That(user.Session, Is.EqualTo(session));
            Assert.That(message, Is.Null.Or.Empty);
        }
コード例 #11
0
        public void MultipleSessionsForSameUser()
        {
            webServiceClient.AddExistingSession("Admin");
            webServiceClient.AddExistingSession("Admin");

            Assert.That(webServiceClient.Sessions, Is.Not.Empty);

            string session1 = webServiceClient.Sessions[0].SessionId;
            string session2 = webServiceClient.Sessions[1].SessionId;

            string    message;
            AmplaUser user = amplaUserService.SessionLogin(session1, out message);

            Assert.That(user, Is.Not.Null);

            Assert.That(user.UserName, Is.EqualTo("Admin"));
            Assert.That(user.Session, Is.Not.Empty);
            Assert.That(user.Session, Is.EqualTo(session1));
            Assert.That(user.Session, Is.Not.EqualTo(session2));
            Assert.That(message, Is.Null.Or.Empty);
        }
コード例 #12
0
        /// <summary>
        /// Logout the user
        /// </summary>
        /// <param name="userName"></param>
        public void Logout(string userName)
        {
            AmplaUser user = amplaUserStore.GetUserByName(userName);

            if (user != null)
            {
                amplaUserStore.RemoveUser(user);

                if (user.RememberToLogout)
                {
                    ReleaseSessionRequest request = new ReleaseSessionRequest
                    {
                        Session = new Session {
                            User = user.UserName, SessionID = user.Session
                        }
                    };
                    Exception exception;
                    CatchExceptions(() => securityWebService.ReleaseSession(request), out exception);
                }
            }
        }