Package javax.servlet.http

Examples of javax.servlet.http.Cookie


                  out.println();
               }
            }
            StringBuffer sb = null;
            StringBuffer sb2 = null;
            Cookie cc = null;
            // add session cookie
            if (sessionValue != null)
            {
               HttpSession session = serve.getSession(sessionValue);
               if (session != null)
               {
                  if (((AcmeSession) session).isValid())
                  {
                     if (session.isNew())
                     {
                        cc = new Cookie(SESSION_COOKIE_NAME, sessionValue);
                        if (serve.expiredIn < 0)
                           cc.setMaxAge(Math.abs(serve.expiredIn) * 60);
                        ServletContext sc = ((AcmeSession) session).getServletContext();
                        try
                        {
                           String cp = (String) sc.getClass().getMethod("getContextPath", Utils.EMPTY_CLASSES)
                                   .invoke(sc, Utils.EMPTY_OBJECTS);
                           if (cp.length() == 0)
                              cp = "/";
                           cc.setPath(cp);
                        }
                        catch (Exception e)
                        {

                        }

                        addCookie(cc);
                     }
                  }
                  else
                  {
                     cc = new Cookie(SESSION_COOKIE_NAME, "");
                     cc.setMaxAge(0);
                     addCookie(cc);
                  }
               }
            }

            // how to remove a cookie
            // cc = new Cookie(cookieName, "");
            // cc.setMaxAge(0);
            //
            for (int i = 0; outCookies != null && i < outCookies.size(); i++)
            {
               cc = (Cookie) outCookies.elementAt(i);
               if (cc.getSecure() && isSecure() == false)
                  continue;
               int version = cc.getVersion();
               String token;
               if (version > 1)
               {
                  if (sb2 == null)
                     sb2 = new StringBuffer(SETCOOKIE + "2: ");
                  else
                     sb2.append(',');
                  sb2.append(cc.getName());
                  sb2.append("=\"");
                  sb2.append(cc.getValue()).append('"');
                  token = cc.getComment();
                  if (token != null)
                     sb2.append("; Comment=\"").append(token).append('"');
                  token = cc.getDomain();
                  if (token != null)
                     sb2.append("; Domain=\"").append(token).append('"');
                  if (cc.getMaxAge() >= 0)
                     sb2.append("; Max-Age=\"").append(cc.getMaxAge()).append('"');
                  token = cc.getPath();
                  if (token != null)
                     sb2.append("; Path=\"").append(token).append('"');
                  if (cc.getSecure())
                  {
                     sb2.append("; Secure");
                  }
                  sb2.append("; Version=\"").append(version).append('"');
               }
               else
               {
                  if (sb == null)
                     sb = new StringBuffer(SETCOOKIE + ": ");
                  else
                     //sb.append(',');
                     sb.append("\r\n" + SETCOOKIE + ": "); // for IE not
                  sb.append(cc.getName());
                  sb.append('=');
                  sb.append(cc.getValue());//.append('"');
                  if (cc.getDomain() != null && cc.getDomain().length() > 0)
                  {
                     sb.append("; domain=" + cc.getDomain());
                  }
                  if (cc.getMaxAge() >= 0)
                  {
                     sb.append("; expires=");
                     sb.append(expdatefmt.format(new Date(new Date().getTime() + 1000l * cc.getMaxAge())));
                  }
                  if (cc.getPath() != null && cc.getPath().length() > 0)
                  {
                     sb.append("; path=" + cc.getPath());
                  }
                  if (cc.getSecure())
                  {
                     sb.append("; secure");
                  }
               }
            }
View Full Code Here


      {

         @Override
         protected void prepareRequest(EnhancedMockHttpServletRequest request)
         {
            request.addCookie(new Cookie("bar", "baz"));
         }

         @Override
         protected void onResponse(EnhancedMockHttpServletResponse response)
         {
View Full Code Here

     * @param request request
     * @param defaultValue default value
     * @return cookie value
     */
    public static String getCookieValue(String name, HttpServletRequest request, String defaultValue) {
        Cookie c = getCookie(name, request);
        return c == null ? defaultValue : c.getValue();
    }
View Full Code Here

     * @param value ui state cookie value
     * @param request request
     * @param response response
     */
    public static void storeUIState(String name, String value, HttpServletRequest request, HttpServletResponse response) {
        Cookie c = getCookie(name, request);
        if (c != null) {
            c.setValue(value);
        } else {
            c = new Cookie(name, value);
        }
        c.setMaxAge(-1);
        response.addCookie(c);
    }
View Full Code Here

      SessionInfo session = getSessionInfo(ticket);
      logoff(ticket);

      if (request.getCookies() != null) {
        for (int i = 0; i < request.getCookies().length; i++) {
          Cookie cookie = request.getCookies()[i];
          if (cookie.getName().equals(Constants.LOGON_TICKET) || cookie.getName().equals(Constants.DOMAIN_LOGON_TICKET)) {
            cookie.setMaxAge(0);
            response.addCookie(cookie);
          }
        }
      }
      request.getSession().removeAttribute(Constants.LOGON_TICKET);
View Full Code Here

  public int hasClientLoggedOn(HttpServletRequest request, HttpServletResponse response) throws SecurityErrorException {
    // Get the logon cookie
    String logonCookie = null;
    if (request.getCookies() != null) {
      for (int i = 0; i < request.getCookies().length; i++) {
        Cookie cookie = request.getCookies()[i];
        if (cookie.getName().equals(Constants.LOGON_TICKET) || cookie.getName().equals(Constants.DOMAIN_LOGON_TICKET)) {
          logonCookie = cookie.getValue();
        }
      }
    }
    // If there is a logon ticket in the requests attributes then reassign
    // as we've just been issued a new ticket.
View Full Code Here

   
    /**
     * Set the normal logon ticket without a domain - this works in almost
     * all circumstances
     */
    Cookie cookie = new Cookie(Constants.LOGON_TICKET, logonTicket);
    cookie.setMaxAge(Property.getPropertyInt(new SystemConfigKey("security.session.maxCookieAge")));
    cookie.setPath("/");
    cookie.setSecure(true);
    response.addCookie(cookie);
    /**
     * Set a logon ticket for the domain - this is require to make active
     * dns work.
     */
    Cookie cookie2 = new Cookie(Constants.DOMAIN_LOGON_TICKET, logonTicket);
    cookie2.setMaxAge(Property.getPropertyInt(new SystemConfigKey("security.session.maxCookieAge")));
    cookie2.setPath("/");
    // We now set the domain on the cookie so the new Active DNS feature for
    // Reverse Proxy works correctly
    String host = request.getField("Host");
    if (host != null) {
      HostService hostService = new HostService(host);
      cookie2.setDomain(hostService.getHost());
    }
    cookie2.setSecure(true);
    response.addCookie(cookie2);
   
   
    request.setAttribute("sslx.logon.cookie", new Object());
   
View Full Code Here

    logons.put(logonTicket, info);
    /**
     * Set the normal logon ticket without a domain - this works in almost
     * all circumstances
     */
    Cookie cookie = new Cookie(Constants.LOGON_TICKET, logonTicket);
    cookie.setMaxAge(Property.getPropertyInt(new SystemConfigKey("security.session.maxCookieAge")));
    cookie.setPath("/");
    cookie.setSecure(true);
    response.addCookie(cookie);
    /**
     * Set a logon ticket for the domain - this is require to make active
     * dns work.
     */
    Cookie cookie2 = new Cookie(Constants.DOMAIN_LOGON_TICKET, logonTicket);
    cookie2.setMaxAge(Property.getPropertyInt(new SystemConfigKey("security.session.maxCookieAge")));
    cookie2.setPath("/");
    // We now set the domain on the cookie so the new Active DNS feature for
    // Reverse Proxy works correctly
    String host = request.getHeader("Host");
    if (host != null) {
      HostService hostService = new HostService(host);
      cookie2.setDomain(hostService.getHost());
    }
    cookie.setSecure(true);
    response.addCookie(cookie2);
    return info;
  }
View Full Code Here

        }
       
        // Store the new locale in the session and set a persistant cookie
        Locale l = new Locale(lang, country, variant);
        request.getSession().setAttribute(Globals.LOCALE_KEY, l);
        Cookie cookie = new Cookie(SystemProperties.get("adito.cookie", "SSLX_SSESHID") + "_LANG", locale.toString());
        cookie.setMaxAge(60 * 60 * 24 * 7); // a week
        cookie.setPath("/");
        cookie.setSecure(true);
        response.addCookie(cookie);
        return referer == null ? mapping.findForward("home") : new ActionForward(referer, true);
    }
View Full Code Here

      Header header = (Header)e.nextElement();
      header.toString(buf);
    }
    int size = _cookies.size();
    for(int i=0; i<size; i++) {
      Cookie cookie = (Cookie)_cookies.get(i);
      buf.append("Set-Cookie: ");
      getCookieValue(buf, cookie);
      buf.append("\r\n");
    }
    buf.append("\r\n");
View Full Code Here

TOP

Related Classes of javax.servlet.http.Cookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.