Skip to content

Commit

Permalink
修复 quick-login 插件循环依赖问题
Browse files Browse the repository at this point in the history
  • Loading branch information
click33 committed Apr 23, 2022
1 parent 7302a34 commit 0c0b08c
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public static Object ssoLogoutCall() {
String secretkey = req.getParam(ParamName.secretkey);

SaSsoUtil.checkSecretkey(secretkey);
stpLogic.logoutByTokenValue(stpLogic.getTokenValueByLoginId(loginId));
stpLogic.logout(loginId);
return SaSsoConsts.OK;
}

Expand Down
1 change: 1 addition & 0 deletions sa-token-demo/sa-token-demo-quick-login/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<!-- <version>2.6.0</version> -->
</parent>

<!-- 定义sa-token版本号 -->
Expand Down
4 changes: 2 additions & 2 deletions sa-token-doc/doc/fun/not-login-scene.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
``` java
// 全局异常拦截(拦截项目中的NotLoginException异常)
@ExceptionHandler(NotLoginException.class)
public AjaxJson handlerNotLoginException(NotLoginException nle, HttpServletRequest request, HttpServletResponse response)
public SaResult handlerNotLoginException(NotLoginException nle)
throws Exception {

// 打印堆栈,以供调试
Expand Down Expand Up @@ -51,7 +51,7 @@ public AjaxJson handlerNotLoginException(NotLoginException nle, HttpServletReque
}

// 返回给前端
return AjaxJson.getError(message);
return SaResult.error(message);
}
```

Expand Down
8 changes: 4 additions & 4 deletions sa-token-doc/doc/plugin/alone-redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ public class TestController {

// 测试Sa-Token缓存
@RequestMapping("login")
public AjaxJson login(@RequestParam(defaultValue="10001") String id) {
public SaResult login(@RequestParam(defaultValue="10001") String id) {
System.out.println("--------------- 测试Sa-Token缓存");
StpUtil.login(id);
return AjaxJson.getSuccess();
return SaResult.ok();
}

// 测试业务缓存
@RequestMapping("test")
public AjaxJson test() {
public SaResult test() {
System.out.println("--------------- 测试业务缓存");
stringRedisTemplate.opsForValue().set("hello", "Hello World");
return AjaxJson.getSuccess();
return SaResult.ok();
}

}
Expand Down
2 changes: 1 addition & 1 deletion sa-token-doc/doc/start/webflux-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class SaTokenConfigure {
// 指定[异常处理函数]:每次[认证函数]发生异常时执行此函数
.setError(e -> {
System.out.println("---------- sa全局异常 ");
return AjaxJson.getError(e.getMessage());
return SaResult.error(e.getMessage());
})
;
}
Expand Down
2 changes: 1 addition & 1 deletion sa-token-doc/doc/up/global-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class SaTokenConfigure {
// 异常处理函数:每次认证函数发生异常时执行此函数
.setError(e -> {
System.out.println("---------- 进入Sa-Token异常处理 -----------");
return AjaxJson.getError(e.getMessage());
return SaResult.error(e.getMessage());
})

// 前置函数:在每次认证函数之前执行
Expand Down
8 changes: 4 additions & 4 deletions sa-token-doc/doc/use/at-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public String add() {
// 注解式鉴权:只要具有其中一个权限即可通过校验
@RequestMapping("atJurOr")
@SaCheckPermission(value = {"user-add", "user-all", "user-delete"}, mode = SaMode.OR)
public AjaxJson atJurOr() {
return AjaxJson.getSuccessData("用户信息");
public SaResult atJurOr() {
return SaResult.data("用户信息");
}
```

Expand All @@ -103,8 +103,8 @@ mode有两种取值:
// 注解式鉴权:只要具有其中一个权限即可通过校验
@RequestMapping("userAdd")
@SaCheckPermission(value = "user-add", orRole = "admin")
public AjaxJson userAdd() {
return AjaxJson.getSuccessData("用户信息");
public SaResult userAdd() {
return SaResult.data("用户信息");
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cn.dev33.satoken.quick;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import cn.dev33.satoken.quick.config.SaQuickConfig;
import cn.dev33.satoken.quick.web.SaQuickController;

/**
* Quick-Bean 注入
*
* @author kong
*
*/
@Configuration
@Import({ SaQuickController.class, SaQuickRegister.class})
public class SaQuickInject {

/**
* 注入quick-login 配置
*
* @param saQuickConfig 配置对象
*/
@Autowired
public void setSaQuickConfig(SaQuickConfig saQuickConfig) {
SaQuickManager.setConfig(saQuickConfig);
}

}
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
package cn.dev33.satoken.quick;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.quick.config.SaQuickConfig;
import cn.dev33.satoken.quick.web.SaQuickController;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaTokenConsts;

/**
* 自动注入
* Quick-Bean 注册
*
* @author kong
*
*/
@Configuration
@Import({ SaQuickController.class })
public class SaQuickBean implements WebMvcConfigurer {
public class SaQuickRegister {

/**
* quick-login 配置
* 注册 Quick-Login 配置
*
* @return see note
*/
Expand All @@ -38,17 +33,7 @@ public SaQuickConfig getSaQuickConfig() {
}

/**
* 注入quick-login 配置
*
* @param saQuickConfig 配置对象
*/
@Autowired
public void setSaQuickConfig(SaQuickConfig saQuickConfig) {
SaQuickManager.setConfig(saQuickConfig);
}

/**
* 注册 [sa-token全局过滤器]
* 注册 [sa-token全局过滤器]
*
* @return see note
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.quick.SaQuickBean
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.quick.SaQuickInject

0 comments on commit 0c0b08c

Please sign in to comment.