refactor: 适配 ContiNew Starter 认证模块-SaToken
This commit is contained in:
parent
8a11a020e0
commit
86ca8f094f
@ -17,6 +17,12 @@
|
|||||||
<description>公共模块(存放公共工具类,公共配置等)</description>
|
<description>公共模块(存放公共工具类,公共配置等)</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- ContiNew Starter 认证模块 - SaToken -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>top.charles7c.continew</groupId>
|
||||||
|
<artifactId>continew-starter-auth-satoken</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- ContiNew Starter 数据访问模块 - MyBatis Plus -->
|
<!-- ContiNew Starter 数据访问模块 - MyBatis Plus -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>top.charles7c.continew</groupId>
|
<groupId>top.charles7c.continew</groupId>
|
||||||
@ -65,19 +71,6 @@
|
|||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- ################ Sa-Token 相关 ################ -->
|
|
||||||
<!-- Sa-Token(轻量级 Java 权限认证框架,让鉴权变得简单、优雅) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.dev33</groupId>
|
|
||||||
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Sa-Token 整合 JWT -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.dev33</groupId>
|
|
||||||
<artifactId>sa-token-jwt</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MySQL Java 驱动 -->
|
<!-- MySQL Java 驱动 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
|
@ -38,7 +38,7 @@ import com.wf.captcha.*;
|
|||||||
public class CaptchaProperties {
|
public class CaptchaProperties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过期时间
|
* 图形验证码过期时间
|
||||||
*/
|
*/
|
||||||
@Value("${captcha.graphic.expirationInMinutes}")
|
@Value("${captcha.graphic.expirationInMinutes}")
|
||||||
private long expirationInMinutes;
|
private long expirationInMinutes;
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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 top.charles7c.cnadmin.auth.config.satoken;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.dao.SaTokenDao;
|
|
||||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
|
||||||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
|
||||||
import cn.dev33.satoken.stp.StpInterface;
|
|
||||||
import cn.dev33.satoken.stp.StpLogic;
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sa-Token 配置
|
|
||||||
*
|
|
||||||
* @author Lion Li(RuoYi-Vue-Plus)
|
|
||||||
* @author Charles7c
|
|
||||||
* @since 2022/12/19 22:13
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Configuration
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class SaTokenConfiguration implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
private final SecurityProperties securityProperties;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
|
||||||
// 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验
|
|
||||||
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin())).addPathPatterns("/**")
|
|
||||||
.excludePathPatterns(securityProperties.getExcludes());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sa-Token 整合 JWT(简单模式)
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public StpLogic stpLogic() {
|
|
||||||
return new StpLogicJwtForSimple();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sa-Token 持久层本地 Redis 适配
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public SaTokenDao saTokenDao() {
|
|
||||||
return new SaTokenRedisDaoImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sa-Token 权限认证适配
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public StpInterface stpInterface() {
|
|
||||||
return new SaTokenPermissionImpl();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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 top.charles7c.cnadmin.auth.config.satoken;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sa-Token 安全配置属性
|
|
||||||
*
|
|
||||||
* @author Lion Li(RuoYi-Vue-Plus)
|
|
||||||
* @author Charles7c
|
|
||||||
* @since 2022/12/19 22:14
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "security")
|
|
||||||
public class SecurityProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 排除路径配置
|
|
||||||
*/
|
|
||||||
private String[] excludes = new String[0];
|
|
||||||
}
|
|
@ -160,26 +160,6 @@ captcha:
|
|||||||
# 模板 ID
|
# 模板 ID
|
||||||
templateId: 1
|
templateId: 1
|
||||||
|
|
||||||
--- ### 安全配置-排除路径配置
|
|
||||||
security.excludes:
|
|
||||||
- /error
|
|
||||||
# 静态资源
|
|
||||||
- /*.html
|
|
||||||
- /**/*.html
|
|
||||||
- /**/*.css
|
|
||||||
- /**/*.js
|
|
||||||
- /webSocket/**
|
|
||||||
# 接口文档相关资源
|
|
||||||
- /favicon.ico
|
|
||||||
- /doc.html
|
|
||||||
- /webjars/**
|
|
||||||
- /swagger-ui/**
|
|
||||||
- /swagger-resources/**
|
|
||||||
- /*/api-docs/**
|
|
||||||
# 本地存储资源
|
|
||||||
- /avatar/**
|
|
||||||
- /file/**
|
|
||||||
|
|
||||||
--- ### 非对称加密配置(例如:密码加密传输,前端公钥加密,后端私钥解密;在线生成 RSA 密钥对:http://web.chacuo.net/netrsakeypair)
|
--- ### 非对称加密配置(例如:密码加密传输,前端公钥加密,后端私钥解密;在线生成 RSA 密钥对:http://web.chacuo.net/netrsakeypair)
|
||||||
rsa:
|
rsa:
|
||||||
# 私钥
|
# 私钥
|
||||||
@ -197,6 +177,28 @@ springdoc:
|
|||||||
swagger-ui:
|
swagger-ui:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
--- ### Sa-Token 扩展配置
|
||||||
|
sa-token.extension:
|
||||||
|
# 安全配置:排除(放行)路径配置
|
||||||
|
security.excludes:
|
||||||
|
- /error
|
||||||
|
# 静态资源
|
||||||
|
- /*.html
|
||||||
|
- /**/*.html
|
||||||
|
- /**/*.css
|
||||||
|
- /**/*.js
|
||||||
|
- /webSocket/**
|
||||||
|
# 接口文档相关资源
|
||||||
|
- /favicon.ico
|
||||||
|
- /doc.html
|
||||||
|
- /webjars/**
|
||||||
|
- /swagger-ui/**
|
||||||
|
- /swagger-resources/**
|
||||||
|
- /*/api-docs/**
|
||||||
|
# 本地存储资源
|
||||||
|
- /avatar/**
|
||||||
|
- /file/**
|
||||||
|
|
||||||
--- ### 文件上传配置
|
--- ### 文件上传配置
|
||||||
spring.servlet:
|
spring.servlet:
|
||||||
multipart:
|
multipart:
|
||||||
|
@ -162,19 +162,6 @@ captcha:
|
|||||||
# 模板 ID
|
# 模板 ID
|
||||||
templateId: 1
|
templateId: 1
|
||||||
|
|
||||||
--- ### 安全配置-排除路径配置
|
|
||||||
security.excludes:
|
|
||||||
- /error
|
|
||||||
# 静态资源
|
|
||||||
- /*.html
|
|
||||||
- /**/*.html
|
|
||||||
- /**/*.css
|
|
||||||
- /**/*.js
|
|
||||||
- /webSocket/**
|
|
||||||
# 本地存储资源
|
|
||||||
- /avatar/**
|
|
||||||
- /file/**
|
|
||||||
|
|
||||||
--- ### 非对称加密配置(例如:密码加密传输,前端公钥加密,后端私钥解密;在线生成 RSA 密钥对:http://web.chacuo.net/netrsakeypair)
|
--- ### 非对称加密配置(例如:密码加密传输,前端公钥加密,后端私钥解密;在线生成 RSA 密钥对:http://web.chacuo.net/netrsakeypair)
|
||||||
rsa:
|
rsa:
|
||||||
# 私钥
|
# 私钥
|
||||||
@ -196,6 +183,21 @@ knife4j:
|
|||||||
# 开启生产环境屏蔽
|
# 开启生产环境屏蔽
|
||||||
production: true
|
production: true
|
||||||
|
|
||||||
|
--- ### Sa-Token 扩展配置
|
||||||
|
sa-token.extension:
|
||||||
|
# 安全配置:排除(放行)路径配置
|
||||||
|
security.excludes:
|
||||||
|
- /error
|
||||||
|
# 静态资源
|
||||||
|
- /*.html
|
||||||
|
- /**/*.html
|
||||||
|
- /**/*.css
|
||||||
|
- /**/*.js
|
||||||
|
- /webSocket/**
|
||||||
|
# 本地存储资源
|
||||||
|
- /avatar/**
|
||||||
|
- /file/**
|
||||||
|
|
||||||
--- ### 文件上传配置
|
--- ### 文件上传配置
|
||||||
spring.servlet:
|
spring.servlet:
|
||||||
multipart:
|
multipart:
|
||||||
|
@ -117,6 +117,13 @@ sa-token:
|
|||||||
is-log: false
|
is-log: false
|
||||||
# JWT 秘钥
|
# JWT 秘钥
|
||||||
jwt-secret-key: asdasdasifhueuiwyurfewbfjsdafjk
|
jwt-secret-key: asdasdasifhueuiwyurfewbfjsdafjk
|
||||||
|
## 扩展配置
|
||||||
|
extension:
|
||||||
|
enabled: true
|
||||||
|
# 自定义缓存实现
|
||||||
|
dao-impl: top.charles7c.cnadmin.auth.config.satoken.SaTokenRedisDaoImpl
|
||||||
|
# 权限认证实现
|
||||||
|
permission-impl: top.charles7c.cnadmin.auth.config.satoken.SaTokenPermissionImpl
|
||||||
|
|
||||||
--- ### MyBatis Plus 配置
|
--- ### MyBatis Plus 配置
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
|
27
pom.xml
27
pom.xml
@ -4,7 +4,10 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<!--
|
<!--
|
||||||
下方 parent 为 ContiNew Starter(Continue New Starter),是一种特殊类型的 Spring Boot Starter,其作用与常规的 Starter 类似,它可以帮助开发人员快速集成常用的第三方库或工具到 Spring 应用程序中。ContiNew Starter 包含了一系列经过优化和配置的依赖包(如 MyBatis-Plus、SaToken),可轻松集成到应用中,从而避免开发人员手动引入依赖的麻烦,为 Spring Boot 项目的灵活快速构建提供支持。
|
下方 parent 为 ContiNew Starter(Continue New Starter),
|
||||||
|
是一种特殊类型的 Spring Boot Starter,其作用与常规的 Starter 类似,它可以帮助开发人员快速集成常用的第三方库或工具到 Spring 应用程序中。
|
||||||
|
ContiNew Starter 包含了一系列经过优化和配置的依赖包(如 MyBatis-Plus、SaToken),
|
||||||
|
可轻松集成到应用中,从而避免开发人员手动引入依赖的麻烦,为 Spring Boot 项目的灵活快速构建提供支持。
|
||||||
-->
|
-->
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>top.charles7c.continew</groupId>
|
<groupId>top.charles7c.continew</groupId>
|
||||||
@ -31,7 +34,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>2.1.0-SNAPSHOT</revision>
|
<revision>2.1.0-SNAPSHOT</revision>
|
||||||
<sa-token.version>1.37.0</sa-token.version>
|
|
||||||
|
|
||||||
<!-- ### 工具库相关 ### -->
|
<!-- ### 工具库相关 ### -->
|
||||||
<sms4j.version>3.0.4</sms4j.version>
|
<sms4j.version>3.0.4</sms4j.version>
|
||||||
@ -46,27 +48,6 @@
|
|||||||
<!-- 全局依赖版本管理 -->
|
<!-- 全局依赖版本管理 -->
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- ################ Sa-Token 相关 ################ -->
|
|
||||||
<!-- Sa-Token(轻量级 Java 权限认证框架,让鉴权变得简单、优雅) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.dev33</groupId>
|
|
||||||
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
|
||||||
<version>${sa-token.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Sa-Token 整合 JWT -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.dev33</groupId>
|
|
||||||
<artifactId>sa-token-jwt</artifactId>
|
|
||||||
<version>${sa-token.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-jwt</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- ################ 工具库相关 ################ -->
|
<!-- ################ 工具库相关 ################ -->
|
||||||
<!-- SMS4J(短信聚合框架,轻松集成多家短信服务,解决接入多个短信 SDK 的繁琐流程) -->
|
<!-- SMS4J(短信聚合框架,轻松集成多家短信服务,解决接入多个短信 SDK 的繁琐流程) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
Loading…
Reference in New Issue
Block a user