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:net.mindengine.oculus.frontend.web.Auth.java

private static Cookie createCookie(String name, String value, int maxAge, String path) {
    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge(maxAge);// w  w  w .j av  a  2 s . c o  m
    cookie.setPath(path);
    return cookie;
}

From source file:ke.alphacba.cms.core.util.NoSessionIdUtils.java

private static void writeCookie(HttpServletResponse response, String loginCookieName, String domain,
        int cookieTime, String jsessionId, boolean httpOnly) {

    String cookieValue = new String(Base64.encodeBase64(new StringBuilder().append(loginCookieName)
            .append(new Date().getTime()).append(jsessionId).toString().getBytes()));
    Cookie cookie1 = new Cookie(loginCookieName, cookieValue);
    cookie1.setHttpOnly(true);//from w w w.  j  a  v  a  2s  .  c  o  m
    cookie1.setMaxAge(cookieTime);
    cookie1.setPath("/");
    cookie1.setDomain(domain);
    response.addCookie(cookie1);
}

From source file:alpha.portal.webapp.util.RequestUtil.java

/**
 * Convenience method to set a cookie.//from w  ww.j  a  va2s. c om
 * 
 * @param response
 *            the current response
 * @param name
 *            the name of the cookie
 * @param value
 *            the value of the cookie
 * @param path
 *            the path to set it on
 */
public static void setCookie(final HttpServletResponse response, final String name, final String value,
        final String path) {
    if (RequestUtil.log.isDebugEnabled()) {
        RequestUtil.log.debug("Setting cookie '" + name + "' on path '" + path + "'");
    }

    final Cookie cookie = new Cookie(name, value);
    cookie.setSecure(false);
    cookie.setPath(path);
    cookie.setMaxAge(3600 * 24 * 30); // 30 days

    response.addCookie(cookie);
}

From source file:org.kuali.continuity.security.SecurityUtil.java

public static void setRootCookie(String[] tokens, int maxAge, String key, HttpServletRequest request,
        HttpServletResponse response) {/*from   ww w. j  a  v  a  2s . co  m*/
    String cookieValue = encodeCookie(tokens);
    Cookie cookie = new Cookie(key, cookieValue);
    cookie.setMaxAge(maxAge);
    cookie.setPath("/");
    response.addCookie(cookie);
}

From source file:org.kuali.continuity.security.SecurityUtil.java

/**
 * Sets the cookie on the response//from ww w.j a  va2  s  . co m
 *
 * @param tokens the tokens which will be encoded to make the cookie value.
 * @param maxAge the value passed to {@link Cookie#setMaxAge(int)}
 * @param request the request
 * @param response the response to add the cookie to.
 */
public static void setCookie(String[] tokens, int maxAge, String key, HttpServletRequest request,
        HttpServletResponse response) {
    String cookieValue = encodeCookie(tokens);
    Cookie cookie = new Cookie(key, cookieValue);
    cookie.setMaxAge(maxAge);
    cookie.setPath(StringUtils.hasLength(request.getContextPath()) ? request.getContextPath() : "/");
    response.addCookie(cookie);
}

From source file:net.bluehornreader.web.WebUtils.java

private static void saveCookie(HttpServletResponse httpServletResponse, boolean secured, String name,
        String value, int expires) {
    Cookie cookie = new Cookie(name, value);
    cookie.setHttpOnly(true);//from  ww w  . j  ava  2 s.  com
    cookie.setMaxAge(expires);
    cookie.setPath("/");
    if (secured) {
        cookie.setSecure(true);
    }
    LOG.info(cookieAsString(cookie));
    httpServletResponse.addCookie(cookie);
}

From source file:io.syndesis.rest.v1.handler.credential.CredentialHandler.java

static void removeCredentialCookies(final HttpServletRequest request,
        final HttpServletResponse response) {
    Arrays.stream(request.getCookies())
            .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)).forEach(c -> {
                final Cookie removal = new Cookie(c.getName(), "");
                removal.setPath("/");
                removal.setMaxAge(0);/* ww  w  .j a v a  2 s . c  o  m*/
                removal.setHttpOnly(true);
                removal.setSecure(true);

                response.addCookie(removal);
            });
}

From source file:com.leixl.easyframework.web.CookieUtils.java

/**
 * ?cookie/* w ww.  ja v a  2s. com*/
 * 
 * @param request
 * @param response
 * @param name
 * @param domain
 */
public static void cancleCookie(HttpServletRequest request, HttpServletResponse response, String name,
        String domain) {
    Cookie cookie = new Cookie(name, "");
    cookie.setMaxAge(0);
    String ctx = request.getContextPath();
    cookie.setPath(StringUtils.isBlank(ctx) ? "/" : ctx);
    if (StringUtils.isNotBlank(domain)) {
        cookie.setDomain(domain);
    }
    response.addCookie(cookie);
}

From source file:com.wikipy.security.AuthenticationFilter.java

public static Cookie createNewCookie(HttpServletResponse httpResp) {
    Cookie cookie = new Cookie(ARG_TICKET, UUID.randomUUID().toString());
    cookie.setMaxAge(24 * 60 * 60);/*from  ww  w .jav  a  2  s.c o m*/
    cookie.setPath("/");
    httpResp.addCookie(cookie);
    return cookie;
}

From source file:com.aurel.track.master.ModuleBL.java

public static Cookie cretaeCookie(String cookieValue, String path, String url) {
    Cookie myCookie = new Cookie("JSESSIONID", cookieValue);
    myCookie.setPath(path);
    URI uri;/*from w w w  .ja v a  2 s .c  o  m*/
    try {
        uri = new URI(url);
        String domain = uri.getHost();
        myCookie.setDomain(domain);
    } catch (URISyntaxException e) {
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    return myCookie;
}