Skip to content

Commit

Permalink
v1.8.0更新
Browse files Browse the repository at this point in the history
  • Loading branch information
click33 committed Jan 1, 2021
1 parent 5ec35cc commit 2c6e656
Show file tree
Hide file tree
Showing 45 changed files with 1,104 additions and 894 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ unpackage/
.project

.factorypath
/.factorypath

.idea/
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<p align="center">
<img alt="logo" src="https://gitee.com/sz6/sa-token/raw/master/sa-token-doc/doc/logo.png" width="150" height="150" style="margin-bottom: 10px;">
</p>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">sa-token v1.7.0</h1>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">sa-token v1.8.0</h1>
<h4 align="center">一个JavaWeb轻量级权限认证框架,功能全面,上手简单</h4>
<h4 align="center">
<a href="https://gitee.com/sz6/sa-token/stargazers"><img src="https://gitee.com/sz6/sa-token/badge/star.svg"></a>
<a href="https://github.com/click33/sa-token"><img src="https://img.shields.io/badge/sa--token-v1.7.0-2B9939"></a>
<a href="https://github.com/click33/sa-token"><img src="https://img.shields.io/badge/sa--token-v1.8.0-2B9939"></a>
<a href="https://github.com/click33/sa-token/stargazers"><img src="https://img.shields.io/github/stars/click33/sa-token"></a>
<a href="https://github.com/click33/sa-token/watchers"><img src="https://img.shields.io/github/watchers/click33/sa-token"></a>
<a href="https://github.com/click33/sa-token/network/members"><img src="https://img.shields.io/github/forks/click33/sa-token"></a>
Expand All @@ -28,21 +28,18 @@


## ⭐ sa-token是什么?
- **sa-token是一个JavaWeb轻量级权限认证框架,其API调用非常简单,有多简单呢?以登录验证为例,你只需要:**
**sa-token是一个JavaWeb轻量级权限认证框架,其API调用非常简单,有多简单呢?以登录验证为例,你只需要:**

``` java
// 在登录时写入当前会话的账号id
StpUtil.setLoginId(10001);
```

StpUtil.setLoginId(10001);

- **然后在任意需要验证登录权限的地方:**
``` java
// 检测是否登录 --- 如果当前会话未登录,下面这句代码会抛出 `NotLoginException`异常
StpUtil.checkLogin();
// 然后在任意需要校验登录处调用以下API --- 如果当前会话未登录,这句代码会抛出 `NotLoginException`异常
StpUtil.checkLogin();
```


- **没有复杂的封装!不要任何的配置!先写入,后鉴权!只需这两行简单的调用,即可轻松完成系统登录鉴权!**
**没有复杂的封装!不要任何的配置!只需这两行简单的调用,即可轻松完成系统登录鉴权!**


## 🔥 框架设计思想
Expand All @@ -51,6 +48,24 @@ StpUtil.checkLogin();
- 功能强大:能涵盖的功能全部涵盖,不让你用个框架还要自己给框架打各种补丁


**如果上面的示例能够证明`sa-token`的简单,那么以下API则可以证明`sa-token`的强大**
``` java
StpUtil.setLoginId(10001); // 标记当前会话登录的账号id
StpUtil.getLoginId(); // 获取当前会话登录的账号id
StpUtil.isLogin(); // 获取当前会话是否已经登录, 返回true或false
StpUtil.logout(); // 当前会话注销登录
StpUtil.logoutByLoginId(10001); // 让账号为10001的会话注销登录(踢人下线)
StpUtil.hasRole("super-admin"); // 查询当前账号是否含有指定角色标识, 返回true或false
StpUtil.hasPermission("user:add"); // 查询当前账号是否含有指定权限, 返回true或false
StpUtil.getSession(); // 获取当前账号id的Session
StpUtil.getSessionByLoginId(10001); // 获取账号id为10001的Session
StpUtil.getTokenValueByLoginId(10001); // 获取账号id为10001的token令牌值
```
**sa-token的API众多,请恕此处无法为您逐一展示,更多示例请戳官方在线文档**




## 💦️️ 涵盖功能
- **登录验证** —— 轻松登录鉴权,并提供五种细分场景值
- **权限验证** —— 拦截违规调用,不同角色不同授权
Expand All @@ -59,7 +74,7 @@ StpUtil.checkLogin();
- **模拟他人账号** —— 实时操作任意用户状态数据
- **持久层扩展** —— 可集成redis、MongoDB等专业缓存中间件
- **多账号认证体系** —— 比如一个商城项目的user表和admin表分开鉴权
- **无cookie模式** —— APP、小程序等前后台分离场景
- **无Cookie模式** —— APP、小程序等前后台分离场景
- **注解式鉴权** —— 优雅的将鉴权与业务代码分离
- **花式token生成** —— 内置六种token风格,还可自定义token生成策略
- **自动续签** —— 提供两种token过期策略,灵活搭配使用,还可自动续签
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>cn.dev33</groupId>
<artifactId>sa-token-parent</artifactId>
<packaging>pom</packaging>
<version>1.7.0</version>
<version>1.8.0</version>

<!-- 项目介绍 -->
<name>sa-token</name>
Expand All @@ -21,6 +21,7 @@
<module>sa-token-core</module>
<module>sa-token-spring-boot-starter</module>
<module>sa-token-dao-redis</module>
<module>sa-token-dao-redis-jackson</module>
</modules>

<!-- 开源协议 apache 2.0 -->
Expand Down
2 changes: 1 addition & 1 deletion sa-token-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-parent</artifactId>
<version>1.7.0</version>
<version>1.8.0</version>
</parent>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public class SaTokenConfig {
/** token临时有效期 (指定时间内无操作就视为token过期) 单位/秒, 默认-1 代表不限制 (例如可以设置为1800代表30分钟内无操作就过期) */
private long activityTimeout = -1;

/** 在多人登录同一账号时,是否共享会话 (为true时共用一个,为false时新登录挤掉旧登录) */
/** 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) */
private Boolean allowConcurrentLogin = true;

/** 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) */
private Boolean isShare = true;

/** 是否尝试从请求体里读取token */
Expand All @@ -34,14 +37,13 @@ public class SaTokenConfig {
/** 默认dao层实现类中,每次清理过期数据间隔的时间 (单位: 秒) ,默认值30秒,设置为-1代表不启动定时清理 */
private int dataRefreshPeriod = 30;

/** 获取token专属session时是否必须登录 */
/** 获取token专属session时是否必须登录 (如果配置为true,会在每次获取token专属session时校验是否登录) */
private Boolean tokenSessionCheckLogin = true;

/** 是否在初始化配置时打印版本字符画 */
private Boolean isV = true;



/**
* @return tokenName
*/
Expand Down Expand Up @@ -69,7 +71,7 @@ public long getTimeout() {
public void setTimeout(long timeout) {
this.timeout = timeout;
}

/**
* @return activityTimeout
*/
Expand All @@ -83,7 +85,21 @@ public long getActivityTimeout() {
public void setActivityTimeout(long activityTimeout) {
this.activityTimeout = activityTimeout;
}


/**
* @return allowConcurrentLogin
*/
public Boolean getAllowConcurrentLogin() {
return allowConcurrentLogin;
}

/**
* @param allowConcurrentLogin 要设置的 allowConcurrentLogin
*/
public void setAllowConcurrentLogin(Boolean allowConcurrentLogin) {
this.allowConcurrentLogin = allowConcurrentLogin;
}

/**
* @return isShare
*/
Expand All @@ -99,19 +115,19 @@ public void setIsShare(Boolean isShare) {
}

/**
* @return isReadCookie
* @return isReadBody
*/
public Boolean getIsReadCookie() {
return isReadCookie;
public Boolean getIsReadBody() {
return isReadBody;
}

/**
* @param isReadCookie 要设置的 isReadCookie
* @param isReadBody 要设置的 isReadBody
*/
public void setIsReadCookie(Boolean isReadCookie) {
this.isReadCookie = isReadCookie;
public void setIsReadBody(Boolean isReadBody) {
this.isReadBody = isReadBody;
}

/**
* @return isReadHead
*/
Expand All @@ -127,19 +143,19 @@ public void setIsReadHead(Boolean isReadHead) {
}

/**
* @return isReadBody
* @return isReadCookie
*/
public Boolean getIsReadBody() {
return isReadBody;
public Boolean getIsReadCookie() {
return isReadCookie;
}

/**
* @param isReadBody 要设置的 isReadBody
* @param isReadCookie 要设置的 isReadCookie
*/
public void setIsReadBody(Boolean isReadBody) {
this.isReadBody = isReadBody;
public void setIsReadCookie(Boolean isReadCookie) {
this.isReadCookie = isReadCookie;
}

/**
* @return tokenStyle
*/
Expand All @@ -153,20 +169,6 @@ public String getTokenStyle() {
public void setTokenStyle(String tokenStyle) {
this.tokenStyle = tokenStyle;
}

/**
* @return isV
*/
public Boolean getIsV() {
return isV;
}

/**
* @param isV 要设置的 isV
*/
public void setIsV(Boolean isV) {
this.isV = isV;
}

/**
* @return dataRefreshPeriod
Expand Down Expand Up @@ -196,20 +198,31 @@ public void setTokenSessionCheckLogin(Boolean tokenSessionCheckLogin) {
this.tokenSessionCheckLogin = tokenSessionCheckLogin;
}



/**
* @return isV
*/
public Boolean getIsV() {
return isV;
}

/**
* 将对象转为String字符串
* @param isV 要设置的 isV
*/
public void setIsV(Boolean isV) {
this.isV = isV;
}



@Override
public String toString() {
return "SaTokenConfig [tokenName=" + tokenName + ", timeout=" + timeout + ", activityTimeout=" + activityTimeout
+ ", isShare=" + isShare + ", isReadBody=" + isReadBody + ", isReadHead=" + isReadHead
+ ", isReadCookie=" + isReadCookie + ", tokenStyle=" + tokenStyle + ", dataRefreshPeriod="
+ dataRefreshPeriod + ", tokenSessionCheckLogin=" + tokenSessionCheckLogin + ", isV=" + isV + "]";
+ ", allowConcurrentLogin=" + allowConcurrentLogin + ", isShare=" + isShare + ", isReadBody="
+ isReadBody + ", isReadHead=" + isReadHead + ", isReadCookie=" + isReadCookie + ", tokenStyle="
+ tokenStyle + ", dataRefreshPeriod=" + dataRefreshPeriod + ", tokenSessionCheckLogin="
+ tokenSessionCheckLogin + ", isV=" + isV + "]";
}




Expand Down
16 changes: 15 additions & 1 deletion sa-token-core/src/main/java/cn/dev33/satoken/dao/SaTokenDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public interface SaTokenDao {
*/
public long getTimeout(String key);

/**
* 修改指定key的剩余存活时间 (单位: 秒)
* @param key 指定key
* @param timeout 过期时间
*/
public void updateTimeout(String key, long timeout);


/**
* 根据指定key的Session,如果没有,则返回空
Expand Down Expand Up @@ -80,12 +87,19 @@ public interface SaTokenDao {
public void deleteSession(String sessionId);

/**
* 获取指定SaSession的剩余存活时间 (单位: 秒)
* 获取指定SaSession的剩余存活时间 (单位: 秒)
* @param sessionId 指定SaSession
* @return 这个SaSession的剩余存活时间 (单位: 秒)
*/
public long getSessionTimeout(String sessionId);

/**
* 修改指定SaSession的剩余存活时间 (单位: 秒)
* @param sessionId sessionId
* @param timeout 过期时间
*/
public void updateSessionTimeout(String sessionId, long timeout);




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public long getTimeout(String key) {
return getKeyTimeout(key);
}

@Override
public void updateTimeout(String key, long timeout) {
expireMap.put(key, System.currentTimeMillis() + timeout * 1000);
}


// ------------------------ Session 读写操作

Expand Down Expand Up @@ -104,8 +109,13 @@ public long getSessionTimeout(String sessionId) {
return getKeyTimeout(sessionId);
}

@Override
public void updateSessionTimeout(String sessionId, long timeout) {
expireMap.put(sessionId, System.currentTimeMillis() + timeout * 1000);
}


// ------------------------ Session 读写操作
// ------------------------ 过期时间相关操作

/**
* 如果指定key已经过期,则立即清除它
Expand Down Expand Up @@ -193,6 +203,11 @@ public void run() {
public void endRefreshTimer() {
this.refreshTimer.cancel();
}








Expand Down
Loading

0 comments on commit 2c6e656

Please sign in to comment.