示例#1
0
        internal void SetSessionCookiesForPortal(HttpCookieCollection cookies)
        {
            if (cookies == null || cookies.Count == 0)
            {
                return;
            }

            if (!(context.WorkerRequest is IHttpExtendedWorkerRequest))
            {
                return;
            }
            IHttpExtendedWorkerRequest exWorker      = (IHttpExtendedWorkerRequest)context.WorkerRequest;
            bool        inPortletMode                = !context.IsServletRequest;
            bool        shouldStoreCookiesCollection = false;
            HttpSession javaSession = exWorker.GetSession(false);

            if (javaSession == null && inPortletMode)
            {
                javaSession = exWorker.GetSession(true);
            }

            if (javaSession == null)
            {
                return;
            }

            object sessionLock = GetJavaSessionLock(javaSession);

            lock (sessionLock) {
                Hashtable sessionCookies = (Hashtable)javaSession.getAttribute(SessionCookies);
                if (sessionCookies == null)
                {
                    if (inPortletMode)
                    {
                        sessionCookies = new Hashtable();
                        shouldStoreCookiesCollection = true;
                    }
                    else
                    {
                        return;
                    }
                }

                ArrayList sessionStoredCookies = null;
                for (int i = 0; i < cookies.Count; i++)
                {
                    HttpCookie cookie = cookies[i];
                    if (sessionCookies [cookie.Name] != null || inPortletMode)
                    {
                        sessionCookies [cookie.Name] = cookie;
                        if (sessionStoredCookies == null)
                        {
                            sessionStoredCookies = new ArrayList();
                        }
                        sessionStoredCookies.Add(cookie.Name);
                    }
                }

                if (sessionStoredCookies != null)
                {
                    foreach (object key in sessionStoredCookies)
                    {
                        cookies.Remove((string)key);
                    }
                }

                if (shouldStoreCookiesCollection)
                {
                    javaSession.setAttribute(SessionCookies, sessionCookies);
                }
            }
        }
示例#2
0
        internal void GetSessionCookiesForPortal(HttpCookieCollection cookies)
        {
            if (context == null)
            {
                return;
            }
            if (!(context.WorkerRequest is IHttpExtendedWorkerRequest))
            {
                return;
            }
            IHttpExtendedWorkerRequest exWorker = (IHttpExtendedWorkerRequest)context.WorkerRequest;
            HttpSession javaSession             = exWorker.GetSession(false);

            if (javaSession == null)
            {
                return;
            }

            object sessionLock = GetJavaSessionLock(javaSession);

            lock (sessionLock) {
                Hashtable sessionCookies = (Hashtable)javaSession.getAttribute(SessionCookies);
                if (sessionCookies == null)
                {
                    return;
                }

                ArrayList expiredCookies = null;
                foreach (string key in sessionCookies.Keys)
                {
                    HttpCookie sessionCookie = (HttpCookie)sessionCookies [key];
                    if (sessionCookie.Expires.Ticks != 0 &&
                        sessionCookie.Expires.Ticks < DateTime.Now.Ticks)
                    {
                        if (cookies [key] != null)
                        {
                            cookies.Remove(key);
                        }
                        else
                        {
                            if (expiredCookies == null)
                            {
                                expiredCookies = new ArrayList();
                            }
                            expiredCookies.Add(key);
                        }
                    }
                    else
                    {
                        cookies.Set(sessionCookie);
                    }
                }

                if (expiredCookies != null)
                {
                    foreach (object key in expiredCookies)
                    {
                        sessionCookies.Remove(key);
                    }
                }
            }
        }