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:fi.helsinki.opintoni.security.CustomAuthenticationSuccessHandler.java

private void addCookie(HttpServletResponse response, Cookie cookie) {
    cookie.setDomain("helsinki.fi");
    cookie.setPath("/");
    response.addCookie(cookie);//from  ww w  .  jav  a2  s  . c  om
}

From source file:com.demandware.vulnapp.challenge.impl.CookieChallenge.java

@SuppressWarnings("unchecked")
private Cookie generateCookie() {
    JSONObject o = new JSONObject();
    o.put(ACCESS_KEY, "false");
    String value = new String(Base64.encodeBase64(o.toJSONString().getBytes()));
    Cookie c = new Cookie(COOKIE_NAME, value);
    c.setMaxAge(MAX_AGE);//from ww w  .j  a  va2 s  .  com
    c.setPath("/");
    return c;
}

From source file:org.egov.infstr.security.spring.filter.CustomLogoutHandler.java

private void clearAllCookies(final HttpServletRequest request, final HttpServletResponse response) {
    final Cookie cookies[] = request.getCookies();
    if (cookies == null || cookies.length < 1)
        return;//from   ww  w .j a v a2  s .  co m
    for (final Cookie cookie : cookies) {
        cookie.setMaxAge(0);
        cookie.setPath("/");
        cookie.setValue(null);
        response.addCookie(cookie);
    }
}

From source file:com.reever.humilheme.web.CookieController.java

public Cookie createCookie(HttpServletRequest request, HttpServletResponse response, String conteudo) {
    String path = StringUtils.isEmpty(request.getContextPath()) ? "/" : request.getContextPath();
    try {//from  www.j  a  v a  2  s  .  c om
        conteudo = URLEncoder.encode(conteudo, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        _logger.error("Erro no encode do cookie", e);
    }
    Cookie cookie = new Cookie(nomeCookie, conteudo);
    cookie.setMaxAge(expiry);
    cookie.setPath(path);
    cookie.setVersion(1);
    response.addCookie(cookie);
    return cookie;
}

From source file:org.apache.hadoop.hive.hwi.servlet.RBase.java

/**
 * set current user/* w  w  w  .j a v a2  s  .co m*/
 * @param user
 */
protected void setUser(String user) {
    Cookie cookie = new Cookie(USER_COOKIE_NAME, user);
    cookie.setMaxAge(365 * 24 * 60 * 60);
    cookie.setPath("/hwi");
    response.addCookie(cookie);
}

From source file:org.nuxeo.ecm.mobile.webengine.WebMobileAuthentication.java

@GET
@Path("logout")
public Object doLogout(@Context HttpServletResponse response, @Context HttpServletRequest request)
        throws Exception {

    Cookie cookie = new Cookie("JSESSIONID", null);
    cookie.setMaxAge(0);/*w  ww .j a va 2 s .c  o  m*/
    cookie.setPath("/");

    response.addCookie(cookie);
    getService().invalidateSession(request);

    return redirect(getNuxeoContextPath());
}

From source file:net.lightbody.bmp.proxy.jetty.http.HashSSORealm.java

public void setSingleSignOn(HttpRequest request, HttpResponse response, Principal principal,
        Credential credential) {/*from   ww w . j  a va2 s  .c om*/

    String ssoID = null;

    synchronized (_ssoId2Principal) {
        // Create new SSO ID
        while (true) {
            ssoID = Long.toString(Math.abs(_random.nextLong()), 30 + (int) (System.currentTimeMillis() % 7));
            if (!_ssoId2Principal.containsKey(ssoID))
                break;
        }

        if (log.isDebugEnabled())
            log.debug("set ssoID=" + ssoID);
        _ssoId2Principal.put(ssoID, principal);
        _ssoPrincipal2Credential.put(principal, credential);
        _ssoUsername2Id.put(principal.getName(), ssoID);
    }

    Cookie cookie = new Cookie(SSO_COOKIE_NAME, ssoID);
    cookie.setPath("/");
    response.addSetCookie(cookie);
}

From source file:org.codice.ddf.security.servlet.logout.LocalLogoutServlet.java

private void deleteJSessionId(HttpServletResponse response) {
    Cookie cookie = new Cookie("JSESSIONID", "");
    cookie.setMaxAge(0);/* w ww  . j av a2s  .  co m*/
    cookie.setPath("/");
    cookie.setComment("EXPIRING COOKIE at " + System.currentTimeMillis());
    response.addCookie(cookie);
}

From source file:org.nuxeo.application.definition.MyApplication.java

@GET
@Path("logout")
public Object doLogout(@Context HttpServletResponse response) throws Exception {

    Cookie cookie = new Cookie("JSESSIONID", null);
    cookie.setMaxAge(0);/*from   ww w.ja  v a  2s .c  o m*/
    cookie.setPath("/");

    response.addCookie(cookie);
    getService().invalidateSession(request);

    String redirect = request.getParameter(REQUESTED_URL);
    if (redirect != null) {
        log.debug("Logout done: Redirect to default URL: " + redirect);
    } else {
        redirect = getContext().getBasePath();
    }
    return redirect(redirect);
}

From source file:com.haulmont.cuba.web.sys.AppCookies.java

public void addCookie(String name, String value, int maxAge) {
    if (isCookiesEnabled()) {
        if (StringUtils.isEmpty(value)) {
            removeCookie(name);/*from w  w  w .jav a  2 s .  co m*/
        } else {
            Cookie cookie = new Cookie(name, value);
            cookie.setPath(getCookiePath());
            cookie.setMaxAge(maxAge);
            addCookie(cookie);
        }
    }
}