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:org.jcronjob.session.HttpSessionFilter.java

private Cookie generateCookie(HttpServletRequest request, HttpServletResponse response) {
    Cookie sessionIdCookie;
    String sid = null;//from  w  w w. j  a  v  a  2s . c  o  m
    if (StringUtils.isBlank(sid)) {
        sid = generateUUID();
    }
    sessionIdCookie = new Cookie(sessionIdCookieName, sid);

    String domain = request.getServerName();

    if (domain != null) {
        sessionIdCookie.setDomain(domain);
    }

    sessionIdCookie.setPath("/");
    response.addCookie(sessionIdCookie);
    return sessionIdCookie;
}

From source file:com.zz.globalsession.filter.AbstractGlobalSessionFilter.java

private Cookie generateSessionIdCookie(String sessionIdValue) {

    Cookie sessionIdCookie = new Cookie(settings.getSessionIdKey(), sessionIdValue);
    if (settings.getDomain() != null) {
        sessionIdCookie.setDomain(settings.getDomain());
    }// www . ja  v  a  2  s .co m
    if (settings.getPath() != null) {
        sessionIdCookie.setPath(settings.getPath());
    } else {
        sessionIdCookie.setPath("/");
    }
    if (settings.isSecure())
        sessionIdCookie.setSecure(settings.isSecure());
    // [Note] httpOnly is not supported by Servlet API 2.x, so add it
    // manually later.
    return sessionIdCookie;
}

From source file:org.xwiki.contrib.authentication.internal.CookieAuthenticationPersistenceStore.java

/**
 * Set the authentication cookie to the given value and max age.
 * @param value the value to be set.// ww w.ja va  2s.  c o  m
 * @param maxAge the maximum age of the cookie.
 */
private void setAuthenticationCookie(String value, int maxAge) {
    XWikiContext context = contextProvider.get();

    Cookie cookie = new Cookie(cookiePfx + AUTHENTICATION_COOKIE, value);
    cookie.setMaxAge(maxAge);
    cookie.setPath(cookiePath);
    String cookieDomain = getCookieDomain();
    if (cookieDomain != null) {
        cookie.setDomain(cookieDomain);
    }
    if (context.getRequest().isSecure()) {
        cookie.setSecure(true);
    }
    context.getResponse().addCookie(cookie);
}

From source file:org.mule.transport.http.servlet.MuleHttpServletResponse.java

private org.apache.commons.httpclient.Cookie toHttpClientCookie(Cookie cookie) {
    org.apache.commons.httpclient.Cookie internal = new org.apache.commons.httpclient.Cookie();

    internal.setName(cookie.getName());/* www.  jav  a 2  s  . c om*/
    internal.setValue(cookie.getValue());
    internal.setComment(cookie.getComment());
    internal.setDomain(cookie.getDomain());
    //        internal.setExpiryDate(toExpiry(cookie.getMaxAge()));
    internal.setPath(cookie.getPath());
    internal.setVersion(cookie.getVersion());

    return internal;
}

From source file:fr.paris.lutece.plugins.mylutece.modules.openam.service.OpenamService.java

/**
 * set a paris connect cokkie in the HttpServletResponse
 *
 * @param strPCUID/*from  w ww  . j  av a 2  s.  co  m*/
 *            the user PCUID
 * @param response
 *            The HTTP response
 */
public void removeConnectionCookie(HttpServletResponse response) {
    // remove  openam cookie using the setMaxAgeParameters
    Cookie openamCookie = new Cookie(COOKIE_OPENAM_NAME, null);
    openamCookie.setDomain(COOKIE_OPENAM_DOMAIN);
    openamCookie.setSecure(COOKIE_OPENAM_SECURE);
    openamCookie.setMaxAge(0);
    openamCookie.setPath(COOKIE_OPENAM_PATH);
    response.addCookie(openamCookie);
}

From source file:org.orcid.core.manager.impl.InternalSSOManagerImpl.java

@Override
public void deleteToken(String orcid, HttpServletRequest request, HttpServletResponse response) {
    this.deleteToken(orcid);
    // Delete the cookie
    if (request.getCookies() != null) {
        for (Cookie cookie : request.getCookies()) {
            if (cookie.getName().equals(COOKIE_NAME)) {
                cookie.setMaxAge(0);/*w w w.  j  a  v  a2 s  .c  o m*/
                cookie.setValue(StringUtils.EMPTY);
                cookie.setSecure(true);
                cookie.setHttpOnly(true);
                cookie.setDomain(allowedDomain.trim());
                response.addCookie(cookie);
            }
        }
    }
}

From source file:fr.paris.lutece.plugins.mylutece.modules.openam.service.OpenamService.java

/**
 * set a paris connect cokkie in the HttpServletResponse
 *
 * @param strPCUID// w  ww  . ja v  a2s.  c om
 *            the user PCUID
 * @param response
 *            The HTTP response
 */
public void setConnectionCookie(String strPCUID, HttpServletResponse response) {
    // set a connexion cookie to let the user access other PC Services
    // without sign in
    Cookie openamCookie = new Cookie(COOKIE_OPENAM_NAME, strPCUID);
    openamCookie.setDomain(COOKIE_OPENAM_DOMAIN);
    openamCookie.setSecure(COOKIE_OPENAM_SECURE);
    openamCookie.setMaxAge(COOKIE_OPENAM_MAX_AGE);
    openamCookie.setPath(COOKIE_OPENAM_PATH);

    response.addCookie(openamCookie);
}

From source file:com.shenit.commons.utils.HttpUtils.java

/**
 * cookie//from  w  w w.ja  v  a  2 s. com
 * 
 * @param name
 *            Cookie??
 * @param val
 *            
 * @param expiry
 *            
 * @param domain
 *            
 * @param path
 *            
 * @param httpOnly
 *            ??HTTPcooie
 * @param secure
 *            ?SSL
 * @return
 */
public static Cookie cookie(String name, Object val, Integer expiry, String domain, String path,
        boolean httpOnly, boolean secure) {
    Cookie cookie = new Cookie(name, val == null ? null : val.toString());
    if (expiry != null)
        cookie.setMaxAge(expiry);
    if (!StringUtils.isEmpty(domain))
        cookie.setDomain(domain);
    cookie.setSecure(secure);
    if (!StringUtils.isEmpty(path))
        cookie.setPath(path);
    cookie.setHttpOnly(httpOnly);
    return cookie;
}

From source file:it.scoppelletti.programmerpower.web.security.SsoRememberMeServices.java

/**
 * Inizializza il cookie per l’autenticazione persistente.
 * /*  w  ww.  j  av  a 2 s.c o  m*/
 * @param  value  Valore.
 * @param  maxAge Scadenza.
 * @return        Oggetto.
 */
private Cookie buildCookie(String value, int maxAge) {
    Cookie cookie;

    cookie = new Cookie(getCookieName(), value);
    if (myCookieDomain != null) {
        cookie.setDomain(myCookieDomain);
    }
    cookie.setPath(myCookiePath);
    cookie.setMaxAge(maxAge);

    return cookie;
}

From source file:com.xpn.xwiki.stats.impl.StatsUtil.java

/**
 * Create a new visit cookie and return it.
 * //from ww w .  j  av a2  s  . c om
 * @param context the XWiki context.
 * @return the newly created cookie.
 * @since 1.4M1
 */
protected static Cookie addCookie(XWikiContext context) {
    Cookie cookie = new Cookie(COOKPROP_VISITID, RandomStringUtils.randomAlphanumeric(32).toUpperCase());
    cookie.setPath("/");

    int time = (int) (getCookieExpirationDate().getTime() - (new Date()).getTime()) / 1000;
    cookie.setMaxAge(time);

    String cookieDomain = null;
    getCookieDomains(context);
    if (cookieDomains != null) {
        String servername = context.getRequest().getServerName();
        for (int i = 0; i < cookieDomains.length; i++) {
            if (servername.indexOf(cookieDomains[i]) != -1) {
                cookieDomain = cookieDomains[i];
                break;
            }
        }
    }

    if (cookieDomain != null) {
        cookie.setDomain(cookieDomain);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Setting cookie " + cookie.getValue() + " for name " + cookie.getName() + " with domain "
                + cookie.getDomain() + " and path " + cookie.getPath() + " and maxage " + cookie.getMaxAge());
    }

    context.getResponse().addCookie(cookie);

    return cookie;
}