Ejemplo n.º 1
0
        private string SetRequestSession(IHttpRequest request)
        {
            if (!request.Cookies.ContainsKey(SessionStore.SessionCookieKey))
            {
                string newSessionId = Guid.NewGuid().ToString();

                request.Session = SessionStore.Get(newSessionId);

                return(newSessionId);
            }

            return(request.Cookies.Get(SessionStore.SessionCookieKey).Value);
        }
Ejemplo n.º 2
0
        private string SetRequestSession(IHttpRequest request)
        {
            if (!request.Cookies.ContainsKey(SessionStore.SessionCookieKey))
            {
                var sessionId = Guid.NewGuid().ToString();

                request.Session = SessionStore.Get(sessionId);

                return(sessionId);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public void DynamoDBBigDataAddTest()
        {
            ChangeConnString(DynamoDBConnString);
            ChangeProvider(ProviderTypeOptions.DynamoDB);
            ChangeFormatterType(FormatterTypeOptions.Binary);

            var key = PutItemToExpire(358400 * 3);

            var store = new SessionStore();

            var item = store.Get <TestData>(Category, key);

            Assert.IsNotNull(item);
        }
Ejemplo n.º 4
0
        public void InsertNewSessionAndEvictHard()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            sessionStore.Insert(session);
            sessionStore.EvictSession(session);
            Session storedSession = sessionStore.Get(id, this.ApplicationName);

            Assert.IsNull(storedSession);
        }
Ejemplo n.º 5
0
        public void InsertNewSession()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            sessionStore.Insert(session);
            Session storedSession = sessionStore.Get(id, this.ApplicationName);

            Assert.AreEqual(session.SessionID, storedSession.SessionID);
            Assert.AreEqual(session.ApplicationName, storedSession.ApplicationName);
            Assert.AreEqual(session.SessionItems.Bytes.Length, storedSession.SessionItems.Bytes.Length);
        }
Ejemplo n.º 6
0
        public void AddExpiredSessionAndEvictSoft()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            session.Expires = DateTime.Now.Subtract(new TimeSpan(0, 2, 0));
            sessionStore.Insert(session);
            sessionStore.EvictExpiredSession(session.SessionID, session.ApplicationName);
            Session storedSession = sessionStore.Get(session.SessionID, session.ApplicationName);

            Assert.IsNull(storedSession);
        }
Ejemplo n.º 7
0
        public void UpdateSession()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            sessionStore.Insert(session);
            sessionStore.UpdateSession(id, 5, new Binary(serializedItems), this.ApplicationName, 3, 0);
            Session updatedSession = sessionStore.Get(id, this.ApplicationName);

            Assert.AreEqual(5, updatedSession.Timeout);
            Assert.AreEqual(3, updatedSession.SessionItemsCount);
            Assert.AreEqual(DateTime.Now.AddMinutes(5).Minute, updatedSession.Expires.Minute);
        }
        private string SetRequestSession(IHttpRequest httpRequest)
        {
            string sessionId = null;

            if (httpRequest.Cookies.ContainsKey(SessionStore.SessionCookieKey))
            {
                var cookie = httpRequest.Cookies.Get(SessionStore.SessionCookieKey);
                sessionId           = cookie.Value;
                httpRequest.Session = SessionStore.Get(sessionId);
            }
            else
            {
                sessionId           = Guid.NewGuid().ToString();
                httpRequest.Session = SessionStore.Get(sessionId);
            }

            return(sessionId);
        }
Ejemplo n.º 9
0
        public IHttpResponse Login(IHttpRequest request)
        {
            string username = request.FormData["username"];
            string password = request.FormData["password"];

            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                return(new RedirectResponse("/login"));
            }

            string sessionId = request.Session.Id;

            SessionStore.Get(sessionId).ChangeState(true);

            ShoppingCartStorage.GetOrAddCart(sessionId);

            return(new RedirectResponse("/"));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Save the logged in user object
        /// </summary>
        /// <param name="userRoleContext"></param>
        /// <param name="sessionCtx"></param>
        private void SaveUserRoleContext(UserRoleContext userRoleContext, ISessionContext sessionCtx)
        {
            SessionContext sessionContext = SessionStore.Get <SessionContext>("SessionContext");

            if (sessionContext != null)
            {
                sessionContext.UserSecurity         = userRoleContext.UserSecurity;
                sessionContext.UserTransactionLimit = userRoleContext.UserTransactionLimit;
                sessionContext.UserTask             = new List <IUserTask>();
                if (userRoleContext.UserSecurity != null && userRoleContext.UserSecurity.Count > 0)
                {
                    foreach (UserTask userTask in userRoleContext.UserSecurity)
                    {
                        sessionContext.UserTask.Add(userTask);
                    }
                }
            }
            else
            {
                throw new FrameworkException(1, "Invalid Session");
            }
        }
        private string SetRequestSession(IHttpRequest httpRequest)
        {
            string sessionId = null;

            if (httpRequest.Cookies.ContainsKey(SessionStore.SessionCookieKey))
            {
                //get the cookie and the sessionId
                var cookie = httpRequest.Cookies.Get(SessionStore.SessionCookieKey);
                sessionId = cookie.Value;

                //save the value of that id in the httpRequest Session
                httpRequest.Session = SessionStore.Get(sessionId);
            }
            else
            {
                //if we dont have that cookie
                sessionId           = Guid.NewGuid().ToString();
                httpRequest.Session = new HttpSession(sessionId);
            }

            return(sessionId);
        }
Ejemplo n.º 12
0
        public IHttpResponse Handle(IHttpContext httpContext)
        {
            string sessionIdToSend = null;

            if (!httpContext.Request.Cookies.ContainsKey(SessionStore.SessionCookieKey))
            {
                string sessionId = Guid.NewGuid().ToString();

                httpContext.Request.Session = SessionStore.Get(sessionId);

                sessionIdToSend = sessionId;
            }

            IHttpResponse httpResponse = this.handlingFunc.Invoke(httpContext);

            if (!(httpResponse is ImageResponse))
            {
                httpResponse.AddHeader("Content-Type", "text/html");
            }

            if (sessionIdToSend != null)
            {
                httpResponse.Headers.Add(
                    HttpHeader.SetCookie,
                    $"{SessionStore.SessionCookieKey}={sessionIdToSend}; HttpOnly; Path=/");
            }

            if (!httpResponse.Headers.ContainsKey(HttpHeader.ContentType))
            {
                httpResponse.AddHeader(HttpHeader.ContentType, "text/html");
            }

            foreach (var cookie in httpResponse.Cookies)
            {
                httpResponse.AddHeader(HttpHeader.Cookie, cookie.ToString());
            }
            return(httpResponse);
        }
Ejemplo n.º 13
0
        public IHttpResponse Handle(IHttpContext context)
        {
            string sessionIdToSend = null;

            // Create new Session, if no session cookie
            if (!context.Request.Cookies.ContainsKey(SessionStore.SessionCookieKey))
            {
                var sessionId = Guid.NewGuid().ToString();

                context.Request.Session = SessionStore.Get(sessionId);

                sessionIdToSend = sessionId;
            }

            var response = this.handlingFunc(context.Request);

            // Send new Session Cookie
            if (sessionIdToSend != null)
            {
                response.Headers.Add(
                    HttpHeader.SetCookie,
                    $"{SessionStore.SessionCookieKey}={sessionIdToSend}; HttpOnly; Path=/");
            }

            // Send Content-Type Header
            if (!response.Headers.ContainsKey(HttpHeader.ContentType))
            {
                response.Headers.Add(HttpHeader.ContentType, "text/plain");
            }

            // Send existing Cookies
            foreach (var cookie in response.Cookies)
            {
                response.Headers.Add(HttpHeader.SetCookie, cookie.ToString());
            }

            return(response);
        }
Ejemplo n.º 14
0
        public IHttpResponse Handle(IHttpContext context)
        {
            string sessionIdToSend = null;

            if (!context.Request.Cookies.ContainsKey(SessionStore.SessionCookieKey))
            {
                // Set-up new session (with key)
                string sessionId = Guid.NewGuid().ToString();

                context.Request.Session = SessionStore.Get(sessionId);

                sessionIdToSend = sessionId;
            }

            IHttpResponse response = this.handlingFunc(context.Request);

            if (sessionIdToSend != null)
            {
                // Set-up new Header for session cookie
                response.Headers.Add(
                    HttpHeader.SetCookie,
                    $"{SessionStore.SessionCookieKey}={sessionIdToSend}; HttpOnly; path=/");
            }

            if (!response.Headers.ContainsKey(HttpHeader.ContentType))
            {
                response.Headers.Add(HttpHeader.ContentType, "text/plain");
            }


            foreach (HttpCookie cookie in response.Cookies)
            {
                response.Headers.Add(HttpHeader.SetCookie, cookie.ToString());
            }

            return(response);
        }
Ejemplo n.º 15
0
        private void SetResponseSession(IHttpResponse httpResponse, string sessionId)
        {
            var session = SessionStore.Get(sessionId);

            httpResponse.Headers.Add(HttpHeader.SetCookie, sessionId);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Considers the input parameter as DateTime object in UTC, converts the same to the logged in site's time zone with the details available in the Session.
        /// </summary>
        /// <param name="utcDateTime">DateTime in UTC</param>
        /// <returns></returns>
        public static DateTime ToSiteTime(this DateTime utcDateTime)
        {
            TimeZoneInfo loggedInSiteTimeZoneInfo = SessionStore.Get <ISession>("SessionInfo").LoggedInSite.TimeZone;

            return(TimeZoneInfo.ConvertTimeFromUtc(DateTime.SpecifyKind(utcDateTime, DateTimeKind.Unspecified), loggedInSiteTimeZoneInfo));
        }