当前位置: 首页>>代码示例>>Java>>正文


Java Cookie.setSecure方法代码示例

本文整理汇总了Java中javax.servlet.http.Cookie.setSecure方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.setSecure方法的具体用法?Java Cookie.setSecure怎么用?Java Cookie.setSecure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.Cookie的用法示例。


在下文中一共展示了Cookie.setSecure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 往客户端写入Cookie
 * @param name cookie参数名
 * @param value cookie参数值
 * @param maxAge 有效时间,int(单位秒),0:删除Cookie,-1:页面关闭时删除cookie
 * @param path 与cookie一起传输的虚拟路径
 * @param domain 与cookie关联的域
 * @param isSecure 是否在https请求时才进行传输
 * @param isHttpOnly 是否只能通过http访问
 */
public void addCookie(String name, String value, int maxAge, String path, String domain, boolean isSecure, boolean isHttpOnly)
{
	Cookie cookie = new Cookie(name, value);
	cookie.setMaxAge(maxAge);
	cookie.setPath(path);
	if(maxAge > 0 && domain != null)
	{
		cookie.setDomain(domain);
	}
	cookie.setSecure(isSecure);
	try
	{
		Cookie.class.getMethod("setHttpOnly", boolean.class);
		cookie.setHttpOnly(isHttpOnly);
	}
	catch(Exception e)
	{
		System.out.println("MyCookie ignore setHttpOnly Method");
	}
	response.addCookie(cookie);
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:32,代码来源:MyCookie.java

示例2: copyProxyCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Copy cookie from the proxy to the servlet client. Replaces cookie path to local path and renames cookie to avoid
 * collisions.
 */
protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Header header) {
    List<HttpCookie> cookies = HttpCookie.parse(header.getValue());
    String path = servletRequest.getContextPath(); // path starts with / or is empty string
    path += servletRequest.getServletPath(); // servlet path starts with / or is empty string

    for (HttpCookie cookie : cookies) {
        // set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies
        String proxyCookieName = getCookieNamePrefix() + cookie.getName();
        Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
        servletCookie.setComment(cookie.getComment());
        servletCookie.setMaxAge((int) cookie.getMaxAge());
        servletCookie.setPath(path); // set to the path of the proxy servlet
        // don't set cookie domain
        servletCookie.setSecure(cookie.getSecure());
        servletCookie.setVersion(cookie.getVersion());
        servletResponse.addCookie(servletCookie);
    }
}
 
开发者ID:bluecreator,项目名称:http-agent,代码行数:23,代码来源:AgentServlet.java

示例3: shouldConvertServletCookieToJaxRsCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@Test
public void shouldConvertServletCookieToJaxRsCookie() {
    final Cookie given = new Cookie("myCookie", "myValue");
    given.setDomain("example.com");
    given.setPath("/path");
    given.setMaxAge(1800);
    given.setHttpOnly(true);
    given.setSecure(true);

    final javax.ws.rs.core.Cookie expected = new javax.ws.rs.core.Cookie("myCookie", "myValue", "/path",
        "example.com");

    assertThat(CredentialFlowStateHelper.toJaxRsCookie(given)).isEqualTo(expected);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:15,代码来源:CredentialFlowStateHelperTest.java

示例4: getCookies

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@Override
public Cookie[] getCookies() {
    String cookieString = this.originalRequest.headers().get(COOKIE);
    if (cookieString != null) {
        Set<io.netty.handler.codec.http.Cookie> cookies = CookieDecoder.decode(cookieString);
        if (!cookies.isEmpty()) {
            Cookie[] cookiesArray = new Cookie[cookies.size()];
            int indx = 0;
            for (io.netty.handler.codec.http.Cookie c : cookies) {
                Cookie cookie = new Cookie(c.name(), c.value());
                cookie.setComment(c.comment());
                cookie.setDomain(c.domain());
                cookie.setMaxAge((int) c.maxAge());
                cookie.setPath(c.path());
                cookie.setSecure(c.isSecure());
                cookie.setVersion(c.version());
                cookiesArray[indx] = cookie;
                indx++;
            }
            return cookiesArray;

        }
    }
    return null;
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:26,代码来源:HttpServletRequestImpl.java

示例5: removeCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private void removeCookie(J2EContext context) {
	Cookie cookie = new Cookie(ticketGrantingTicketCookieGenerator.getCookieName(), null); // Not necessary, but saves bandwidth.
	cookie.setPath(ticketGrantingTicketCookieGenerator.getCookiePath());
	cookie.setHttpOnly(true);
	cookie.setSecure(true);
	cookie.setMaxAge(0);
	context.getResponse().addCookie(cookie);
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:9,代码来源:OAuth20AuthorizeEndpointController.java

示例6: multipleCookies

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
void multipleCookies() {
    Cookie safeSecureCookie = new Cookie("cookie 3", "foo");
    safeSecureCookie.setSecure(true);

    // The line bellow should stay line 72 - It is used with the .atLine() annotation in the test
    Cookie unsafeSecureCookie = new Cookie("cookie 4", "bar");
    unsafeSecureCookie.setSecure(false);

    // The line bellow should stay line 76 - It is used with the .atLine() annotation in the test
    Cookie unsafeCookie = new Cookie("cookie 3", "foo");

    Cookie mixedCookiesSafe = new Cookie("cookie 4", "bar");
    // The line bellow should stay line 76 - It is used with the .atLine() annotation in the test
    Cookie mixedCookies = new Cookie("cookie 5", "bar");
    mixedCookiesSafe.setSecure(true);

    // The line bellow should stay line 84 - It is used with the .atLine() annotation in the test
    Cookie unsafeCookie2 = new Cookie("c1", "foo");
    unsafeCookie2.setSecure(false);

    Cookie safeCookie2 = new Cookie("c2", "bar");
    safeCookie2.setSecure(true);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:24,代码来源:InsecureCookieSamples.java

示例7: addCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Add a cookie with the given value to the response,
 * using the cookie descriptor settings of this generator.
 * <p>Delegates to {@link #createCookie} for cookie creation.
 * @param response the HTTP response to add the cookie to
 * @param cookieValue the value of the cookie to add
 * @see #setCookieName
 * @see #setCookieDomain
 * @see #setCookiePath
 * @see #setCookieMaxAge
 */
public void addCookie(HttpServletResponse response, String cookieValue) {
	Assert.notNull(response, "HttpServletResponse must not be null");
	Cookie cookie = createCookie(cookieValue);
	Integer maxAge = getCookieMaxAge();
	if (maxAge != null) {
		cookie.setMaxAge(maxAge);
	}
	if (isCookieSecure()) {
		cookie.setSecure(true);
	}
	if (isCookieHttpOnly()) {
		cookie.setHttpOnly(true);
	}
	response.addCookie(cookie);
	if (logger.isDebugEnabled()) {
		logger.debug("Added cookie with name [" + getCookieName() + "] and value [" + cookieValue + "]");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:CookieGenerator.java

示例8: safeCookie4

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
void safeCookie4() {
    boolean safe = true;
    Cookie cookie = new Cookie("test1","1234");
    cookie.setHttpOnly(false);
    cookie.setSecure(safe);
    cookie.setHttpOnly(false);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:8,代码来源:InsecureCookieSamples.java

示例9: setCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 设置记住密码cookie
 *
 * @param response
 * @param uid
 */
public static void setCookie(HttpServletResponse response, Integer uid) {
    try {
        String val = Tools.enAes(uid.toString(), WebConst.AES_SALT);
        boolean isSSL = false;
        Cookie cookie = new Cookie(WebConst.USER_IN_COOKIE, val);
        cookie.setPath("/");
        cookie.setMaxAge(60 * 30);
        cookie.setSecure(isSSL);
        response.addCookie(cookie);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:ZHENFENG13,项目名称:My-Blog,代码行数:20,代码来源:TaleUtils.java

示例10: addCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public void addCookie(final HttpServletRequest request, final HttpServletResponse response, final String cookieValue) {

        if (!StringUtils.hasText(request.getParameter(RememberMeCredential.REQUEST_PARAMETER_REMEMBER_ME))) {
            super.addCookie(response, cookieValue);
        } else {
            final Cookie cookie = createCookie(cookieValue);
            cookie.setMaxAge(this.rememberMeMaxAge);
            if (isCookieSecure()) {
                cookie.setSecure(true);
            }
            response.addCookie(cookie);
        }
    }
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:14,代码来源:CookieRetrievingCookieGenerator.java

示例11: addSecureParam

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private static void addSecureParam(HttpServletRequest request, Cookie cookie){
    if(cookie == null){
        return;
    }
    String schema = getScheme(request);
    if(schema != null && schema.toLowerCase().startsWith("https")){
        logger.debug("检测到是https请求,设置安全Cookie");
        cookie.setSecure(true);
    }
}
 
开发者ID:bridgeli,项目名称:netty-socketio-demo,代码行数:11,代码来源:CookieUtils.java

示例12: addCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 添加cookie
 * 
 * @param request
 *            HttpServletRequest
 * @param response
 *            HttpServletResponse
 * @param name
 *            cookie名称
 * @param value
 *            cookie值
 * @param maxAge
 *            有效期(单位: 秒)
 * @param path
 *            路径
 * @param domain
 *            域
 * @param secure
 *            是否启用加密
 */
public static void addCookie(HttpServletRequest request, HttpServletResponse response, String name, String value,
		Integer maxAge, String path, String domain, Boolean secure) {
	Assert.notNull(request);
	Assert.notNull(response);
	Assert.hasText(name);
	try {
		name = URLEncoder.encode(name, "UTF-8");
		value = URLEncoder.encode(value, "UTF-8");
		Cookie cookie = new Cookie(name, value);
		if (maxAge != null) {
			cookie.setMaxAge(maxAge);
		}
		if (StringUtils.isNotEmpty(path)) {
			cookie.setPath(path);
		}
		if (StringUtils.isNotEmpty(domain)) {
			cookie.setDomain(domain);
		}
		if (secure != null) {
			cookie.setSecure(secure);
		}
		response.addCookie(cookie);
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
}
 
开发者ID:wenjian-li,项目名称:spring_mybatis_shiro,代码行数:47,代码来源:CookieUtils.java

示例13: writeCookieValue

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public void writeCookieValue(CookieValue cookieValue) {
	HttpServletRequest request = cookieValue.getRequest();
	HttpServletResponse response = cookieValue.getResponse();

	String requestedCookieValue = cookieValue.getCookieValue();
	String actualCookieValue = this.jvmRoute == null ? requestedCookieValue
			: requestedCookieValue + this.jvmRoute;

	Cookie sessionCookie = new Cookie(this.cookieName, this.useBase64Encoding
			? base64Encode(actualCookieValue) : actualCookieValue);
	sessionCookie.setSecure(isSecureCookie(request));
	sessionCookie.setPath(getCookiePath(request));
	String domainName = getDomainName(request);
	if (domainName != null) {
		sessionCookie.setDomain(domainName);
	}

	if (this.useHttpOnlyCookie) {
		// sessionCookie.setHttpOnly(true);
	}

	if ("".equals(requestedCookieValue)) {
		sessionCookie.setMaxAge(0);
	}
	else if (this.rememberMeRequestAttribute != null
			&& request.getAttribute(this.rememberMeRequestAttribute) != null) {
		// the cookie is only written at time of session creation, so we rely on
		// session expiration rather than cookie expiration if remember me is enabled
		sessionCookie.setMaxAge(Integer.MAX_VALUE);
	}
	else {
		sessionCookie.setMaxAge(this.cookieMaxAge);
	}

	response.addCookie(sessionCookie);
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:37,代码来源:DefaultCookieSerializer.java

示例14: createSession

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 创建cookie
 * @param response
 * @return
 */
@RequestMapping(value = "/create", method = RequestMethod.GET)
@ResponseBody
public PrevalentMessage createSession(HttpServletResponse response) {

    Cookie cookie = new Cookie("token", UUID.randomUUID().toString());
    cookie.setPath("/");
    cookie.setSecure(false);
    cookie.setHttpOnly(true);
    cookie.setMaxAge(86400);
    cookie.setValue("test");
    response.addCookie(cookie);

    return new PrevalentMessage("ok");
}
 
开发者ID:lordking,项目名称:spring-rest-sample,代码行数:20,代码来源:CrossDomainSessionController.java

示例15: create

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static void create(HttpServletResponse httpServletResponse, String name, String value, Boolean secure, Integer maxAge, String domain) {
    Cookie cookie = new Cookie(name, value);
    cookie.setSecure(secure);
    cookie.setHttpOnly(true);
    cookie.setMaxAge(maxAge);
    cookie.setDomain(domain);
    cookie.setPath("/");
    httpServletResponse.addCookie(cookie);
}
 
开发者ID:hellokoding,项目名称:single-sign-on-out-resources-jwt-cookie-redis-springboot-freemarker,代码行数:10,代码来源:CookieUtil.java


注:本文中的javax.servlet.http.Cookie.setSecure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。