本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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 + "]");
}
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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");
}
示例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