mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
增加Cookie模式的secure、httpOnly、sameSite等配置
This commit is contained in:
@@ -2,12 +2,10 @@ package cn.dev33.satoken.servlet.model;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
|
||||
/**
|
||||
* Response for Servlet
|
||||
@@ -37,33 +35,6 @@ public class SaResponseForServlet implements SaResponse {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定Cookie
|
||||
*/
|
||||
@Override
|
||||
public void deleteCookie(String name) {
|
||||
addCookie(name, null, null, null, 0, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入指定Cookie
|
||||
*/
|
||||
@Override
|
||||
public void addCookie(String name, String value, String path, String domain, int timeout, boolean isHttpOnly, boolean isSecure) {
|
||||
Cookie cookie = new Cookie(name, value);
|
||||
if(SaFoxUtil.isEmpty(path) == true) {
|
||||
path = "/";
|
||||
}
|
||||
if(SaFoxUtil.isEmpty(domain) == false) {
|
||||
cookie.setDomain(domain);
|
||||
}
|
||||
cookie.setPath(path);
|
||||
cookie.setMaxAge(timeout);
|
||||
cookie.setHttpOnly(isHttpOnly);
|
||||
cookie.setSecure(isSecure);
|
||||
response.addCookie(cookie);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置响应状态码
|
||||
*/
|
||||
@@ -82,6 +53,17 @@ public class SaResponseForServlet implements SaResponse {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在响应头里添加一个值
|
||||
* @param name 名字
|
||||
* @param value 值
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaResponse addHeader(String name, String value) {
|
||||
response.addHeader(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重定向
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user