/// <summary>Creates the Hadoop authentication HTTP cookie.</summary>
        /// <param name="token">authentication token for the cookie.</param>
        /// <param name="expires">
        /// UNIX timestamp that indicates the expire date of the
        /// cookie. It has no effect if its value &lt; 0.
        /// XXX the following code duplicate some logic in Jetty / Servlet API,
        /// because of the fact that Hadoop is stuck at servlet 2.5 and jetty 6
        /// right now.
        /// </param>
        public static void CreateAuthCookie(HttpServletResponse resp, string token, string
                                            domain, string path, long expires, bool isSecure)
        {
            StringBuilder sb = new StringBuilder(AuthenticatedURL.AuthCookie).Append("=");

            if (token != null && token.Length > 0)
            {
                sb.Append("\"").Append(token).Append("\"");
            }
            if (path != null)
            {
                sb.Append("; Path=").Append(path);
            }
            if (domain != null)
            {
                sb.Append("; Domain=").Append(domain);
            }
            if (expires >= 0)
            {
                DateTime         date = Extensions.CreateDate(expires);
                SimpleDateFormat df   = new SimpleDateFormat("EEE, " + "dd-MMM-yyyy HH:mm:ss zzz");
                df.SetTimeZone(Extensions.GetTimeZone("GMT"));
                sb.Append("; Expires=").Append(df.Format(date));
            }
            if (isSecure)
            {
                sb.Append("; Secure");
            }
            sb.Append("; HttpOnly");
            resp.AddHeader("Set-Cookie", sb.ToString());
        }
示例#2
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Javax.Servlet.ServletException"/>
        public virtual void DoFilter(ServletRequest req, ServletResponse res, FilterChain
                                     chain)
        {
            HttpServletResponse httpRes = (HttpServletResponse)res;

            httpRes.SetHeader("Cache-Control", "no-cache");
            long now = Runtime.CurrentTimeMillis();

            httpRes.AddDateHeader("Expires", now);
            httpRes.AddDateHeader("Date", now);
            httpRes.AddHeader("Pragma", "no-cache");
            chain.DoFilter(req, res);
        }