mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-05-03 20:27:54 +08:00
Merge branch 'dev' of github.com:dromara/sa-token into dev
This commit is contained in:
commit
3e09e68b6e
@ -41,6 +41,12 @@ public class SaTokenConfig implements Serializable {
|
|||||||
/** 是否尝试从cookie里读取token */
|
/** 是否尝试从cookie里读取token */
|
||||||
private Boolean isReadCookie = true;
|
private Boolean isReadCookie = true;
|
||||||
|
|
||||||
|
/** 使用Cookie时,是否为HttpOnly */
|
||||||
|
private Boolean isCookieHttpOnly = false;
|
||||||
|
|
||||||
|
/** 使用Cookie时,是否为Secure */
|
||||||
|
private Boolean isCookieSecure = false;
|
||||||
|
|
||||||
/** token风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik) */
|
/** token风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik) */
|
||||||
private String tokenStyle = "uuid";
|
private String tokenStyle = "uuid";
|
||||||
|
|
||||||
@ -220,6 +226,38 @@ public class SaTokenConfig implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 使用Cookie时,是否为HttpOnly
|
||||||
|
*/
|
||||||
|
public Boolean getIsCookieHttpOnly() {
|
||||||
|
return isCookieHttpOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param isCookieHttpOnly 使用Cookie时,是否为HttpOnly
|
||||||
|
* @return 对象自身
|
||||||
|
*/
|
||||||
|
public SaTokenConfig setIsCookieHttpOnly(Boolean isCookieHttpOnly) {
|
||||||
|
this.isCookieHttpOnly = isCookieHttpOnly;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 使用Cookie时,是否为Secure
|
||||||
|
*/
|
||||||
|
public Boolean getIsCookieSecure() {
|
||||||
|
return isCookieSecure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param isCookieSecure 使用Cookie时,是否为Secure
|
||||||
|
* @return 对象自身
|
||||||
|
*/
|
||||||
|
public SaTokenConfig setIsCookieSecure(Boolean isCookieSecure) {
|
||||||
|
this.isCookieSecure = isCookieSecure;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return token风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
* @return token风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||||
*/
|
*/
|
||||||
@ -433,7 +471,9 @@ public class SaTokenConfig implements Serializable {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "SaTokenConfig [tokenName=" + tokenName + ", timeout=" + timeout + ", activityTimeout=" + activityTimeout
|
return "SaTokenConfig [tokenName=" + tokenName + ", timeout=" + timeout + ", activityTimeout=" + activityTimeout
|
||||||
+ ", isConcurrent=" + isConcurrent + ", isShare=" + isShare + ", isReadBody=" + isReadBody
|
+ ", isConcurrent=" + isConcurrent + ", isShare=" + isShare + ", isReadBody=" + isReadBody
|
||||||
+ ", isReadHead=" + isReadHead + ", isReadCookie=" + isReadCookie + ", tokenStyle=" + tokenStyle
|
+ ", isReadHead=" + isReadHead + ", isReadCookie=" + isReadCookie
|
||||||
|
+ ", isCookieHttpOnly=" + isCookieHttpOnly + ", isCookieSecure=" + isCookieSecure
|
||||||
|
+ ", tokenStyle=" + tokenStyle
|
||||||
+ ", dataRefreshPeriod=" + dataRefreshPeriod + ", tokenSessionCheckLogin=" + tokenSessionCheckLogin
|
+ ", dataRefreshPeriod=" + dataRefreshPeriod + ", tokenSessionCheckLogin=" + tokenSessionCheckLogin
|
||||||
+ ", autoRenew=" + autoRenew + ", cookieDomain=" + cookieDomain + ", tokenPrefix=" + tokenPrefix
|
+ ", autoRenew=" + autoRenew + ", cookieDomain=" + cookieDomain + ", tokenPrefix=" + tokenPrefix
|
||||||
+ ", isPrint=" + isPrint + ", isLog=" + isLog + ", jwtSecretKey=" + jwtSecretKey + ", idTokenTimeout="
|
+ ", isPrint=" + isPrint + ", isLog=" + isLog + ", jwtSecretKey=" + jwtSecretKey + ", idTokenTimeout="
|
||||||
|
@ -26,8 +26,10 @@ public interface SaResponse {
|
|||||||
* @param path Cookie路径
|
* @param path Cookie路径
|
||||||
* @param domain Cookie的作用域
|
* @param domain Cookie的作用域
|
||||||
* @param timeout 过期时间 (秒)
|
* @param timeout 过期时间 (秒)
|
||||||
|
* @param isHttpOnly 是否为HttpOnly
|
||||||
|
* @param isSecure 是否为Secure
|
||||||
*/
|
*/
|
||||||
public void addCookie(String name, String value, String path, String domain, int timeout);
|
public void addCookie(String name, String value, String path, String domain, int timeout, boolean isHttpOnly, boolean isSecure);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置响应状态码
|
* 设置响应状态码
|
||||||
|
@ -111,7 +111,7 @@ public class StpLogic {
|
|||||||
// 注入Cookie
|
// 注入Cookie
|
||||||
if (config.getIsReadCookie()) {
|
if (config.getIsReadCookie()) {
|
||||||
SaResponse response = SaHolder.getResponse();
|
SaResponse response = SaHolder.getResponse();
|
||||||
response.addCookie(getTokenName(), tokenValue, "/", config.getCookieDomain(), cookieTimeout);
|
response.addCookie(getTokenName(), tokenValue, "/", config.getCookieDomain(), cookieTimeout, config.getIsCookieHttpOnly(), config.getIsCookieSecure());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +143,8 @@ StpUtil.switchTo(10044); // 将当前会话身份临时切换
|
|||||||
|
|
||||||
- **[ easy-admin ]**:[一个基于SpringBoot2 + Sa-Token + Mybatis-Plus + Snakerflow + Layui 的后台管理系统,灵活多变可前后端分离,也可单体,内置代码生成器、权限管理、工作流引擎等](https://gitee.com/lakernote/easy-admin)
|
- **[ easy-admin ]**:[一个基于SpringBoot2 + Sa-Token + Mybatis-Plus + Snakerflow + Layui 的后台管理系统,灵活多变可前后端分离,也可单体,内置代码生成器、权限管理、工作流引擎等](https://gitee.com/lakernote/easy-admin)
|
||||||
|
|
||||||
|
- **[ RuoYi-Vue-Plus ]**:[基于RuoYi-Vue集成 SaToken+Lombok+Mybatis-Plus+Undertow+knife4j+Hutool+Feign 重写所有原生业务 定期与RuoYi-Vue同步](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus/tree/satoken/)
|
||||||
|
|
||||||
如果您的项目使用了Sa-Token,欢迎提交pr
|
如果您的项目使用了Sa-Token,欢迎提交pr
|
||||||
|
|
||||||
## 友情链接
|
## 友情链接
|
||||||
|
@ -43,20 +43,21 @@ public class SaResponseForReactor implements SaResponse {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteCookie(String name) {
|
public void deleteCookie(String name) {
|
||||||
addCookie(name, null, null, null, 0);
|
addCookie(name, null, null, null, 0, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入指定Cookie
|
* 写入指定Cookie
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addCookie(String name, String value, String path, String domain, int timeout) {
|
public void addCookie(String name, String value, String path, String domain, int timeout, boolean isHttpOnly, boolean isSecure) {
|
||||||
|
|
||||||
// 构建CookieBuilder
|
// 构建CookieBuilder
|
||||||
ResponseCookieBuilder builder = ResponseCookie.from(name, value)
|
ResponseCookieBuilder builder = ResponseCookie.from(name, value)
|
||||||
.domain(domain)
|
.domain(domain)
|
||||||
.path(path)
|
.path(path)
|
||||||
.maxAge(timeout)
|
.maxAge(timeout)
|
||||||
|
.httpOnly(isHttpOnly)
|
||||||
|
.secure(isHttpOnly)
|
||||||
;
|
;
|
||||||
|
|
||||||
// set path
|
// set path
|
||||||
|
@ -42,14 +42,14 @@ public class SaResponseForServlet implements SaResponse {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteCookie(String name) {
|
public void deleteCookie(String name) {
|
||||||
addCookie(name, null, null, null, 0);
|
addCookie(name, null, null, null, 0, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入指定Cookie
|
* 写入指定Cookie
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addCookie(String name, String value, String path, String domain, int timeout) {
|
public void addCookie(String name, String value, String path, String domain, int timeout, boolean isHttpOnly, boolean isSecure) {
|
||||||
Cookie cookie = new Cookie(name, value);
|
Cookie cookie = new Cookie(name, value);
|
||||||
if(SaFoxUtil.isEmpty(path) == true) {
|
if(SaFoxUtil.isEmpty(path) == true) {
|
||||||
path = "/";
|
path = "/";
|
||||||
@ -59,6 +59,8 @@ public class SaResponseForServlet implements SaResponse {
|
|||||||
}
|
}
|
||||||
cookie.setPath(path);
|
cookie.setPath(path);
|
||||||
cookie.setMaxAge(timeout);
|
cookie.setMaxAge(timeout);
|
||||||
|
cookie.setHttpOnly(isHttpOnly);
|
||||||
|
cookie.setSecure(isSecure);
|
||||||
response.addCookie(cookie);
|
response.addCookie(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public class SaResponseForSolon implements SaResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCookie(String name, String value, String path, String domain, int timeout) {
|
public void addCookie(String name, String value, String path, String domain, int timeout, boolean isHttpOnly, boolean isSecure) {
|
||||||
if (Utils.isNotEmpty(path)) {
|
if (Utils.isNotEmpty(path)) {
|
||||||
path = "/";
|
path = "/";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user