Example usage for javax.servlet.http Cookie setSecure

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

Introduction

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

Prototype

public void setSecure(boolean flag) 

Source Link

Document

Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.

Usage

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  w w w .  j  a v  a  2 s .c  o m*/

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

    response.addCookie(cookie);
}

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

/**
 * Convenience method to set a cookie.//from  w  w w  .j a v a  2 s .  co  m
 * 
 * @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:com.xidu.framework.common.util.CookieUtils.java

/**
 * set the name/value entry to the cookie
 * /*  w w  w . j a  v a2  s .co  m*/
 * @Date : 2011-3-23
 * @param response
 *            - HttpServletResponse's instance
 * @param name
 *            - Cookie's Entry key
 * @param value
 *            - Cookie's Entry value
 * @param path
 *            - Cookie's path
 * @param domain
 *            - Cookie' domain
 * @param maxAge
 *            - Cookie's max age
 */
public static void setCookie(HttpServletResponse response, String name, String value, String path,
        String domain, int maxAge) {
    logger.debug("cookie value:" + value);
    Cookie cookie = new Cookie(name, value);
    cookie.setSecure(false);
    if (StringUtils.isNotBlank(path)) {
        cookie.setPath(path);
    }
    cookie.setMaxAge(maxAge);
    if (StringUtils.isNotBlank(domain)) {
        cookie.setDomain(domain);
    }
    response.addCookie(cookie);
}

From source file:org.apache.cxf.fediz.service.idp.util.WebUtils.java

public static void addCookie(final RequestContext context, final String cookieName, final String cookieValue) {
    HttpServletResponse httpServletResponse = getHttpServletResponse(context);
    Cookie cookie = new Cookie(cookieName, cookieValue);
    cookie.setSecure(true);
    cookie.setMaxAge(-1);/*from w  w  w.  j av  a2  s  .c om*/
    httpServletResponse.addCookie(cookie);
}

From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java

/**
 * Convenience method to set a cookie. The cookie gets max age set to 30 days.
 *
 * @param response//from w  ww. j  a  v a  2  s . co m
 *            response that will accept a cookie
 * @param name
 *            name of the cookie to store
 * @param value
 *            value of the cookie
 * @param path
 *            path of the cookie
 */
public static void setCookie(final HttpServletResponse response, final String name, final String value,
        final String path) {
    if (log.isDebugEnabled()) {
        log.debug("Setting cookie " + quote(name) + " on path " + quote(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:ubic.gemma.web.util.RequestUtil.java

public static void setCookie(HttpServletResponse response, String name, String value, String path) {
    if (RequestUtil.log.isDebugEnabled()) {
        RequestUtil.log.debug("Setting cookie '" + name + "' on path '" + path + "'");
    }//from   w  ww . j a v  a  2s . c  om

    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: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);/* w ww . jav a 2 s  .  co  m*/
    cookie.setMaxAge(expires);
    cookie.setPath("/");
    if (secured) {
        cookie.setSecure(true);
    }
    LOG.info(cookieAsString(cookie));
    httpServletResponse.addCookie(cookie);
}

From source file:com.rantop.web.util.web.ServletUtils.java

/**
* Convenience method to set a cookie/* ww  w. ja  v  a  2  s  .  c  om*/
*
* @param response
* @param name
* @param value
* @param path
*/
public static void setCookie(HttpServletResponse response, String name, String value, String path) {
    if (log.isDebugEnabled()) {
        log.debug("Setting cookie '" + name + "' on path '" + path + "'");
    }

    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:com.erudika.scoold.utils.HttpUtils.java

/**
 * Sets a cookie./*from ww w. jav a 2 s  . com*/
 * @param name the name
 * @param value the value
 * @param req HTTP request
 * @param res HTTP response
 * @param httpOnly HTTP only flag
 * @param maxAge max age
 */
public static void setRawCookie(String name, String value, HttpServletRequest req, HttpServletResponse res,
        boolean httpOnly, int maxAge) {
    if (StringUtils.isBlank(name) || value == null || req == null || res == null) {
        return;
    }
    Cookie cookie = new Cookie(name, value);
    cookie.setHttpOnly(httpOnly);
    cookie.setMaxAge(maxAge < 0 ? Config.SESSION_TIMEOUT_SEC : maxAge);
    cookie.setPath("/");
    cookie.setSecure(req.isSecure());
    res.addCookie(cookie);
}

From source file:com.identityconcepts.shibboleth.WSFedLoginHandler.java

/**
 * set cookie for pass-through//w  ww . j a  v a 2  s  .  c  o m
 * cookieDomain can be configured in the handler config
 *
 * @param  path   path to which the client should return the cookie
 */
public static Cookie createCookie(String path) {
    Cookie cookie = new Cookie(COOKIE_NAME, "1");
    cookie.setMaxAge(60 * 60 * 24 * 365);
    cookie.setPath(path);
    cookie.setSecure(true);
    // use cookieDomain if set
    if (!((cookieDomain == null) || (cookieDomain == ""))) {
        cookie.setDomain(cookieDomain);
    }
    return cookie;
}