Esempio n. 1
0
        protected void CheckIfSessionIsStillValid()
        {
            _session = UserAuthentication.ValidateSession(_session.Principal.Identity.Name, _session.SessionToken.Id);
            _lastSessionCheckTicks = Environment.TickCount;

            if (Platform.IsLogLevelEnabled(LogLevel.Debug))
            {
                Platform.Log(LogLevel.Debug, "Session {0} for user {1} is still valid. Will expire on {2}", _session.SessionToken.Id, _session.Principal.Identity.Name, _session.SessionToken.ExpiryTime);
            }
        }
Esempio n. 2
0
        protected void EnsureSessionIsValid()
        {
            if (_session == null)
            {
                return;
            }

            bool     nearExpiry         = Platform.Time.Add(TimeSpan.FromMinutes(SessionRenewalOffsetMinutes)) > _session.SessionToken.ExpiryTime;
            TimeSpan timeSinceLastCheck = TimeSpan.FromMilliseconds(Environment.TickCount - _lastSessionCheckTicks);

            if (nearExpiry || timeSinceLastCheck > _sessionPollingIntervalSeconds)
            {
                _lastSessionCheckTicks = Environment.TickCount;
                _session = UserAuthentication.RenewSession(_session);
                OnSessionRenewed();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Renew the specified <see cref="UserSessionInfo"/>
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        /// <remarks>
        /// <paramref name="session"/> is deemed invalid once this method returns and should be discarded.
        /// </remarks>
        static public UserSessionInfo RenewSession(UserSessionInfo session)
        {
            if (_logStuff)
            {
                string message = String.Format("Renewing user session (username={0}, session={1}).", session.Principal.Identity.Name, session.SessionToken.Id);
                //Console.WriteLine(message);
                Platform.Log(LogLevel.Debug, message);
            }

            var newSession = _instance.RenewSession(session);

            // double check
            if (newSession == null || newSession.SessionToken == null || newSession.SessionToken.ExpiryTime < Platform.Time)
            {
                throw new Exception("Unexpected Error: Session was renewed but invalid");
            }
            return(newSession);
        }
Esempio n. 4
0
        private void AuthenticateUser(StartApplicationRequest request)
        {
            _userName = request.Username;
            if (!String.IsNullOrEmpty(request.SessionId))
            {
                IsSessionShared = request.IsSessionShared;
            }

            _session = UserAuthentication.ValidateSession(request.Username, request.SessionId);
            if (_session == null)
            {
                return;
            }

            if (_session.Principal != null)
            {
                Thread.CurrentPrincipal = Principal = _session.Principal;
            }
        }
Esempio n. 5
0
        static public void Logout(UserSessionInfo session)
        {
            string username = session.Principal.Identity.Name;

            if (_logStuff)
            {
                string message = String.Format("Attempting to log out (username={0}, session={1}).", username, session.SessionToken.Id);
                Platform.Log(LogLevel.Debug, message);
            }

            try
            {
                _instance.Logout(session);
                if (_logStuff)
                {
                    Platform.Log(LogLevel.Info, "Successfully logged out (username={0}, session={1}).", username, session.SessionToken.Id);
                }
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Warn, e, "Failed to log out (user={0}, session={1}).", username, session.SessionToken.Id);
            }
        }