Example usage for javax.servlet.http Cookie setDomain

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

Introduction

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

Prototype

public void setDomain(String domain) 

Source Link

Document

Specifies the domain within which this cookie should be presented.

Usage

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

/**
 * cookie//from  www .ja  va2s.c o m
 * 
 * @param response
 * @param name
 * @param value
 * @param domain
 * @param expire
 */
public static void addCookie(HttpServletResponse response, String name, String value, String domain,
        Integer expire) {
    Cookie cookie = new Cookie(name, value);
    if (StringUtils.isNotEmpty(domain)) {
        cookie.setDomain(domain);
    }
    if (expire != null) {
        cookie.setMaxAge(expire);
    }
    cookie.setPath("/");
    response.addCookie(cookie);
}

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

/**
 * cookie//from  www .j  ava 2s .c  o  m
 * 
 * @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: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 2  s.  co m
    cookie1.setMaxAge(cookieTime);
    cookie1.setPath("/");
    cookie1.setDomain(domain);
    response.addCookie(cookie1);
}

From source file:com.hp.octane.integrations.testhelpers.OctaneSecuritySimulationUtils.java

static private Cookie createSecurityCookie(String client, String secret) {
    Cookie result = new Cookie(SECURITY_COOKIE_NAME, String.join(SECURITY_TOKEN_SEPARATOR, Stream
            .of(client, secret, String.valueOf(System.currentTimeMillis())).collect(Collectors.toList())));
    result.setHttpOnly(true);/*from   ww  w  .  j a v  a  2s  .  c om*/
    result.setDomain(".localhost");
    return result;
}

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

/**
 * ?cookie?/*w w w . j  ava2s .c o  m*/
 * 
 * @param request
 * @param response
 * @param name
 * @param value
 * @param expiry
 * @param domain
 * @return
 */
public static Cookie addCookie(HttpServletRequest request, HttpServletResponse response, String name,
        String value, Integer expiry, String domain) {
    Cookie cookie = new Cookie(name, value);
    if (expiry != null) {
        cookie.setMaxAge(expiry);
    }
    if (StringUtils.isNotBlank(domain)) {
        cookie.setDomain(domain);
    }
    String ctx = request.getContextPath();
    cookie.setPath(StringUtils.isBlank(ctx) ? "/" : ctx);
    response.addCookie(cookie);
    return cookie;
}

From source file:com.bacic5i5j.framework.toolbox.web.WebUtils.java

/**
 * cookie?/*from   w ww  .j  a va 2 s  .c o  m*/
 *
 * @param response
 * @param name
 * @param value
 * @param domain
 * @param expiry
 */
public static void setCookie(HttpServletResponse response, String name, String value, String domain,
        int expiry) {
    Cookie cookie = new Cookie(name, value);
    cookie.setDomain(domain);
    cookie.setPath("/");
    cookie.setMaxAge(expiry);

    response.addCookie(cookie);
}

From source file:org.apache.archiva.redback.integration.util.AutoLoginCookies.java

private static Cookie createCookie(String cookieName, String value, String domain, String path,
        HttpServletRequest httpRequest) {
    Cookie cookie = new Cookie(cookieName, value);
    if (domain != null) {
        cookie.setDomain(domain);
    }/* w  w w.jav a 2 s  .c  o m*/
    if (path != null) {
        cookie.setPath(path);
    } else {
        // default to the context path, otherwise you get /security and such in some places
        cookie.setPath(getWebappContext(httpRequest));
    }
    return cookie;
}

From source file:com.kingcore.framework.util.CookieUtils.java

/**
 *  domain clearCookie/*from w w w .jav a2s.  c  o  m*/
 *    The form of the domain name is specified by RFC 2109. A domain name begins with a dot (.foo.com) 
 *       and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone 
 *       (for example, www.foo.com, but not a.b.foo.com). By default, cookies are only returned to 
 *       the server that sent them.
 * @param name ?Cookie??
 * @param response ?
 * @param domain Cookie??
 */
public static void clearCookie(String name, HttpServletResponse response, String domain) {
    Cookie cookie = new Cookie(name, null);
    cookie.setMaxAge(0);
    cookie.setPath("/");
    cookie.setDomain(domain);
    response.addCookie(cookie);
}

From source file:com.kingcore.framework.util.CookieUtils.java

/**
 *  domain,path ? clearCookie// w ww  .  j  a v a 2 s. c o  m
 *    The form of the domain name is specified by RFC 2109. A domain name begins with a dot (.foo.com) 
 *       and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone 
 *       (for example, www.foo.com, but not a.b.foo.com). By default, cookies are only returned to 
 *       the server that sent them.
 * @param name ?Cookie??
 * @param response ?
 * @param domain Cookie??
 * @param path Cookie?
 */
public static void clearCookie(String name, HttpServletResponse response, String domain, String path) {
    Cookie cookie = new Cookie(name, null);
    cookie.setMaxAge(0);
    cookie.setPath(path);
    cookie.setDomain(domain);
    response.addCookie(cookie);
}

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

/**
 * ?cookie/*w w w  . j a v  a 2 s  . co  m*/
 * 
 * @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);
}