[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AppleOfGray committed Jan 10, 2023
2 parents 24b6168 + c6c1ad1 commit 85f0f9f
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cn.dev33.satoken.basic.SaBasicTemplate;

/**
* Http Basic 认证:只有通过 Basic 认证后才能进入该方法
* Http Basic 认证校验:只有通过 Basic 认证后才能进入该方法
* <p> 可标注在函数、类上(效果等同于标注在此类的所有方法上)
* @author kong
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.lang.annotation.Target;

/**
* 登录认证:只有登录之后才能进入该方法
* 登录认证校验:只有登录之后才能进入该方法
* <p> 可标注在函数、类上(效果等同于标注在此类的所有方法上)
* @author kong
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.lang.annotation.Target;

/**
* 权限认证:必须具有指定权限才能进入该方法
* 权限认证校验:必须具有指定权限才能进入该方法
* <p> 可标注在函数、类上(效果等同于标注在此类的所有方法上)
* @author kong
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.lang.annotation.Target;

/**
* 角色认证:必须具有指定角色标识才能进入该方法
* 角色认证校验:必须具有指定角色标识才能进入该方法
* <p> 可标注在函数、类上(效果等同于标注在此类的所有方法上)
* @author kong
*
Expand Down
12 changes: 4 additions & 8 deletions sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,10 @@ protected String distUsableToken(Object id, SaLoginModel loginModel) {
if(isConcurrent) {
// 全局配置是否允许复用旧 Token
if(getConfigOfIsShare()) {
// 为确保 jwt-simple 模式的 token Extra 数据生成不受旧token影响,这里必须确保 is-share 配置项在 ExtraData 为空时才可以生效
// 即:在 login 时提供了 Extra 数据后,即使配置了 is-share=true 也不能复用旧 Token,必须创建新 Token
if(loginModel.isSetExtraData() == false) {
String tokenValue = getTokenValueByLoginId(id, loginModel.getDeviceOrDefault());
// 复用成功的话就直接返回,否则还是要继续新建Token
if(SaFoxUtil.isNotEmpty(tokenValue)) {
return tokenValue;
}
String tokenValue = getTokenValueByLoginId(id, loginModel.getDeviceOrDefault());
// 复用成功的话就直接返回,否则还是要继续新建Token
if(SaFoxUtil.isNotEmpty(tokenValue)) {
return tokenValue;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@SpringBootApplication
public class SaTokenAloneRedisClusterApplication {

public static void main(String[] args) throws ClassNotFoundException {
public static void main(String[] args) {
SpringApplication.run(SaTokenAloneRedisClusterApplication.class, args);
System.out.println("\n启动成功:Sa-Token配置如下:" + SaManager.getConfig());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sa-token:
# 配置Sa-Token单独使用的Redis连接
alone-redis:
# 普通集群
pattern: cluster
# pattern: cluster
# Redis服务器连接用户名(默认为空)
username:
# Redis服务器连接密码(默认为空)
Expand Down
36 changes: 18 additions & 18 deletions sa-token-demo/sa-token-demo-sso-client-vue2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions sa-token-doc/plugin/alone-redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ spring.redis.timeout=10s

具体可参考示例:[码云:application.yml](https://gitee.com/dromara/sa-token/blob/master/sa-token-demo/sa-token-demo-alone-redis/src/main/resources/application.yml)

集群配置说明: alone-redis同样可以配置集群(cluster模式和sentinel模式), 且基础配置参数和spring redis集群配置别无二致

集群配置示例可参考demo项目sa-token-demo-alone-redis-cluster


### 3、测试
新建Controller测试一下
Expand Down
20 changes: 20 additions & 0 deletions sa-token-doc/plugin/jwt-extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,23 @@ public void setSaJwtTemplate() {
});
}
```


### 9、注意点

##### 1、使用 jwt-simple 模式后,is-share=false 恒等于 false。

`is-share=true` 的意思是每次登录都产生一样的 token,这种策略和 [ 为每个 token 单独设定 setExtra 数据 ] 不兼容的,
为保证正确设定 Extra 数据,当使用 `jwt-simple` 模式后,`is-share` 配置项 恒等于 `false`


##### 2、使用 jwt-mixin 模式后,is-concurrent 必须为 true。

`is-concurrent=false` 代表每次登录都把旧登录顶下线,但是 jwt-mixin 模式登录的 token 并不会记录在持久库数据中,
技术上来讲无法将其踢下线,所以此时顶人下线和踢人下线等 API 都属于不可用状态,所以此时 `is-concurrent` 配置项必须配置为 `true`






Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ public Object getExtra(String tokenValue, String key) {
return SaJwtUtil.getPayloadsNotCheck(tokenValue, loginType, jwtSecretKey()).get(key);
}


@Override
public boolean getConfigOfIsShare() {
// 为确保 jwt-simple 模式的 token Extra 数据生成不受旧token影响,这里必须让 is-share 恒为 false
// 即:在使用 jwt-simple 模式后,即使配置了 is-share=true 也不能复用旧 Token,必须每次创建新 Token
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ public Object ssoLogoutType2() {
StpLogic stpLogic = ssoTemplate.getStpLogic();

// 开始处理
stpLogic.logout();
if(stpLogic.isLogin()) {
stpLogic.logout(stpLogic.getLoginId());
}

// 返回
return ssoLogoutBack(req, res);
Expand All @@ -337,7 +339,7 @@ public Object ssoLogoutType3() {

// 如果未登录,则无需注销
if(stpLogic.isLogin() == false) {
return SaResult.ok();
return ssoLogoutBack(req, res);
}

// 调用 sso-server 认证中心单点注销API
Expand Down

0 comments on commit 85f0f9f

Please sign in to comment.