Package javax.servlet.http

Examples of javax.servlet.http.Cookie


  /// @synopsis void addCookie(Cookie cookie)
  public static final Object[] p_addCookie = { null, "cookie" };
  public Any m_addCookie(Context context, Any cookie_)
  {
   if (cookie_ instanceof AnyCookie) {
      Cookie cookie = (Cookie)cookie_.toObject();
      _response.addCookie(cookie);
      return this;
    }
    throw context.BadParameter("Expected Cookie");
  }     
View Full Code Here


      }
     
      boolean hascookie = false;
     
      if (_use_cookies) {
        Cookie cookies[] = context.getRequest().getCookies();
        if (cookies != null) {
          int n = cookies.length;
          for(int i=0; i<n; i++) {
            Cookie c = cookies[i];
            if (c.getName().equals(_cookie_name)) {
              String s = c.getValue();
              session = context.getSession(s);
              if (session != null) {
                context.setSession(session);
                hascookie = true;
                break;
              }
            }
          }
        }
       
      }
     
      if (session == null) {
        session = context.createSession();
        context.setSession(session);
      }

      if (_use_cookies && !hascookie) {
        Cookie c = new Cookie(_cookie_name, session.getId());
        c.setMaxAge(_cookie_lifetime);
        c.setSecure(_cookie_secured);
        if (_cookie_domain != null) {
          c.setDomain(_cookie_domain);
        }
        if (_cookie_path != null) {
          c.setPath(_cookie_path);
        }
        context.getResponse().addCookie(c);
      }
     
      if (_auto_redirect) {
View Full Code Here

        value = "";
      }
      if (_cookies == null) {
        _cookies = new ArrayList();
      }
      _cookies.add(new Cookie(name, value));
    }
  }
View Full Code Here

  /// Creates and returns a new Cookie.
  /// @synopsis Cookie(string name, string value)
  public static final Object[] newInstance = { "name", "value" };
  public static final Any newInstance(Any name, Any value)
  {
    return new AnyCookie(new Cookie(name.toString(), value.toString()));
  }
View Full Code Here

      if (nodeIdStr.length()==1) {
        nodeIdStr = "0"+nodeIdStr;
      }
      Cookie[] cookies = ureq.getHttpReq().getCookies();
      for (int i = 0; i < cookies.length; i++) {
        Cookie cookie = cookies[i];
        if ("JSESSIONID".equals(cookie.getName())) {
          String redirectedButInvalidSessionId = cookie.getValue();
          redirectedButInvalidSessionId = redirectedButInvalidSessionId.substring(0, redirectedButInvalidSessionId.length()-2) + nodeIdStr;
          Tracing.logInfo("redirecting session to node "+nodeIdStr+", new sessionid="+redirectedButInvalidSessionId, getClass());
          cookie.setValue(redirectedButInvalidSessionId);
          replaceCookie(ureq.getHttpReq(), ureq.getHttpResp(), cookie);
         
          // OLAT-5165: make sure we can always bypass the dmz reject mechanism (for 5min that is)
          Cookie newCookie = new Cookie("bypassdmzreject", String.valueOf(System.currentTimeMillis()));
          newCookie.setMaxAge(5 * 60); // 5min lifetime
          newCookie.setPath(WebappHelper.getServletContextPath());
          newCookie.setSecure(ureq.getHttpReq().isSecure());
          newCookie.setComment("cookie allowing olat admin users to bypass dmz rejects");
          ureq.getHttpResp().addCookie(newCookie);

          OncePanel oncePanel = new OncePanel("refresh");
          oncePanel.setContent(createVelocityContainer("refresh"));
          mainVc.put("refresh", oncePanel);
View Full Code Here

    }
    sb.append("<h4>Cookies in this hreq:</h4>");
    Cookie[] cookies = hreq.getCookies();
    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {
        Cookie cookie = cookies[i];
        appendFormattedKeyValue(sb, cookie.getName(), cookie.getValue());
      }
    }

    sb.append("<h4>Hreq parameters:</h4>");
    appendFormattedKeyValue(sb, "Request Is Secure", new Boolean(hreq.isSecure()));
View Full Code Here

   * @return the Cookie object
   */
  public static String getHomeSiteCookieValue(UserRequest ureq) {
    // get Cookie for preselection of HomeSite
    Cookie[] cookies = ureq.getHttpReq().getCookies();
    Cookie cookie = null;
    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {
        if (log.isDebug()) {
          log.debug("found cookie with name: " + cookies[i].getName() + " and value: " + cookies[i].getValue());
        }
        if (cookies[i].getName().equals(IDP_HOMESITE_COOKIE)) {
          cookie = cookies[i];
          break;
        }
      }
      if (cookie != null) {
        try {
          return URLDecoder.decode(cookie.getValue(), "utf-8");
        } catch (UnsupportedEncodingException e) {/* utf-8 is present */}
      }
    }
    // else cookie was null
    return null;
View Full Code Here

   *
   * @param homeSite
   * @param ureq
   */
  public static void setHomeSiteCookie(String homeSite, UserRequest ureq) {
    Cookie cookie = null;
    try {
      cookie = new Cookie(IDP_HOMESITE_COOKIE, URLEncoder.encode(homeSite, "utf-8"));
    } catch (UnsupportedEncodingException e) {/* utf-8 is always present */}
    cookie.setMaxAge(100 * 24 * 60 * 60); // 100 days lifetime
    cookie.setPath(WebappHelper.getServletContextPath());
    cookie.setComment("cookie for preselection of AAI homesite");
    ureq.getHttpResp().addCookie(cookie);
  }
View Full Code Here

  }

  private static void deleteShibsessionCookie(UserRequest ureq) {
    //  try to delete the "shibsession" cookie for this ureq, if any found
    Cookie[] cookies = ureq.getHttpReq().getCookies();
    Cookie cookie = null;
    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {           
        /*if(log.isDebug()) {
          log.info("found cookie with name: " + cookies[i].getName() + " and value: " + cookies[i].getValue());
        }*/
        if (cookies[i].getName().indexOf("shibsession")!=-1) { //contains "shibsession"
          cookie = cookies[i];
          break;
        }
      }
    }
    if(cookie!=null) {
      //A zero value causes the cookie to be deleted.
      cookie.setMaxAge(0);
      //cookie.setMaxAge(-1); //TODO: LD: check this out as well
      cookie.setPath("/");
      ureq.getHttpResp().addCookie(cookie);         
      if(log.isDebug()) {
        log.info("AuthHelper - shibsession cookie deleted");
      }         
    }
View Full Code Here

   * @param iAge lifetime of the cookie, in seconds, relative to "now". Negative=session cookie. Zero=delete this cookie.
   * @return true on success, false on error
   */
  public boolean setCookie(final String sName, final String sValue, final String sDomain, final int iAge) {
    try {
      final Cookie c = new Cookie(sName, sValue);

      c.setMaxAge(iAge);

      c.setDomain(sDomain);
      c.setPath("/"); //$NON-NLS-1$
      c.setSecure(false);

      this.response.addCookie(c);

      return true;
    } catch (Exception e) {
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.