mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebc381772f | ||
|
|
d08f93bdc0 | ||
|
|
c2fc4decef | ||
|
|
f7378f3898 | ||
|
|
7bde74bc51 | ||
|
|
5fc40a5af2 | ||
|
|
e13b263f27 | ||
|
|
bd22a94a10 | ||
|
|
be5ee2fc2b | ||
|
|
f4e7dac95f | ||
|
|
e97cddb5e2 | ||
|
|
e80369eb4b | ||
|
|
0cd3d66712 | ||
|
|
923b76a8db | ||
|
|
a6b38430cd | ||
|
|
e2c08f7dd2 | ||
|
|
986111b10c | ||
|
|
2cf18309b2 | ||
|
|
d22ac1b7cf | ||
|
|
fece7081a9 | ||
|
|
dc874c2275 |
@@ -1,7 +1,7 @@
|
||||
<p align="center">
|
||||
<img alt="logo" src="https://sa-token.cc/logo.png" width="150" height="150">
|
||||
</p>
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Sa-Token v1.43.0</h1>
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Sa-Token v1.44.0</h1>
|
||||
<h4 align="center">开源、免费、轻量级 Java 权限认证框架,让鉴权变得简单、优雅!</h4>
|
||||
<p align="center">
|
||||
<a href="https://gitee.com/dromara/sa-token/stargazers"><img src="https://gitee.com/dromara/sa-token/badge/star.svg?theme=gvp"></a>
|
||||
@@ -32,7 +32,7 @@ Sa-Token 是一个轻量级 Java 权限认证框架,目前拥有五大核心
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<version>1.43.0</version>
|
||||
<version>1.44.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -37,7 +37,7 @@
|
||||
|
||||
<!-- 一些属性 -->
|
||||
<properties>
|
||||
<revision>1.43.0</revision>
|
||||
<revision>1.44.0</revision>
|
||||
<jdk.version>1.8</jdk.version>
|
||||
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>utf-8</project.reporting.outputEncoding>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<url>https://github.com/dromara/sa-token</url>
|
||||
|
||||
<properties>
|
||||
<revision>1.43.0</revision>
|
||||
<revision>1.44.0</revision>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SaTokenConsts {
|
||||
/**
|
||||
* Sa-Token 当前版本号
|
||||
*/
|
||||
public static final String VERSION_NO = "v1.43.0";
|
||||
public static final String VERSION_NO = "v1.44.0";
|
||||
|
||||
/**
|
||||
* Sa-Token 开源地址 Gitee
|
||||
|
||||
@@ -57,8 +57,9 @@
|
||||
<module>sa-token-demo-webflux-springboot3</module>
|
||||
<module>sa-token-demo-websocket</module>
|
||||
<module>sa-token-demo-websocket-spring</module>
|
||||
<module>sa-token-demo-loveqq-boot</module>
|
||||
|
||||
</modules>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<java.run.main.class>com.pj.SaTokenAsyncApplication</java.run.main.class>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -73,7 +73,7 @@
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-bom</artifactId>
|
||||
<version>1.43.0</version>
|
||||
<version>1.44.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<java.run.main.class>com.pj.SaTokenDeviceLockApplication</java.run.main.class>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<dubbo.version>2.7.21</dubbo.version>
|
||||
<nacos.version>1.4.2</nacos.version>
|
||||
</properties>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<dubbo.version>2.7.21</dubbo.version>
|
||||
<nacos.version>1.4.2</nacos.version>
|
||||
</properties>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<dubbo.version>3.2.2</dubbo.version>
|
||||
<nacos.version>2.2.2</nacos.version>
|
||||
</properties>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<dubbo.version>3.2.2</dubbo.version>
|
||||
<nacos.version>2.2.2</nacos.version>
|
||||
</properties>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<lombok.version>1.18.10</lombok.version>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
74
sa-token-demo/sa-token-demo-loveqq-boot/pom.xml
Normal file
74
sa-token-demo/sa-token-demo-loveqq-boot/pom.xml
Normal file
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-framework</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<artifactId>sa-token-demo-loveqq-boot</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<jdk.version>17</jdk.version>
|
||||
<java.version>17</java.version>
|
||||
<maven.source.version>17</maven.source.version>
|
||||
<maven.compile.version>17</maven.compile.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 引导启动模块 -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-boot</artifactId>
|
||||
<version>${loveqq.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- reactor-netty 服务器,同时支持命令式/响应式编程范式 -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-boot-starter-netty</artifactId>
|
||||
<version>${loveqq.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- sa-token 集成 -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-loveqq-boot-starter</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- logback 启动器 -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-boot-starter-logback</artifactId>
|
||||
<version>${loveqq.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- yaml 支持,默认使用 properties 文件,如果使用 yaml 需自行引入依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.pj;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import com.kfyty.loveqq.framework.boot.K;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.BootApplication;
|
||||
import com.kfyty.loveqq.framework.web.core.autoconfig.annotation.EnableWebMvc;
|
||||
|
||||
/**
|
||||
* Sa-Token 整合 loveqq-framework 示例
|
||||
*
|
||||
* @author kfyty725
|
||||
*/
|
||||
@EnableWebMvc
|
||||
@BootApplication
|
||||
public class SaTokenLoveqqApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
K.run(SaTokenLoveqqApplication.class, args);
|
||||
System.out.println("\n启动成功:Sa-Token配置如下:" + SaManager.getConfig());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.pj.satoken;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaTokenContextModelBox;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenContextUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.web.core.filter.Filter;
|
||||
import com.kfyty.loveqq.framework.web.core.filter.FilterChain;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
|
||||
/**
|
||||
* 自定义过滤器
|
||||
*/
|
||||
@Component
|
||||
public class MyFilter implements Filter {
|
||||
/**
|
||||
* 实现该方法,可以实现 servlet/reactor 的统一
|
||||
* 但是该方法内部是同步方法,若需要异步,可以实现仅 reactor 支持的 {@link Filter#doFilter(ServerRequest, ServerResponse, FilterChain)} 方法
|
||||
*
|
||||
* @param request 请求
|
||||
* @param response 响应
|
||||
*/
|
||||
@Override
|
||||
public Continue doFilter(ServerRequest request, ServerResponse response) {
|
||||
System.out.println("进入自定义过滤器");
|
||||
|
||||
// 先 set 上下文,再调用 Sa-Token 同步 API,并在 finally 里清除上下文
|
||||
SaTokenContextModelBox prev = SaTokenContextUtil.setContext(request, response);
|
||||
try {
|
||||
System.out.println(StpUtil.isLogin());
|
||||
} finally {
|
||||
SaTokenContextUtil.clearContext(prev);
|
||||
}
|
||||
|
||||
return Continue.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.pj.satoken;
|
||||
|
||||
import cn.dev33.satoken.loveqq.boot.filter.SaRequestFilter;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Bean;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* [Sa-Token 权限认证] 配置类
|
||||
* @author click33
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
public class SaTokenConfigure {
|
||||
|
||||
/**
|
||||
* 注册 [sa-token全局过滤器]
|
||||
*/
|
||||
@Bean
|
||||
public SaRequestFilter getSaReactorFilter() {
|
||||
return new SaRequestFilter()
|
||||
// 指定 [拦截路由]
|
||||
.addInclude("/**")
|
||||
// 指定 [放行路由]
|
||||
.addExclude("/favicon.ico")
|
||||
// 指定[认证函数]: 每次请求执行
|
||||
.setAuth(r -> {
|
||||
System.out.println("---------- sa全局认证");
|
||||
// SaRouter.match("/test/test", () -> StpUtil.checkLogin());
|
||||
})
|
||||
// 指定[异常处理函数]:每次[认证函数]发生异常时执行此函数
|
||||
.setError(e -> {
|
||||
System.out.println("---------- sa全局异常 ");
|
||||
e.printStackTrace();
|
||||
return SaResult.error(e.getMessage());
|
||||
})
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.pj.satoken;
|
||||
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 自定义权限验证接口扩展
|
||||
*/
|
||||
@Component // 打开此注解,保证此类被springboot扫描,即可完成sa-token的自定义权限验证扩展
|
||||
public class StpInterfaceImpl implements StpInterface {
|
||||
|
||||
/**
|
||||
* 返回一个账号所拥有的权限码集合
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPermissionList(Object loginId, String loginType) {
|
||||
// 本list仅做模拟,实际项目中要根据具体业务逻辑来查询权限
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("101");
|
||||
list.add("user-add");
|
||||
list.add("user-delete");
|
||||
list.add("user-update");
|
||||
list.add("user-get");
|
||||
list.add("article-get");
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个账号所拥有的角色标识集合
|
||||
*/
|
||||
@Override
|
||||
public List<String> getRoleList(Object loginId, String loginType) {
|
||||
// 本list仅做模拟,实际项目中要根据具体业务逻辑来查询角色
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("admin");
|
||||
list.add("super-admin");
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.pj.test;
|
||||
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.kfyty.loveqq.framework.web.core.annotation.ExceptionHandler;
|
||||
import com.kfyty.loveqq.framework.web.core.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class GlobalException {
|
||||
|
||||
@ExceptionHandler
|
||||
public SaResult handlerException(Exception e) {
|
||||
e.printStackTrace();
|
||||
return SaResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.pj.test;
|
||||
|
||||
import cn.dev33.satoken.loveqq.boot.context.SaReactorHolder;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenContextUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Autowired;
|
||||
import com.kfyty.loveqq.framework.web.core.annotation.GetMapping;
|
||||
import com.kfyty.loveqq.framework.web.core.annotation.RequestMapping;
|
||||
import com.kfyty.loveqq.framework.web.core.annotation.RestController;
|
||||
import com.kfyty.loveqq.framework.web.core.annotation.bind.CookieValue;
|
||||
import com.kfyty.loveqq.framework.web.core.annotation.bind.RequestParam;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* 测试专用 Controller
|
||||
* 本示例是基于 reactor 编写,如果是 servlet,去除 SaReactorHolder/SaTokenContextUtil 包装,直接调用 sa-token api 即可
|
||||
*
|
||||
* @author click33
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test/")
|
||||
public class TestController {
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
// 登录测试:Controller 里调用 Sa-Token API --- http://localhost:8081/test/login
|
||||
@GetMapping("login")
|
||||
public Mono<SaResult> login(@RequestParam(defaultValue = "10001") String id) {
|
||||
return SaReactorHolder.sync(() -> {
|
||||
StpUtil.login(id);
|
||||
return SaResult.ok("登录成功");
|
||||
});
|
||||
}
|
||||
|
||||
// API测试:手动设置上下文、try-finally 形式 --- http://localhost:8081/test/isLogin
|
||||
@GetMapping("isLogin")
|
||||
public SaResult isLogin(ServerRequest request, ServerResponse response) {
|
||||
try {
|
||||
SaTokenContextUtil.setContext(request, response);
|
||||
System.out.println("是否登录:" + StpUtil.isLogin());
|
||||
return SaResult.data(StpUtil.getTokenInfo());
|
||||
} finally {
|
||||
SaTokenContextUtil.clearContext(null);
|
||||
}
|
||||
}
|
||||
|
||||
// API测试:手动设置上下文、lambda 表达式形式 --- http://localhost:8081/test/isLogin2
|
||||
@GetMapping("isLogin2")
|
||||
public SaResult isLogin2(ServerRequest request, ServerResponse response) {
|
||||
SaResult res = SaTokenContextUtil.setContext(request, response, () -> {
|
||||
System.out.println("是否登录:" + StpUtil.isLogin());
|
||||
return SaResult.data(StpUtil.getTokenInfo());
|
||||
});
|
||||
return SaResult.data(res);
|
||||
}
|
||||
|
||||
// API测试:自动设置上下文、lambda 表达式形式 --- http://localhost:8081/test/isLogin3
|
||||
@GetMapping("isLogin3")
|
||||
public Mono<SaResult> isLogin3() {
|
||||
return SaReactorHolder.sync(() -> {
|
||||
System.out.println("是否登录:" + StpUtil.isLogin());
|
||||
userService.isLogin();
|
||||
return SaResult.data(StpUtil.getTokenInfo());
|
||||
});
|
||||
}
|
||||
|
||||
// API测试:自动设置上下文、调用 userService Mono 方法 --- http://localhost:8081/test/isLogin4
|
||||
@GetMapping("isLogin4")
|
||||
public Mono<SaResult> isLogin4() {
|
||||
return userService.findUserIdByNamePwd("ZhangSan", "123456")
|
||||
.flatMap(userId -> SaReactorHolder.sync(() -> {
|
||||
StpUtil.login(userId);
|
||||
return SaResult.data(StpUtil.getTokenInfo());
|
||||
}));
|
||||
}
|
||||
|
||||
// API测试:切换线程、复杂嵌套调用 --- http://localhost:8081/test/isLogin5
|
||||
@GetMapping("isLogin5")
|
||||
public Mono<SaResult> isLogin5() {
|
||||
System.out.println("线程id-----" + Thread.currentThread().getId());
|
||||
// 要点:在流里调用 Sa-Token API 之前,必须用 SaReactorHolder.sync( () -> {} ) 进行包裹
|
||||
return Mono.delay(Duration.ofSeconds(1))
|
||||
.doOnNext(r -> System.out.println("线程id-----" + Thread.currentThread().getId()))
|
||||
.map(r -> SaReactorHolder.sync(() -> userService.isLogin()))
|
||||
.map(r -> userService.findUserIdByNamePwd("ZhangSan", "123456"))
|
||||
.map(r -> SaReactorHolder.sync(() -> userService.isLogin()))
|
||||
.flatMap(isLogin -> {
|
||||
System.out.println("是否登录 " + isLogin);
|
||||
return SaReactorHolder.sync(() -> {
|
||||
System.out.println("是否登录 " + StpUtil.isLogin());
|
||||
return SaResult.data(StpUtil.getTokenInfo());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// API测试:使用上下文无关的API --- http://localhost:8081/test/isLogin6
|
||||
@GetMapping("isLogin6")
|
||||
public SaResult isLogin6(@CookieValue("satoken") String satoken) {
|
||||
System.out.println("token 为:" + satoken);
|
||||
System.out.println("登录人:" + StpUtil.getLoginIdByToken(satoken));
|
||||
return SaResult.ok("登录人:" + StpUtil.getLoginIdByToken(satoken));
|
||||
}
|
||||
|
||||
// 测试 浏览器访问: http://localhost:8081/test/test
|
||||
@GetMapping("test")
|
||||
public SaResult test() {
|
||||
System.out.println("线程id------- " + Thread.currentThread().getId());
|
||||
return SaResult.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.pj.test;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 模拟 Service 方法
|
||||
* @author click33
|
||||
* @since 2025/4/6
|
||||
*/
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
public boolean isLogin() {
|
||||
System.out.println("UserService 里调用 API 测试,是否登录:" + StpUtil.isLogin());
|
||||
return StpUtil.isLogin();
|
||||
}
|
||||
|
||||
public Mono<Long> findUserIdByNamePwd(String name, String pwd) {
|
||||
// ...
|
||||
return Mono.just(10001L);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# 端口
|
||||
k:
|
||||
server:
|
||||
port: 8081
|
||||
@@ -17,7 +17,7 @@
|
||||
<java.version>1.8</java.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<java.version>1.8</java.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.traget>17</maven.compiler.traget>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<java.run.main.class>com.pj.SaTokenApplication</java.run.main.class>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<java.run.main.class>com.pj.SaTokenSseApplication</java.run.main.class>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<!--<spring.version>4.2.5.RELEASE</spring.version>-->
|
||||
<spring.version>5.3.7</spring.version>
|
||||
<jackson.version>2.16.1</jackson.version>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -34,7 +34,7 @@ public class H5Controller {
|
||||
return SaResult.data(redirect);
|
||||
} else {
|
||||
// 模式二或模式三
|
||||
String redirectUrl = SaSsoServerUtil.buildRedirectUrl(client, redirect, StpUtil.getLoginId(), StpUtil.getLoginDeviceId());
|
||||
String redirectUrl = SaSsoServerUtil.buildRedirectUrl(client, redirect, StpUtil.getLoginId(), StpUtil.getTokenValue());
|
||||
return SaResult.data(redirectUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<java.run.main.class>com.pj.SaTokenApplication</java.run.main.class>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.43.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<description>Sa-Token Dependencies</description>
|
||||
|
||||
<properties>
|
||||
<revision>1.43.0</revision>
|
||||
<revision>1.44.0</revision>
|
||||
|
||||
<!-- 统一定义依赖版本号 -->
|
||||
<springboot.version>2.7.18</springboot.version>
|
||||
@@ -30,6 +30,7 @@
|
||||
<noear-snack3.version>3.2.133</noear-snack3.version>
|
||||
<jfinal.version>4.9.17</jfinal.version>
|
||||
<jboot.version>3.14.4</jboot.version>
|
||||
<loveqq.version>1.1.2-java8</loveqq.version>
|
||||
<commons-pool2.version>2.5.0</commons-pool2.version>
|
||||
<dubbo.version>2.7.21</dubbo.version>
|
||||
<grpc-spring-boot-starter.version>2.10.1.RELEASE</grpc-spring-boot-starter.version>
|
||||
@@ -124,6 +125,27 @@
|
||||
<artifactId>jfinal</artifactId>
|
||||
<version>${jfinal.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- loveqq-core -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-core</artifactId>
|
||||
<version>${loveqq.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- loveqq-mvc-core -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-mvc-core</artifactId>
|
||||
<version>${loveqq.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- loveqq redisson starter -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-boot-starter-redisson</artifactId>
|
||||
<version>${loveqq.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test -->
|
||||
<!-- <dependency>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<p align="center">
|
||||
<img alt="logo" src="https://sa-token.cc/logo.png" width="150" height="150">
|
||||
</p>
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Sa-Token v1.43.0</h1>
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Sa-Token v1.44.0</h1>
|
||||
<h5 align="center">开源、免费、轻量级 Java 权限认证框架,让鉴权变得简单、优雅!</h5>
|
||||
<p align="center" class="badge-box">
|
||||
<a href="https://gitee.com/dromara/sa-token/stargazers"><img src="https://gitee.com/dromara/sa-token/badge/star.svg?theme=gvp"></a>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<div class="logo-box">
|
||||
<img src="logo.png" title="logo" />
|
||||
<h1 class="logo-text">Sa-Token</h1>
|
||||
<sub>v1.43.0</sub>
|
||||
<sub>v1.44.0</sub>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
@@ -28,6 +28,7 @@
|
||||
</div>
|
||||
<select class="select-version p-none" onchange="location.href=this.value">
|
||||
<option value="doc.html">最新版</option>
|
||||
<option value="v/v1.43.0/doc.html">v1.43.0</option>
|
||||
<option value="v/v1.42.0/doc.html">v1.42.0</option>
|
||||
<option value="v/v1.41.0/doc.html">v1.41.0</option>
|
||||
<option value="v/v1.40.0/doc.html">v1.40.0</option>
|
||||
@@ -215,7 +216,7 @@
|
||||
<!-- ew-wa -->
|
||||
<div class="ew-wa">
|
||||
<p>
|
||||
<a href="https://pan.quark.cn/s/d9dd62340d62" target="_blank">离线版文档</a>
|
||||
<a href="https://pan.quark.cn/s/d5abda720e88" target="_blank">离线版文档</a>
|
||||
<a href="https://pan.quark.cn/s/fea7e5ec72ee" target="_blank">历史所有版本文档</a>
|
||||
</p>
|
||||
</div>
|
||||
@@ -262,7 +263,7 @@
|
||||
<script src="./static/is-star-plugin.js?v=7"></script>
|
||||
<script src="./static/is-fill-in-wj-plugin.js?v=7"></script>
|
||||
<script>
|
||||
var saTokenTopVersion = '1.43.0'; // Sa-Token最新版本
|
||||
var saTokenTopVersion = '1.44.0'; // Sa-Token最新版本
|
||||
var name = '<img style="width: 60px; height: 60px; vertical-align: middle;" src="logo.png" alt="logo" /> ';
|
||||
name += '<b style="font-size: 28px; vertical-align: middle;">Sa-Token</b> <sub>v' + saTokenTopVersion + '</sub>';
|
||||
window.$docsify = {
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
<div class="main-box">
|
||||
<div class="content-box">
|
||||
<!-- <div class="fenge"></div> -->
|
||||
<h1>Sa-Token<small>v1.43.0</small></h1>
|
||||
<h1>Sa-Token<small>v1.44.0</small></h1>
|
||||
<div class="sub-title">
|
||||
<span class="sub-title-nr">开源、免费、轻量级 java 权限认证框架,让鉴权变得简单、优雅!</span>
|
||||
<div class="gb-cursor"> </div>
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
# 更新日志
|
||||
|
||||
### v1.44.0 @2025-6-7
|
||||
|
||||
- 修复:修复 sso-server 前后端分离示例无法正常登录的问题。
|
||||
- 修复:修复 SSO 模式三全端注销失效的问题。
|
||||
- 修复:修复 SSO `SaSsoClientModel` 部分场景下无法序列化的问题。
|
||||
- 新增:OAuth2 模块新增支持从 `SaOAuth2DataLoader` 接口获取高级权限与低级权限的方法。
|
||||
- 修复:修复 `sa-token-dubbo` 与 `sa-token-dubbo3` 每次调用都强制需要上下文的问题。
|
||||
- 文档:新增 `sa-token-dubbo3` 的说明。
|
||||
- 文档:更新赞助者名单。
|
||||
- 文档:新增 `loveqq-framework` 框架集成包。 **[重要]**
|
||||
|
||||
|
||||
|
||||
### v1.43.0 @2025-5-17
|
||||
- core:
|
||||
@@ -68,6 +80,7 @@
|
||||
|
||||
|
||||
### v1.42.0 @2025-4-11
|
||||
更新导读:[视频](https://www.bilibili.com/video/BV1h85izzEe8/)、[文字版](https://juejin.cn/post/7491971657201451062)
|
||||
|
||||
- core:
|
||||
- 新增: 新增 `API Key` 模块。 **[重要]**
|
||||
|
||||
@@ -42,6 +42,7 @@ implementation 'cn.dev33:sa-token-dubbo:${sa.top.version}'
|
||||
```
|
||||
<!---------------------------- tabs:end ---------------------------->
|
||||
|
||||
注:如果使用的是 dubbo3,只需要将 `sa-token-dubbo` 修改为 `sa-token-dubbo3` 即可。
|
||||
|
||||
|
||||
然后我们就可以愉快的做到以下事情:
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
---
|
||||
|
||||
### 正式版本
|
||||
v1.43.0 正式版,可上生产:
|
||||
v1.44.0 正式版,可上生产:
|
||||
|
||||
``` xml
|
||||
<!-- Sa-Token 权限认证 -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<version>1.43.0</version>
|
||||
<version>1.44.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@@ -1391,4 +1391,11 @@ var donateList = [
|
||||
"msg": '请你喝杯奶茶',
|
||||
"date": "2025-04-07"
|
||||
},
|
||||
{
|
||||
"name": "16群群友 错别字先生(微信打赏)",
|
||||
"link": "",
|
||||
"money": 50,
|
||||
"msg": '感谢您的开源项目!',
|
||||
"date": "2025-05-27"
|
||||
},
|
||||
]
|
||||
@@ -16,6 +16,7 @@
|
||||
package cn.dev33.satoken.context.dubbo.filter;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.context.SaTokenContextDefaultImpl;
|
||||
import cn.dev33.satoken.same.SaSameUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
@@ -36,23 +37,28 @@ public class SaTokenDubboConsumerFilter implements Filter {
|
||||
@Override
|
||||
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
||||
|
||||
// 1、追加 Same-Token 参数
|
||||
// 追加 Same-Token 参数
|
||||
if(SaManager.getConfig().getCheckSameToken()) {
|
||||
RpcContext.getContext().setAttachment(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken());
|
||||
}
|
||||
|
||||
// 2、调用前,向下传递会话Token
|
||||
|
||||
// 无上下文时只做简单调用,不传递会话 token
|
||||
if( ! SaHolder.getContext().isValid()) {
|
||||
return invoker.invoke(invocation);
|
||||
}
|
||||
|
||||
// 1、调用前,向下传递会话Token
|
||||
if(SaManager.getSaTokenContext() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
RpcContext.getContext().setAttachment(SaTokenConsts.JUST_CREATED, StpUtil.getTokenValueNotCut());
|
||||
}
|
||||
|
||||
// 3、开始调用
|
||||
// 2、开始调用
|
||||
Result invoke = invoker.invoke(invocation);
|
||||
|
||||
// 4、调用后,解析回传的Token值
|
||||
// 3、调用后,解析回传的Token值
|
||||
StpUtil.setTokenValue(invoke.getAttachment(SaTokenConsts.JUST_CREATED_NOT_PREFIX));
|
||||
|
||||
// 5、返回结果
|
||||
// note
|
||||
return invoke;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,13 +36,12 @@ public class SaTokenDubboContextFilter implements Filter {
|
||||
public Result invoke(Invoker<?> invoker, Invocation invocation) {
|
||||
if(SaHolder.getContext().isValid()) {
|
||||
return invoker.invoke(invocation);
|
||||
} else {
|
||||
try {
|
||||
SaTokenContextDubboUtil.setContext(RpcContext.getContext());
|
||||
return invoker.invoke(invocation);
|
||||
} finally {
|
||||
SaManager.getSaTokenContext().clearContext();
|
||||
}
|
||||
}
|
||||
try {
|
||||
SaTokenContextDubboUtil.setContext(RpcContext.getContext());
|
||||
return invoker.invoke(invocation);
|
||||
} finally {
|
||||
SaManager.getSaTokenContext().clearContext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package cn.dev33.satoken.context.dubbo3.filter;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.context.SaTokenContextDefaultImpl;
|
||||
import cn.dev33.satoken.same.SaSameUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
@@ -40,6 +41,11 @@ public class SaTokenDubbo3ConsumerFilter implements Filter {
|
||||
if(SaManager.getConfig().getCheckSameToken()) {
|
||||
RpcContext.getServiceContext().setAttachment(SaSameUtil.SAME_TOKEN,SaSameUtil.getToken());
|
||||
}
|
||||
|
||||
// 无上下文时只做简单调用,不传递会话 token
|
||||
if( ! SaHolder.getContext().isValid()) {
|
||||
return invoker.invoke(invocation);
|
||||
}
|
||||
|
||||
// 1. 调用前,向下传递会话Token
|
||||
if(SaManager.getSaTokenContext() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
|
||||
@@ -36,14 +36,14 @@ public class SaTokenDubbo3ContextFilter implements Filter {
|
||||
public Result invoke(Invoker<?> invoker, Invocation invocation) {
|
||||
if(SaHolder.getContext().isValid()) {
|
||||
return invoker.invoke(invocation);
|
||||
} else {
|
||||
try {
|
||||
SaTokenContextDubbo3Util.setContext(RpcContext.getServiceContext());
|
||||
return invoker.invoke(invocation);
|
||||
} finally {
|
||||
SaManager.getSaTokenContext().clearContext();
|
||||
}
|
||||
}
|
||||
try {
|
||||
SaTokenContextDubbo3Util.setContext(RpcContext.getServiceContext());
|
||||
return invoker.invoke(invocation);
|
||||
} finally {
|
||||
SaManager.getSaTokenContext().clearContext();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import cn.dev33.satoken.oauth2.error.SaOAuth2ErrorCode;
|
||||
import cn.dev33.satoken.oauth2.exception.SaOAuth2ClientModelException;
|
||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Sa-Token OAuth2 数据加载器
|
||||
*
|
||||
@@ -78,4 +80,21 @@ public interface SaOAuth2DataLoader {
|
||||
return SaSecureUtil.md5(SaOAuth2Manager.getServerConfig().getUnionidDigestPrefix() + "_" + subjectId + "_" + loginId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取高级权限列表
|
||||
* @return /
|
||||
*/
|
||||
default List<String> getHigherScopeList() {
|
||||
String higherScope = SaOAuth2Manager.getServerConfig().getHigherScope();
|
||||
return SaOAuth2Manager.getDataConverter().convertScopeStringToList(higherScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取低级权限列表
|
||||
* @return /
|
||||
*/
|
||||
default List<String> getLowerScopeList() {
|
||||
String lowerScope = SaOAuth2Manager.getServerConfig().getLowerScope();
|
||||
return SaOAuth2Manager.getDataConverter().convertScopeStringToList(lowerScope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -765,8 +765,7 @@ public class SaOAuth2Template {
|
||||
* @return /
|
||||
*/
|
||||
public List<String> getHigherScopeList() {
|
||||
String higherScope = SaOAuth2Manager.getServerConfig().getHigherScope();
|
||||
return SaOAuth2Manager.getDataConverter().convertScopeStringToList(higherScope);
|
||||
return SaOAuth2Manager.getDataLoader().getHigherScopeList();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -774,8 +773,7 @@ public class SaOAuth2Template {
|
||||
* @return /
|
||||
*/
|
||||
public List<String> getLowerScopeList() {
|
||||
String lowerScope = SaOAuth2Manager.getServerConfig().getLowerScope();
|
||||
return SaOAuth2Manager.getDataConverter().convertScopeStringToList(lowerScope);
|
||||
return SaOAuth2Manager.getDataLoader().getLowerScopeList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,15 +95,6 @@ public class SaSsoClientModel implements Serializable {
|
||||
return _pushUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否配置了有效地推送地址
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public boolean isValidPushUrl() {
|
||||
return SaFoxUtil.isUrl(splicingPushUrl());
|
||||
}
|
||||
|
||||
|
||||
// get set
|
||||
|
||||
|
||||
@@ -274,7 +274,8 @@ public class SaSsoClientProcessor {
|
||||
if(singleDeviceIdLogout) {
|
||||
logoutParameter.setDeviceId(stpLogic.getLoginDeviceId());
|
||||
}
|
||||
Object centerId = ssoClientTemplate.strategy.convertLoginIdToCenterId.run(stpLogic.getLoginId());
|
||||
Object loginId = stpLogic.getLoginId();
|
||||
Object centerId = ssoClientTemplate.strategy.convertLoginIdToCenterId.run(loginId);
|
||||
SaSsoMessage message = ssoClientTemplate.buildSignoutMessage(centerId, logoutParameter);
|
||||
SaResult result = ssoClientTemplate.pushMessageAsSaResult(message);
|
||||
|
||||
@@ -285,7 +286,7 @@ public class SaSsoClientProcessor {
|
||||
|
||||
// 极端场景下,sso-server 中心的单点注销可能并不会通知到当前 client 端,所以这里需要再补一刀
|
||||
if(stpLogic.isLogin()) {
|
||||
stpLogic.logout(logoutParameter);
|
||||
stpLogic.logout(loginId, logoutParameter);
|
||||
}
|
||||
return _ssoLogoutBack(req, res);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<module>sa-token-solon-plugin</module>
|
||||
<module>sa-token-jboot-plugin</module>
|
||||
<module>sa-token-jfinal-plugin</module>
|
||||
<module>sa-token-loveqq-boot-starter</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
84
sa-token-starter/sa-token-loveqq-boot-starter/pom.xml
Normal file
84
sa-token-starter/sa-token-loveqq-boot-starter/pom.xml
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-starter</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<name>sa-token-loveqq-boot-starter</name>
|
||||
<artifactId>sa-token-loveqq-boot-starter</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<description>loveqq-framework integrate sa-token</description>
|
||||
|
||||
<properties>
|
||||
<jdk.version>1.8</jdk.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- loveqq-core -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- loveqq-mvc-core -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-mvc-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- jackson 序列化、redis集成、SSO、OAuth2 等模块要用到,比较重要所以内置集成 -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- loveqq redisson starter -->
|
||||
<dependency>
|
||||
<groupId>com.kfyty</groupId>
|
||||
<artifactId>loveqq-boot-starter-redisson</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Servlet API -->
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- SSO (optional) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-sso</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- OAuth2.0 (optional) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-oauth2</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- API Key (optional) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-apikey</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- API Sign (optional) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-sign</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.annotation.handler.SaAnnotationHandlerInterface;
|
||||
import cn.dev33.satoken.config.SaTokenConfig;
|
||||
import cn.dev33.satoken.context.SaTokenContext;
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.fun.strategy.SaCorsHandleFunction;
|
||||
import cn.dev33.satoken.http.SaHttpTemplate;
|
||||
import cn.dev33.satoken.httpauth.basic.SaHttpBasicTemplate;
|
||||
import cn.dev33.satoken.httpauth.basic.SaHttpBasicUtil;
|
||||
import cn.dev33.satoken.httpauth.digest.SaHttpDigestTemplate;
|
||||
import cn.dev33.satoken.httpauth.digest.SaHttpDigestUtil;
|
||||
import cn.dev33.satoken.json.SaJsonTemplate;
|
||||
import cn.dev33.satoken.listener.SaTokenEventCenter;
|
||||
import cn.dev33.satoken.listener.SaTokenListener;
|
||||
import cn.dev33.satoken.log.SaLog;
|
||||
import cn.dev33.satoken.loveqq.boot.support.SaPathMatcherHolder;
|
||||
import cn.dev33.satoken.plugin.SaTokenPlugin;
|
||||
import cn.dev33.satoken.plugin.SaTokenPluginHolder;
|
||||
import cn.dev33.satoken.same.SaSameTemplate;
|
||||
import cn.dev33.satoken.secure.totp.SaTotpTemplate;
|
||||
import cn.dev33.satoken.serializer.SaSerializerTemplate;
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.strategy.SaAnnotationStrategy;
|
||||
import cn.dev33.satoken.strategy.SaFirewallStrategy;
|
||||
import cn.dev33.satoken.strategy.SaStrategy;
|
||||
import cn.dev33.satoken.strategy.hooks.SaFirewallCheckHook;
|
||||
import cn.dev33.satoken.temp.SaTempTemplate;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Autowired;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.support.PatternMatcher;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token 所需要的 Bean
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.34.0
|
||||
*/
|
||||
@Component
|
||||
public class SaBeanInject {
|
||||
|
||||
/**
|
||||
* 组件注入
|
||||
* <p> 为确保 Log 组件正常打印,必须将 SaLog 和 SaTokenConfig 率先初始化 </p>
|
||||
*
|
||||
* @param log log 对象
|
||||
* @param saTokenConfig 配置对象
|
||||
*/
|
||||
public SaBeanInject(@Autowired(required = false) SaLog log,
|
||||
@Autowired(required = false) SaTokenConfig saTokenConfig,
|
||||
@Autowired(required = false) SaTokenPluginHolder pluginHolder) {
|
||||
if (log != null) {
|
||||
SaManager.setLog(log);
|
||||
}
|
||||
|
||||
if (saTokenConfig != null) {
|
||||
SaManager.setConfig(saTokenConfig);
|
||||
}
|
||||
|
||||
// 初始化 Sa-Token SPI 插件
|
||||
if (pluginHolder == null) {
|
||||
pluginHolder = SaTokenPluginHolder.instance;
|
||||
}
|
||||
|
||||
pluginHolder.init();
|
||||
|
||||
SaTokenPluginHolder.instance = pluginHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入持久化Bean
|
||||
*
|
||||
* @param saTokenDao SaTokenDao对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaTokenDao(SaTokenDao saTokenDao) {
|
||||
SaManager.setSaTokenDao(saTokenDao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入权限认证Bean
|
||||
*
|
||||
* @param stpInterface StpInterface对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setStpInterface(StpInterface stpInterface) {
|
||||
SaManager.setStpInterface(stpInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入上下文Bean
|
||||
*
|
||||
* @param saTokenContext SaTokenContext对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaTokenContext(SaTokenContext saTokenContext) {
|
||||
SaManager.setSaTokenContext(saTokenContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入侦听器Bean
|
||||
*
|
||||
* @param listenerList 侦听器集合
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaTokenListener(List<SaTokenListener> listenerList) {
|
||||
SaTokenEventCenter.registerListenerList(listenerList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义注解处理器
|
||||
*
|
||||
* @param handlerList 自定义注解处理器集合
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaAnnotationHandler(List<SaAnnotationHandlerInterface<?>> handlerList) {
|
||||
for (SaAnnotationHandlerInterface<?> handler : handlerList) {
|
||||
SaAnnotationStrategy.instance.registerAnnotationHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入临时令牌验证模块 Bean
|
||||
*
|
||||
* @param saTempTemplate /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaTempTemplate(SaTempTemplate saTempTemplate) {
|
||||
SaManager.setSaTempTemplate(saTempTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 Same-Token 模块 Bean
|
||||
*
|
||||
* @param saSameTemplate saSameTemplate对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaIdTemplate(SaSameTemplate saSameTemplate) {
|
||||
SaManager.setSaSameTemplate(saSameTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token Http Basic 认证模块
|
||||
*
|
||||
* @param saBasicTemplate saBasicTemplate对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaHttpBasicTemplate(SaHttpBasicTemplate saBasicTemplate) {
|
||||
SaHttpBasicUtil.saHttpBasicTemplate = saBasicTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token Http Digest 认证模块
|
||||
*
|
||||
* @param saHttpDigestTemplate saHttpDigestTemplate 对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaHttpDigestTemplate(SaHttpDigestTemplate saHttpDigestTemplate) {
|
||||
SaHttpDigestUtil.saHttpDigestTemplate = saHttpDigestTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义的 JSON 转换器 Bean
|
||||
*
|
||||
* @param saJsonTemplate JSON 转换器
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaJsonTemplate(SaJsonTemplate saJsonTemplate) {
|
||||
SaManager.setSaJsonTemplate(saJsonTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义的 Http 转换器 Bean
|
||||
*
|
||||
* @param saHttpTemplate /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaHttpTemplate(SaHttpTemplate saHttpTemplate) {
|
||||
SaManager.setSaHttpTemplate(saHttpTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义的序列化器 Bean
|
||||
*
|
||||
* @param saSerializerTemplate 序列化器
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaSerializerTemplate(SaSerializerTemplate saSerializerTemplate) {
|
||||
SaManager.setSaSerializerTemplate(saSerializerTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义的 TOTP 算法 Bean
|
||||
*
|
||||
* @param totpTemplate TOTP 算法类
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaTotpTemplate(SaTotpTemplate totpTemplate) {
|
||||
SaManager.setSaTotpTemplate(totpTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义的 StpLogic
|
||||
*
|
||||
* @param stpLogic /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setStpLogic(StpLogic stpLogic) {
|
||||
StpUtil.setStpLogic(stpLogic);
|
||||
}
|
||||
|
||||
/**
|
||||
* 利用自动注入特性,获取Spring框架内部使用的路由匹配器
|
||||
*
|
||||
* @param pathMatcher 要设置的 pathMatcher
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setPathMatcher(PatternMatcher pathMatcher) {
|
||||
SaPathMatcherHolder.setPathMatcher(pathMatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义防火墙校验 hook 集合
|
||||
*
|
||||
* @param hooks /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaFirewallCheckHooks(List<SaFirewallCheckHook> hooks) {
|
||||
for (SaFirewallCheckHook hook : hooks) {
|
||||
SaFirewallStrategy.instance.registerHook(hook);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入CORS 策略处理函数
|
||||
*
|
||||
* @param corsHandle /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setCorsHandle(SaCorsHandleFunction corsHandle) {
|
||||
SaStrategy.instance.corsHandle = corsHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义插件集合
|
||||
*
|
||||
* @param plugins /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaTokenPluginList(List<SaTokenPlugin> plugins) {
|
||||
for (SaTokenPlugin plugin : plugins) {
|
||||
SaTokenPluginHolder.instance.installPlugin(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot;
|
||||
|
||||
import cn.dev33.satoken.config.SaTokenConfig;
|
||||
import cn.dev33.satoken.loveqq.boot.context.path.ApplicationContextPathLoading;
|
||||
import cn.dev33.satoken.loveqq.boot.filter.SaFirewallCheckFilter;
|
||||
import cn.dev33.satoken.loveqq.boot.filter.SaTokenContextFilter;
|
||||
import cn.dev33.satoken.loveqq.boot.filter.SaTokenCorsFilter;
|
||||
import cn.dev33.satoken.loveqq.boot.support.SaPathMatcherHolder;
|
||||
import cn.dev33.satoken.strategy.SaStrategy;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Bean;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.ConfigurationProperties;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Import;
|
||||
|
||||
/**
|
||||
* 注册Sa-Token所需要的Bean
|
||||
* <p> Bean 的注册与注入应该分开在两个文件中,否则在某些场景下会造成循环依赖
|
||||
*
|
||||
* @author click33
|
||||
*/
|
||||
@Component
|
||||
@Import(config = {
|
||||
SaFirewallCheckFilter.class,
|
||||
SaTokenContextFilter.class,
|
||||
SaTokenCorsFilter.class
|
||||
})
|
||||
public class SaBeanRegister {
|
||||
|
||||
public SaBeanRegister() {
|
||||
// 重写路由匹配算法
|
||||
SaStrategy.instance.routeMatcher = SaPathMatcherHolder::match;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置Bean
|
||||
*
|
||||
* @return 配置对象
|
||||
*/
|
||||
@Bean
|
||||
@ConfigurationProperties("sa-token")
|
||||
public SaTokenConfig getSaTokenConfig() {
|
||||
return new SaTokenConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用上下文路径加载器
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@Bean
|
||||
public ApplicationContextPathLoading getApplicationContextPathLoading() {
|
||||
return new ApplicationContextPathLoading();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.apiKey;
|
||||
|
||||
import cn.dev33.satoken.apikey.SaApiKeyManager;
|
||||
import cn.dev33.satoken.apikey.config.SaApiKeyConfig;
|
||||
import cn.dev33.satoken.apikey.loader.SaApiKeyDataLoader;
|
||||
import cn.dev33.satoken.apikey.template.SaApiKeyTemplate;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Autowired;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.condition.annotation.ConditionalOnClass;
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token API Key 所需要的 Bean
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.43.0
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnClass("cn.dev33.satoken.apikey.SaApiKeyManager")
|
||||
public class SaApiKeyBeanInject {
|
||||
/**
|
||||
* 注入 API Key 配置对象
|
||||
*
|
||||
* @param saApiKeyConfig 配置对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaApiKeyConfig(SaApiKeyConfig saApiKeyConfig) {
|
||||
SaApiKeyManager.setConfig(saApiKeyConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义的 API Key 模版方法 Bean
|
||||
*
|
||||
* @param apiKeyTemplate /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaApiKeyTemplate(SaApiKeyTemplate apiKeyTemplate) {
|
||||
SaApiKeyManager.setSaApiKeyTemplate(apiKeyTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义的 API Key 数据加载器 Bean
|
||||
*
|
||||
* @param apiKeyDataLoader /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaApiKeyDataLoader(SaApiKeyDataLoader apiKeyDataLoader) {
|
||||
SaApiKeyManager.setSaApiKeyDataLoader(apiKeyDataLoader);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.apiKey;
|
||||
|
||||
import cn.dev33.satoken.apikey.config.SaApiKeyConfig;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Bean;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.ConfigurationProperties;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.condition.annotation.ConditionalOnClass;
|
||||
|
||||
/**
|
||||
* 注册 Sa-Token API Key 所需要的 Bean
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.43.0
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnClass("cn.dev33.satoken.apikey.SaApiKeyManager")
|
||||
public class SaApiKeyBeanRegister {
|
||||
/**
|
||||
* 获取 API Key 配置对象
|
||||
*
|
||||
* @return 配置对象
|
||||
*/
|
||||
@Bean
|
||||
@ConfigurationProperties("sa-token.api-key")
|
||||
public SaApiKeyConfig getSaApiKeyConfig() {
|
||||
return new SaApiKeyConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.context;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaTokenContextModelBox;
|
||||
import cn.dev33.satoken.fun.SaRetGenericFunction;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenContextUtil;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Reactor 上下文操作(异步),持有当前请求的 ServerWebExchange 全局引用
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.19.0
|
||||
*/
|
||||
public class SaReactorHolder {
|
||||
public static final String REQUEST_CONTEXT_ATTRIBUTE = "com.kfyty.loveqq.framework.web.mvc.netty.request.support.RequestContextHolder.REQUEST_CONTEXT_ATTRIBUTE";
|
||||
public static final String RESPONSE_CONTEXT_ATTRIBUTE = "com.kfyty.loveqq.framework.web.mvc.netty.request.support.ResponseContextHolder.REQUEST_CONTEXT_ATTRIBUTE";
|
||||
|
||||
/**
|
||||
* 获取 Mono < ServerRequest >
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public static Mono<ServerRequest> getRequest() {
|
||||
return Mono.deferContextual(Mono::just).map(e -> e.get(REQUEST_CONTEXT_ATTRIBUTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Mono < ServerResponse >
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public static Mono<ServerResponse> getResponse() {
|
||||
return Mono.deferContextual(Mono::just).map(e -> e.get(RESPONSE_CONTEXT_ATTRIBUTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 ServerRequest/ServerResponse 写入到同步上下文中,并执行一段代码,执行完毕清除上下文
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public static <R> Mono<R> sync(SaRetGenericFunction<R> fun) {
|
||||
return Mono.deferContextual(ctx -> {
|
||||
SaTokenContextModelBox prev = SaTokenContextUtil.setContext(ctx.get(REQUEST_CONTEXT_ATTRIBUTE), ctx.get(RESPONSE_CONTEXT_ATTRIBUTE));
|
||||
try {
|
||||
return Mono.just(fun.run());
|
||||
} finally {
|
||||
SaTokenContextUtil.clearContext(prev);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.context.path;
|
||||
|
||||
import cn.dev33.satoken.application.ApplicationInfo;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.CommandLineRunner;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Value;
|
||||
|
||||
/**
|
||||
* 应用上下文路径加载器
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.37.0
|
||||
*/
|
||||
public class ApplicationContextPathLoading implements CommandLineRunner {
|
||||
@Value("${k.mvc.tomcat.contextPath:}")
|
||||
private String contextPath;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
|
||||
String routePrefix = "";
|
||||
|
||||
if (SaFoxUtil.isNotEmpty(contextPath)) {
|
||||
if (!contextPath.startsWith("/")) {
|
||||
contextPath = "/" + contextPath;
|
||||
}
|
||||
if (contextPath.endsWith("/")) {
|
||||
contextPath = contextPath.substring(0, contextPath.length() - 1);
|
||||
}
|
||||
routePrefix += contextPath;
|
||||
}
|
||||
|
||||
if (SaFoxUtil.isNotEmpty(routePrefix) && !routePrefix.equals("/")) {
|
||||
ApplicationInfo.routePrefix = routePrefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.filter;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaTokenContextModelBox;
|
||||
import cn.dev33.satoken.exception.BackResultException;
|
||||
import cn.dev33.satoken.exception.FirewallCheckException;
|
||||
import cn.dev33.satoken.exception.StopMatchException;
|
||||
import cn.dev33.satoken.loveqq.boot.model.LoveqqSaRequest;
|
||||
import cn.dev33.satoken.loveqq.boot.model.LoveqqSaResponse;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenContextUtil;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenOperateUtil;
|
||||
import cn.dev33.satoken.strategy.SaFirewallStrategy;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Order;
|
||||
import com.kfyty.loveqq.framework.web.core.filter.Filter;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
|
||||
/**
|
||||
* 防火墙校验过滤器 (基于 loveqq-framework 统一 Filter,可以统一 servlet 和 reactor 配置)
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.37.0
|
||||
*/
|
||||
@Component
|
||||
@Order(SaTokenConsts.FIREWALL_CHECK_FILTER_ORDER)
|
||||
public class SaFirewallCheckFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public Continue doFilter(ServerRequest request, ServerResponse response) {
|
||||
LoveqqSaRequest saRequest = new LoveqqSaRequest(request);
|
||||
LoveqqSaResponse saResponse = new LoveqqSaResponse(response);
|
||||
SaTokenContextModelBox prev = SaTokenContextUtil.setContext(request, response);
|
||||
try {
|
||||
SaFirewallStrategy.instance.check.execute(saRequest, saResponse, null);
|
||||
} catch (StopMatchException ignored) {
|
||||
// ignored
|
||||
} catch (BackResultException e) {
|
||||
SaTokenOperateUtil.writeResult(response, e.getMessage());
|
||||
return Continue.FALSE;
|
||||
} catch (FirewallCheckException e) {
|
||||
if (SaFirewallStrategy.instance.checkFailHandle == null) {
|
||||
SaTokenOperateUtil.writeResult(response, e.getMessage());
|
||||
} else {
|
||||
SaFirewallStrategy.instance.checkFailHandle.run(e, saRequest, saResponse, null);
|
||||
}
|
||||
return Continue.FALSE;
|
||||
} finally {
|
||||
SaTokenContextUtil.clearContext(prev);
|
||||
}
|
||||
|
||||
// 更多异常则不处理,交由 Web 框架处理
|
||||
|
||||
// 向内执行
|
||||
return Continue.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.filter;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaTokenContextModelBox;
|
||||
import cn.dev33.satoken.exception.BackResultException;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
import cn.dev33.satoken.exception.StopMatchException;
|
||||
import cn.dev33.satoken.filter.SaFilter;
|
||||
import cn.dev33.satoken.filter.SaFilterAuthStrategy;
|
||||
import cn.dev33.satoken.filter.SaFilterErrorStrategy;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenContextUtil;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenOperateUtil;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Order;
|
||||
import com.kfyty.loveqq.framework.web.core.filter.Filter;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 全局鉴权过滤器 (基于 loveqq-framework 统一 Filter,可以统一 servlet 和 reactor 配置)
|
||||
* <p>
|
||||
* 默认优先级为 -100,尽量保证在其它过滤器之前执行
|
||||
* </p>
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.19.0
|
||||
*/
|
||||
@Order(SaTokenConsts.ASSEMBLY_ORDER)
|
||||
public class SaRequestFilter implements SaFilter, Filter {
|
||||
|
||||
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
|
||||
|
||||
/**
|
||||
* 拦截路由
|
||||
*/
|
||||
public List<String> includeList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 放行路由
|
||||
*/
|
||||
public List<String> excludeList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public SaRequestFilter addInclude(String... paths) {
|
||||
includeList.addAll(Arrays.asList(paths));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaRequestFilter addExclude(String... paths) {
|
||||
excludeList.addAll(Arrays.asList(paths));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaRequestFilter setIncludeList(List<String> pathList) {
|
||||
includeList = pathList;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaRequestFilter setExcludeList(List<String> pathList) {
|
||||
excludeList = pathList;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------ 钩子函数
|
||||
|
||||
/**
|
||||
* 认证函数:每次请求执行
|
||||
*/
|
||||
public SaFilterAuthStrategy auth = r -> {
|
||||
};
|
||||
|
||||
/**
|
||||
* 异常处理函数:每次[认证函数]发生异常时执行此函数
|
||||
*/
|
||||
public SaFilterErrorStrategy error = e -> {
|
||||
throw new SaTokenException(e);
|
||||
};
|
||||
|
||||
/**
|
||||
* 前置函数:在每次[认证函数]之前执行
|
||||
* <b>注意点:前置认证函数将不受 includeList 与 excludeList 的限制,所有路由的请求都会进入 beforeAuth</b>
|
||||
*/
|
||||
public SaFilterAuthStrategy beforeAuth = r -> {
|
||||
};
|
||||
|
||||
@Override
|
||||
public SaRequestFilter setAuth(SaFilterAuthStrategy auth) {
|
||||
this.auth = auth;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaRequestFilter setError(SaFilterErrorStrategy error) {
|
||||
this.error = error;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaRequestFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
|
||||
this.beforeAuth = beforeAuth;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------ doFilter
|
||||
|
||||
@Override
|
||||
public Continue doFilter(ServerRequest request, ServerResponse response) {
|
||||
SaTokenContextModelBox prev = SaTokenContextUtil.setContext(request, response);
|
||||
try {
|
||||
beforeAuth.run(null);
|
||||
SaRouter.match(includeList).notMatch(excludeList).check(r -> auth.run(null));
|
||||
} catch (StopMatchException ignored) {
|
||||
// ignored
|
||||
} catch (BackResultException e) {
|
||||
SaTokenOperateUtil.writeResult(response, e.getMessage());
|
||||
return Continue.FALSE;
|
||||
} catch (Throwable e) {
|
||||
SaTokenOperateUtil.writeResult(response, String.valueOf(error.run(e)));
|
||||
return Continue.FALSE;
|
||||
} finally {
|
||||
SaTokenContextUtil.clearContext(prev);
|
||||
}
|
||||
|
||||
// 执行
|
||||
return Continue.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.filter;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaTokenContextModelBox;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenContextUtil;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Order;
|
||||
import com.kfyty.loveqq.framework.web.core.filter.Filter;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
|
||||
/**
|
||||
* SaTokenContext 上下文初始化过滤器 (基于 loveqq-framework 统一 Filter,可以统一 servlet 和 reactor 配置)
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.42.0
|
||||
*/
|
||||
@Component
|
||||
@Order(SaTokenConsts.SA_TOKEN_CONTEXT_FILTER_ORDER)
|
||||
public class SaTokenContextFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public Continue doFilter(ServerRequest request, ServerResponse response) {
|
||||
SaTokenContextModelBox prev = SaTokenContextUtil.setContext(request, response);
|
||||
return Continue.ofTrue(() -> SaTokenContextUtil.clearContext(prev));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.filter;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.context.model.SaTokenContextModelBox;
|
||||
import cn.dev33.satoken.exception.BackResultException;
|
||||
import cn.dev33.satoken.exception.StopMatchException;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenContextUtil;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenOperateUtil;
|
||||
import cn.dev33.satoken.strategy.SaStrategy;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Order;
|
||||
import com.kfyty.loveqq.framework.web.core.filter.Filter;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
|
||||
/**
|
||||
* CORS 跨域策略过滤器 (基于 loveqq-framework 统一 Filter,可以统一 servlet 和 reactor 配置)
|
||||
* loveqq-framework 也有跨域过滤器,切勿同时配置
|
||||
*
|
||||
* @author click33
|
||||
* @see com.kfyty.loveqq.framework.web.core.cors.CorsFilter
|
||||
* @since 1.42.0
|
||||
*/
|
||||
@Component
|
||||
@Order(SaTokenConsts.CORS_FILTER_ORDER)
|
||||
public class SaTokenCorsFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public Continue doFilter(ServerRequest request, ServerResponse response) {
|
||||
SaTokenContextModelBox prev = SaTokenContextUtil.setContext(request, response);
|
||||
try {
|
||||
SaTokenContextModelBox box = SaHolder.getContext().getModelBox();
|
||||
SaStrategy.instance.corsHandle.execute(box.getRequest(), box.getResponse(), box.getStorage());
|
||||
} catch (StopMatchException ignored) {
|
||||
// ignored
|
||||
} catch (BackResultException e) {
|
||||
SaTokenOperateUtil.writeResult(response, e.getMessage());
|
||||
return Continue.FALSE;
|
||||
} finally {
|
||||
SaTokenContextUtil.clearContext(prev);
|
||||
}
|
||||
return Continue.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.interceptor;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaTokenContextModelBox;
|
||||
import cn.dev33.satoken.exception.BackResultException;
|
||||
import cn.dev33.satoken.exception.StopMatchException;
|
||||
import cn.dev33.satoken.fun.SaParamFunction;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenContextUtil;
|
||||
import cn.dev33.satoken.loveqq.boot.utils.SaTokenOperateUtil;
|
||||
import cn.dev33.satoken.strategy.SaAnnotationStrategy;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
import com.kfyty.loveqq.framework.web.core.interceptor.HandlerInterceptor;
|
||||
import com.kfyty.loveqq.framework.web.core.mapping.MethodMapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Sa-Token 综合拦截器,提供注解鉴权和路由拦截鉴权能力
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.31.0
|
||||
*/
|
||||
public class SaInterceptor implements HandlerInterceptor {
|
||||
/**
|
||||
* 是否打开注解鉴权,配置为 true 时注解鉴权才会生效,配置为 false 时,即使写了注解也不会进行鉴权
|
||||
*/
|
||||
public boolean isAnnotation = true;
|
||||
|
||||
/**
|
||||
* 认证前置函数:在注解鉴权之前执行
|
||||
* <p> 参数:路由处理函数指针
|
||||
*/
|
||||
public SaParamFunction<Object> beforeAuth = handler -> {
|
||||
};
|
||||
|
||||
/**
|
||||
* 认证函数:每次请求执行
|
||||
* <p> 参数:路由处理函数指针
|
||||
*/
|
||||
public SaParamFunction<Object> auth = handler -> {
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建一个 Sa-Token 综合拦截器,默认带有注解鉴权能力
|
||||
*/
|
||||
public SaInterceptor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个 Sa-Token 综合拦截器,默认带有注解鉴权能力
|
||||
*
|
||||
* @param auth 认证函数,每次请求执行
|
||||
*/
|
||||
public SaInterceptor(SaParamFunction<Object> auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否打开注解鉴权:配置为 true 时注解鉴权才会生效,配置为 false 时,即使写了注解也不会进行鉴权
|
||||
*
|
||||
* @param isAnnotation /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaInterceptor isAnnotation(boolean isAnnotation) {
|
||||
this.isAnnotation = isAnnotation;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入 [ 认证前置函数 ]: 在注解鉴权之前执行
|
||||
*
|
||||
* @param beforeAuth /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaInterceptor setBeforeAuth(SaParamFunction<Object> beforeAuth) {
|
||||
this.beforeAuth = beforeAuth;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入 [ 认证函数 ]: 每次请求执行
|
||||
*
|
||||
* @param auth /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaInterceptor setAuth(SaParamFunction<Object> auth) {
|
||||
this.auth = auth;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// ----------------- 验证方法 -----------------
|
||||
|
||||
/**
|
||||
* 每次请求之前触发的方法
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(ServerRequest request, ServerResponse response, MethodMapping handler) {
|
||||
SaTokenContextModelBox prev = SaTokenContextUtil.setContext(request, response);
|
||||
try {
|
||||
// 前置函数:在注解鉴权之前执行
|
||||
beforeAuth.run(handler);
|
||||
|
||||
// 这里必须确保 handler 是 HandlerMethod 类型时,才能进行注解鉴权
|
||||
if (isAnnotation) {
|
||||
Method method = handler.getMappingMethod();
|
||||
SaAnnotationStrategy.instance.checkMethodAnnotation.accept(method);
|
||||
}
|
||||
|
||||
// Auth 路由拦截鉴权校验
|
||||
auth.run(handler);
|
||||
} catch (StopMatchException e) {
|
||||
// StopMatchException 异常代表:停止匹配,进入Controller
|
||||
} catch (BackResultException e) {
|
||||
SaTokenOperateUtil.writeResult(response, e.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
SaTokenContextUtil.clearContext(prev);
|
||||
}
|
||||
|
||||
// 通过验证
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package cn.dev33.satoken.loveqq.boot.model;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.application.ApplicationInfo;
|
||||
import cn.dev33.satoken.context.model.SaRequest;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
|
||||
import java.net.HttpCookie;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 对 SaRequest 包装类的实现
|
||||
*
|
||||
* @author kfyty725
|
||||
*/
|
||||
public class LoveqqSaRequest implements SaRequest {
|
||||
/**
|
||||
* loveqq-framework 包装请求
|
||||
*/
|
||||
private final ServerRequest request;
|
||||
|
||||
public LoveqqSaRequest(ServerRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSource() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParam(String name) {
|
||||
return request.getParameter(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getParamNames() {
|
||||
return request.getParameterNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getParamMap() {
|
||||
return request.getParameterMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader(String name) {
|
||||
return request.getHeader(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCookieValue(String name) {
|
||||
HttpCookie cookie = request.getCookie(name);
|
||||
return cookie == null ? null : cookie.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCookieFirstValue(String name) {
|
||||
HttpCookie[] cookies = request.getCookies();
|
||||
if (cookies != null) {
|
||||
for (HttpCookie cookie : cookies) {
|
||||
if (cookie != null && name.equals(cookie.getName())) {
|
||||
return cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCookieLastValue(String name) {
|
||||
String value = null;
|
||||
HttpCookie[] cookies = request.getCookies();
|
||||
if (cookies != null) {
|
||||
for (HttpCookie cookie : cookies) {
|
||||
if (cookie != null && name.equals(cookie.getName())) {
|
||||
value = cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestPath() {
|
||||
return ApplicationInfo.cutPathPrefix(request.getRequestURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
String currDomain = SaManager.getConfig().getCurrDomain();
|
||||
if (!SaFoxUtil.isEmpty(currDomain)) {
|
||||
return currDomain + this.getRequestPath();
|
||||
}
|
||||
return request.getRequestURL();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return request.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return request.getHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object forward(String path) {
|
||||
ServerResponse response = (ServerResponse) SaManager.getSaTokenContext().getResponse().getSource();
|
||||
return response.sendRedirect(path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.dev33.satoken.loveqq.boot.model;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
|
||||
|
||||
/**
|
||||
* 对 SaResponse 包装类的实现
|
||||
*
|
||||
* @author kfyty725
|
||||
*/
|
||||
public class LoveqqSaResponse implements SaResponse {
|
||||
/**
|
||||
* loveqq-framework 包装响应
|
||||
*/
|
||||
private final ServerResponse response;
|
||||
|
||||
public LoveqqSaResponse(ServerResponse response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSource() {
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaResponse setStatus(int sc) {
|
||||
response.setStatus(sc);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaResponse setHeader(String name, String value) {
|
||||
response.setHeader(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaResponse addHeader(String name, String value) {
|
||||
response.addHeader(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object redirect(String url) {
|
||||
return response.sendRedirect(url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.dev33.satoken.loveqq.boot.model;
|
||||
|
||||
import cn.dev33.satoken.context.model.SaStorage;
|
||||
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
|
||||
|
||||
/**
|
||||
* 对 SaStorage 包装类的实现
|
||||
*
|
||||
* @author kfyty725
|
||||
*/
|
||||
public class LoveqqSaStorage implements SaStorage {
|
||||
/**
|
||||
* loveqq-framework 包装请求
|
||||
*/
|
||||
private final ServerRequest request;
|
||||
|
||||
public LoveqqSaStorage(ServerRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSource() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String key) {
|
||||
return request.getAttribute(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaStorage set(String key, Object value) {
|
||||
request.setAttribute(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaStorage delete(String key) {
|
||||
request.removeAttribute(key);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.oauth2;
|
||||
|
||||
import cn.dev33.satoken.oauth2.SaOAuth2Manager;
|
||||
import cn.dev33.satoken.oauth2.config.SaOAuth2ServerConfig;
|
||||
import cn.dev33.satoken.oauth2.dao.SaOAuth2Dao;
|
||||
import cn.dev33.satoken.oauth2.data.convert.SaOAuth2DataConverter;
|
||||
import cn.dev33.satoken.oauth2.data.generate.SaOAuth2DataGenerate;
|
||||
import cn.dev33.satoken.oauth2.data.loader.SaOAuth2DataLoader;
|
||||
import cn.dev33.satoken.oauth2.data.resolver.SaOAuth2DataResolver;
|
||||
import cn.dev33.satoken.oauth2.granttype.handler.SaOAuth2GrantTypeHandlerInterface;
|
||||
import cn.dev33.satoken.oauth2.processor.SaOAuth2ServerProcessor;
|
||||
import cn.dev33.satoken.oauth2.scope.handler.SaOAuth2ScopeHandlerInterface;
|
||||
import cn.dev33.satoken.oauth2.strategy.SaOAuth2Strategy;
|
||||
import cn.dev33.satoken.oauth2.template.SaOAuth2Template;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Autowired;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.condition.annotation.ConditionalOnClass;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
// 小提示:如果你在 idea 中运行源码时出现异常:java: 程序包cn.dev33.satoken.oauth2不存在。
|
||||
// 在项目根目录进入 cmd,执行 mvn package 即可解决
|
||||
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token-OAuth2 所需要的组件
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.34.0
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnClass("cn.dev33.satoken.oauth2.SaOAuth2Manager")
|
||||
public class SaOAuth2BeanInject {
|
||||
/**
|
||||
* 注入 OAuth2 配置对象
|
||||
*
|
||||
* @param saOAuth2Config 配置对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2Config(SaOAuth2ServerConfig saOAuth2Config) {
|
||||
SaOAuth2Manager.setServerConfig(saOAuth2Config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 OAuth2 模板代码类
|
||||
*
|
||||
* @param saOAuth2Template 模板代码类
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2Template(SaOAuth2Template saOAuth2Template) {
|
||||
SaOAuth2Manager.setTemplate(saOAuth2Template);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 OAuth2 请求处理器
|
||||
*
|
||||
* @param serverProcessor 请求处理器
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2Template(SaOAuth2ServerProcessor serverProcessor) {
|
||||
SaOAuth2ServerProcessor.instance = serverProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 OAuth2 数据加载器
|
||||
*
|
||||
* @param dataLoader /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2DataLoader(SaOAuth2DataLoader dataLoader) {
|
||||
SaOAuth2Manager.setDataLoader(dataLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 OAuth2 数据解析器 Bean
|
||||
*
|
||||
* @param dataResolver /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2DataResolver(SaOAuth2DataResolver dataResolver) {
|
||||
SaOAuth2Manager.setDataResolver(dataResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 OAuth2 数据格式转换器 Bean
|
||||
*
|
||||
* @param dataConverter /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2DataConverter(SaOAuth2DataConverter dataConverter) {
|
||||
SaOAuth2Manager.setDataConverter(dataConverter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 OAuth2 数据构建器 Bean
|
||||
*
|
||||
* @param dataGenerate /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2DataGenerate(SaOAuth2DataGenerate dataGenerate) {
|
||||
SaOAuth2Manager.setDataGenerate(dataGenerate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 OAuth2 数据持久 Bean
|
||||
*
|
||||
* @param dao /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2Dao(SaOAuth2Dao dao) {
|
||||
SaOAuth2Manager.setDao(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义 scope 处理器
|
||||
*
|
||||
* @param handlerList 自定义 scope 处理器集合
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2ScopeHandler(List<SaOAuth2ScopeHandlerInterface> handlerList) {
|
||||
for (SaOAuth2ScopeHandlerInterface handler : handlerList) {
|
||||
SaOAuth2Strategy.instance.registerScopeHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义 grant_type 处理器
|
||||
*
|
||||
* @param handlerList 自定义 grant_type 处理器集合
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaOAuth2GrantTypeHandlerInterface(List<SaOAuth2GrantTypeHandlerInterface> handlerList) {
|
||||
for (SaOAuth2GrantTypeHandlerInterface handler : handlerList) {
|
||||
SaOAuth2Strategy.instance.registerGrantTypeHandler(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.oauth2;
|
||||
|
||||
import cn.dev33.satoken.oauth2.config.SaOAuth2ServerConfig;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Bean;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.ConfigurationProperties;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.condition.annotation.ConditionalOnClass;
|
||||
|
||||
/**
|
||||
* 注册 Sa-Token-OAuth2 所需要的Bean
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.34.0
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnClass("cn.dev33.satoken.oauth2.SaOAuth2Manager")
|
||||
public class SaOAuth2BeanRegister {
|
||||
/**
|
||||
* 获取 OAuth2 配置 Bean
|
||||
*
|
||||
* @return 配置对象
|
||||
*/
|
||||
@Bean
|
||||
@ConfigurationProperties("sa-token.oauth2-server")
|
||||
public SaOAuth2ServerConfig getSaOAuth2Config() {
|
||||
return new SaOAuth2ServerConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Sa-Token 集成 loveqq-framework 的各个组件
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot;
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.sign;
|
||||
|
||||
import cn.dev33.satoken.sign.SaSignManager;
|
||||
import cn.dev33.satoken.sign.config.SaSignConfig;
|
||||
import cn.dev33.satoken.sign.config.SaSignManyConfigWrapper;
|
||||
import cn.dev33.satoken.sign.template.SaSignTemplate;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Autowired;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.condition.annotation.ConditionalOnClass;
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token API 参数签名 所需要的 Bean
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.43.0
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnClass("cn.dev33.satoken.sign.SaSignManager")
|
||||
public class SaSignBeanInject {
|
||||
/**
|
||||
* 注入 API 参数签名配置对象
|
||||
*
|
||||
* @param saSignConfig 配置对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSignConfig(SaSignConfig saSignConfig) {
|
||||
SaSignManager.setConfig(saSignConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 API 参数签名配置对象
|
||||
*
|
||||
* @param signManyConfigWrapper 配置对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSignManyConfig(SaSignManyConfigWrapper signManyConfigWrapper) {
|
||||
SaSignManager.setSignMany(signManyConfigWrapper.getSignMany());
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入自定义的 参数签名 模版方法 Bean
|
||||
*
|
||||
* @param saSignTemplate 参数签名 Bean
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaSignTemplate(SaSignTemplate saSignTemplate) {
|
||||
SaSignManager.setSaSignTemplate(saSignTemplate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.sign;
|
||||
|
||||
import cn.dev33.satoken.sign.config.SaSignConfig;
|
||||
import cn.dev33.satoken.sign.config.SaSignManyConfigWrapper;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Bean;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.ConfigurationProperties;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.condition.annotation.ConditionalOnClass;
|
||||
|
||||
/**
|
||||
* 注册 Sa-Token API 参数签名所需要的 Bean
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.43.0
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnClass("cn.dev33.satoken.sign.SaSignManager")
|
||||
public class SaSignBeanRegister {
|
||||
/**
|
||||
* 获取 API 参数签名配置对象
|
||||
*
|
||||
* @return 配置对象
|
||||
*/
|
||||
@Bean
|
||||
@ConfigurationProperties("sa-token.sign")
|
||||
public SaSignConfig getSaSignConfig() {
|
||||
return new SaSignConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 API 参数签名 Many 配置对象
|
||||
*
|
||||
* @return 配置对象
|
||||
*/
|
||||
@Bean
|
||||
@ConfigurationProperties("sa-token")
|
||||
public SaSignManyConfigWrapper getSaSignManyConfigWrapper() {
|
||||
return new SaSignManyConfigWrapper();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.dev33.satoken.loveqq.boot.sso;
|
||||
|
||||
import cn.dev33.satoken.sso.SaSsoManager;
|
||||
import cn.dev33.satoken.sso.config.SaSsoClientConfig;
|
||||
import cn.dev33.satoken.sso.config.SaSsoServerConfig;
|
||||
import cn.dev33.satoken.sso.processor.SaSsoClientProcessor;
|
||||
import cn.dev33.satoken.sso.processor.SaSsoServerProcessor;
|
||||
import cn.dev33.satoken.sso.template.SaSsoClientTemplate;
|
||||
import cn.dev33.satoken.sso.template.SaSsoServerTemplate;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Autowired;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
|
||||
import com.kfyty.loveqq.framework.core.autoconfig.condition.annotation.ConditionalOnClass;
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token SSO 所需要的 Bean
|
||||
*
|
||||
* @author click33
|
||||
* @since 1.34.0
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnClass("cn.dev33.satoken.sso.SaSsoManager")
|
||||
public class SaSsoBeanInject {
|
||||
/**
|
||||
* 注入 Sa-Token SSO Server 端 配置类
|
||||
*
|
||||
* @param serverConfig 配置对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaSsoServerConfig(SaSsoServerConfig serverConfig) {
|
||||
SaSsoManager.setServerConfig(serverConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token SSO Client 端 配置类
|
||||
*
|
||||
* @param clientConfig 配置对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaSsoClientConfig(SaSsoClientConfig clientConfig) {
|
||||
SaSsoManager.setClientConfig(clientConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 SSO 模板代码类 (Server 端)
|
||||
*
|
||||
* @param ssoServerTemplate /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaSsoServerTemplate(SaSsoServerTemplate ssoServerTemplate) {
|
||||
SaSsoServerProcessor.instance.ssoServerTemplate = ssoServerTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 SSO 模板代码类 (Client 端)
|
||||
*
|
||||
* @param ssoClientTemplate /
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaSsoClientTemplate(SaSsoClientTemplate ssoClientTemplate) {
|
||||
SaSsoClientProcessor.instance.ssoClientTemplate = ssoClientTemplate;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user