Example usage for javax.servlet.http Cookie setPath

List of usage examples for javax.servlet.http Cookie setPath

Introduction

In this page you can find the example usage for javax.servlet.http Cookie setPath.

Prototype

public void setPath(String uri) 

Source Link

Document

Specifies a path for the cookie to which the client should return the cookie.

Usage

From source file:org.glimpse.server.GlimpseUtils.java

public static void setConnectionId(HttpServletRequest request, HttpServletResponse response,
        String connectionId, boolean persistent) {
    Cookie cookie = new Cookie(COOKIE_CONNECTION, connectionId);
    cookie.setPath(request.getContextPath() + "/");
    if (!persistent) {
        cookie.setMaxAge(-1);/*from ww w.  j  a v a2 s.  c om*/
    } else {
        cookie.setMaxAge(365 * 24 * 60 * 60);
    }
    response.addCookie(cookie);
}

From source file:modelo.AutenticacionManager.Autenticacion.java

private static void variablesSession(HttpSession sesion, HttpServletResponse response, String login, String rol,
        String ip) {/*from   w  w  w . j  av a  2 s .  com*/

    //public static void variablesSession(HttpSession sesion, String login, String ip, String rol, String persona, String codigoPersona) {
    sesion.setAttribute("login", login);
    sesion.setAttribute("ip", ip);

    Cookie ssocookie = new Cookie("login", encode(login));
    ssocookie.setPath("/");
    response.addCookie(ssocookie);

    ssocookie = new Cookie("ip", encode(ip));
    ssocookie.setPath("/");
    response.addCookie(ssocookie);

    /*ssocookie = new Cookie("rol", encode(rol));
    ssocookie.setPath("/");
    response.addCookie(ssocookie);*/

}

From source file:com.eryansky.common.web.utils.RequestUtil.java

public static void setCookie(HttpServletResponse response, String name, String value, String path) {
    if (logger.isDebugEnabled()) {
        logger.debug("Cookie '" + name + "',?: '" + path + "'");
    }/*from ww  w. jav a2  s.  com*/

    Cookie cookie = new Cookie(name, value);
    cookie.setSecure(false);
    cookie.setPath(path);
    cookie.setMaxAge(2592000);

    response.addCookie(cookie);
}

From source file:com.usefullc.platform.common.utils.CookieUtils.java

/**
 * cookie//from  w  w w. j  a v a2 s  . c om
 * 
 * @param request
 * @param response
 * @param name
 */
public static void remove(String name, String domain) {
    Cookie cookie = new Cookie(name, "");
    cookie.setPath("/");
    cookie.setMaxAge(0);
    cookie.setDomain(domain);
    HttpServletResponse response = ServeltContextManager.getResponse();
    response.addCookie(cookie);
}

From source file:architecture.ee.web.util.CookieUtils.java

public static void setCookie(HttpServletRequest request, HttpServletResponse response, String name,
        String value, int maxAge) {
    if (value == null)
        value = "";
    String path = request.getContextPath() != null ? request.getContextPath() : "/";
    if ("".equals(path))
        path = "/";
    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge(maxAge);//from  w  w w.  ja v a2 s .  co  m
    cookie.setPath(path);
    response.addCookie(cookie);
}

From source file:com.eryansky.common.web.utils.RequestUtil.java

public static void deleteCookie(HttpServletResponse response, Cookie cookie, String path) {
    if (cookie != null) {
        cookie.setMaxAge(0);//w w w . ja v  a  2  s.  c  om
        cookie.setPath(path);
        response.addCookie(cookie);
    }
}

From source file:ru.org.linux.csrf.CSRFProtectionService.java

public static void generateCSRFCookie(HttpServletRequest request, HttpServletResponse response) {
    SecureRandom random = new SecureRandom();

    byte[] value = new byte[16];
    random.nextBytes(value);/* w  ww .  j  a v  a 2  s.  c  om*/

    String token = new String(Base64.encodeBase64(value));

    Cookie cookie = new Cookie(CSRF_COOKIE, token);
    cookie.setMaxAge(TWO_YEARS);
    cookie.setPath("/");
    response.addCookie(cookie);

    request.setAttribute(CSRF_ATTRIBUTE, token);
}

From source file:com.kamike.misc.CookieUtils.java

/**
 *
 * COOKIE//from   w w w  . j a v a2  s .c  o m
 *
 *
 *
 * @param name
 *
 * @param value
 *
 * @param maxAge
 *
 */
public static void setCookie(HttpServletRequest request, HttpServletResponse response, String name,
        String value, int maxAge) {

    Cookie cookie = new Cookie(name, value);

    cookie.setMaxAge(maxAge);

    cookie.setPath("/");

    response.addCookie(cookie);

}

From source file:net.webpasswordsafe.server.ServerSessionUtil.java

public static void initCsrfSession() {
    HttpSession session = getRequest().getSession(false);
    if (session.isNew() || (session.getAttribute(Constants.CSRF_TOKEN_KEY) == null)) {
        // either new session or old session without csrf token set, so set it
        session.setAttribute(Constants.CSRF_TOKEN_KEY, session.getId());
        Cookie cookie = new Cookie(Constants.CSRF_TOKEN_KEY, session.getId());
        cookie.setPath("".equals(getRequest().getContextPath()) ? "/" : getRequest().getContextPath());
        getResponse().addCookie(cookie);
    }//  w w  w  .j av a2  s  . co m
}

From source file:com.netsteadfast.greenstep.base.sys.UserCurrentCookie.java

public static void setCurrentId(HttpServletResponse response, String currentId, String sessionId,
        String account, String language) {
    try {//from www .  j a  v  a2  s .c o  m
        String value = currentId + Constants.ID_DELIMITER + sessionId + Constants.ID_DELIMITER + account
                + Constants.ID_DELIMITER + language;
        String encValue = EncryptorUtils.encrypt(Constants.getEncryptorKey1(), Constants.getEncryptorKey2(),
                value);
        encValue = SimpleUtils.toHex(encValue);
        Cookie cookie = new Cookie(Constants.APP_SITE_CURRENTID_COOKIE_NAME, encValue);
        cookie.setPath("/");
        cookie.setValue(encValue);
        cookie.setMaxAge(60 * 60 * 24); // 1-day
        cookie.setHttpOnly(true);
        response.addCookie(cookie);
    } catch (Exception e) {
        e.printStackTrace();
    }
}