Compare commits
188 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5476f543f3 | ||
![]() |
c820bb4e74 | ||
![]() |
d4f30e7de7 | ||
![]() |
384a3f9b92 | ||
![]() |
1e9abcb3f5 | ||
![]() |
ee3948d8e3 | ||
![]() |
4117bd6cc5 | ||
![]() |
0cbeb5b2df | ||
![]() |
335f806566 | ||
![]() |
8655030c7b | ||
![]() |
2635d74af5 | ||
![]() |
da91600948 | ||
![]() |
08cda7b792 | ||
![]() |
a0957a76c1 | ||
![]() |
fe227e62cd | ||
![]() |
502b692fee | ||
![]() |
d28e5fadb5 | ||
![]() |
935da2f093 | ||
![]() |
e78c09ddbe | ||
![]() |
ae9c718ddd | ||
![]() |
844aa24b43 | ||
![]() |
d86def6036 | ||
![]() |
108bd8e7c4 | ||
![]() |
c8738f6eb0 | ||
![]() |
6174ca90e1 | ||
![]() |
3d7fd649fd | ||
![]() |
4224ffdc64 | ||
![]() |
0b3f82660f | ||
![]() |
8230404035 | ||
![]() |
4c5bb90361 | ||
![]() |
15b8251601 | ||
![]() |
0e86f9a111 | ||
![]() |
5de6e70ca1 | ||
![]() |
ee3272918b | ||
![]() |
2219f02a17 | ||
![]() |
4606755e42 | ||
![]() |
d057d654fa | ||
![]() |
8263a252f1 | ||
![]() |
2c98a64d17 | ||
![]() |
2c721c0a09 | ||
![]() |
8555e6d684 | ||
![]() |
70d2864488 | ||
![]() |
6517cdd084 | ||
![]() |
226d18b627 | ||
![]() |
0d91f15061 | ||
![]() |
54b134e942 | ||
![]() |
a53709481c | ||
![]() |
7a67dce923 | ||
![]() |
048fb6abcb | ||
![]() |
3573a71af3 | ||
![]() |
41ea876a96 | ||
![]() |
d494c551d5 | ||
![]() |
445ef5763d | ||
![]() |
92b3efb87d | ||
![]() |
b07033ba51 | ||
![]() |
fad4f8e19e | ||
![]() |
0b99d54edf | ||
![]() |
596cf10a1c | ||
![]() |
659caa1d0e | ||
![]() |
4358633176 | ||
![]() |
9660f65dad | ||
![]() |
f57b1092e4 | ||
![]() |
00e3ee95c3 | ||
![]() |
e5b182a8ef | ||
![]() |
458f60be07 | ||
![]() |
32fd0311b3 | ||
![]() |
d60ca890a2 | ||
![]() |
9d6fc4f539 | ||
![]() |
f3b3bec8b0 | ||
![]() |
bcd06f3d2b | ||
![]() |
f8c699ebbd | ||
![]() |
c91f9686d7 | ||
![]() |
7fb5c26cee | ||
![]() |
c1fb7b4484 | ||
![]() |
918d67abef | ||
![]() |
a2e1acb66c | ||
![]() |
050a48b134 | ||
![]() |
b8ab413eab | ||
![]() |
7c649bb5b2 | ||
![]() |
c9cb308abf | ||
![]() |
0974e65c0a | ||
![]() |
fa75c7155a | ||
![]() |
2c180c89a9 | ||
![]() |
f31983c2c7 | ||
![]() |
62c8e1c877 | ||
![]() |
3bedaa7ddc | ||
![]() |
e7b6dac49f | ||
![]() |
d151c053a7 | ||
![]() |
fc2eab2a6d | ||
![]() |
e28a2a404e | ||
![]() |
773e257fa1 | ||
![]() |
651da9a92a | ||
![]() |
e5ca734018 | ||
![]() |
5b131ad3fd | ||
![]() |
fe848f418a | ||
![]() |
6d484c0bda | ||
![]() |
f366e430f1 | ||
![]() |
7e9ba78376 | ||
![]() |
5a814b947c | ||
![]() |
0af60f5ac5 | ||
![]() |
6b8f3e2ed1 | ||
![]() |
3f829e271d | ||
![]() |
8027f5c2d8 | ||
![]() |
29a620eb41 | ||
![]() |
885918d11f | ||
![]() |
6d31a7107b | ||
![]() |
29ec129069 | ||
![]() |
3f3f3d793a | ||
![]() |
2b7ba78eb1 | ||
![]() |
baf6140159 | ||
![]() |
ba11dd8927 | ||
![]() |
3734a6ef23 | ||
![]() |
a601c8c54c | ||
![]() |
9e4171f4ad | ||
![]() |
254dfe383b | ||
![]() |
a2c31048cb | ||
![]() |
fad44cc117 | ||
![]() |
e0e190671f | ||
![]() |
5e8a8f6cd9 | ||
![]() |
09157fe27f | ||
![]() |
1183249080 | ||
![]() |
ee7ef99c36 | ||
![]() |
3ae17b0657 | ||
![]() |
84be51d691 | ||
![]() |
e6b877366e | ||
![]() |
e112a7b5fe | ||
![]() |
677e5e6168 | ||
![]() |
da582764a7 | ||
![]() |
4ee432bfee | ||
![]() |
eda8a2d33b | ||
![]() |
1d0399b9b0 | ||
![]() |
b0204c224c | ||
![]() |
ee8f101807 | ||
![]() |
6a6bf19db5 | ||
![]() |
32ef43f198 | ||
![]() |
b06857e8c8 | ||
![]() |
74853f4d9c | ||
![]() |
17eb0212fd | ||
![]() |
52ea5f2e2a | ||
![]() |
8f1ce9a5df | ||
![]() |
2868e20c86 | ||
![]() |
54d4b8bf16 | ||
![]() |
14740e817e | ||
![]() |
71d1d7bd77 | ||
![]() |
c39403a0d2 | ||
![]() |
9c8de8afbf | ||
![]() |
a84a3c6049 | ||
![]() |
9f4991f32f | ||
![]() |
d09b65c396 | ||
![]() |
9b1602649e | ||
![]() |
ec9ff68567 | ||
![]() |
58c62ee6b4 | ||
![]() |
0993d1abf3 | ||
![]() |
52d7c80683 | ||
![]() |
815da0f1fa | ||
![]() |
578e2ae583 | ||
![]() |
f72cfbcb3b | ||
![]() |
fe75716c7f | ||
![]() |
f3e2afcaa3 | ||
![]() |
b0d0aefde8 | ||
![]() |
741b4a842e | ||
![]() |
f2cad965fd | ||
![]() |
7a4ef2efdd | ||
![]() |
967427c8bc | ||
![]() |
55c8c842dc | ||
![]() |
071ba49c92 | ||
![]() |
95599f3350 | ||
![]() |
714c371ee2 | ||
![]() |
873d809df5 | ||
![]() |
bfe02a50ac | ||
![]() |
5a1c99cfd5 | ||
![]() |
4946f2f45f | ||
![]() |
a862b258fc | ||
![]() |
a2e904d1f2 | ||
![]() |
6e9d42088b | ||
![]() |
617cf85209 | ||
![]() |
c14f8d098f | ||
![]() |
a03742f481 | ||
![]() |
3693ee1a35 | ||
![]() |
dd3349bf2e | ||
![]() |
64685e74f9 | ||
![]() |
64fea077c2 | ||
![]() |
c8643dc779 | ||
![]() |
abef9c503f | ||
![]() |
02c55cf5df | ||
![]() |
ed30212ddc | ||
![]() |
cf81b1f67c | ||
![]() |
3786e6f078 |
72
README.md
72
README.md
@ -1,13 +1,13 @@
|
||||
<p align="center">
|
||||
<img alt="logo" src="https://gitee.com/dataprince/ruoyi-flex/raw/master/image/ruoyi-flex-logo.png">
|
||||
</p>
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Ruoyi-Flex V4.2.0</h1>
|
||||
<h4 align="center">Ruoyi-Flex是基于JDK21、Spring Boot V3.2.X+平台 前后端分离的Java快速开发框架</h4>
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Ruoyi-Flex V5.2.0-SNAPSHOT</h1>
|
||||
<h4 align="center">Ruoyi-Flex是基于JDK21、Spring Boot V3.2.X+平台 前后端分离的未来8年更快的Java开发框架</h4>
|
||||
|
||||
|
||||
## 1、平台简介
|
||||
|
||||
Ruoyi-Flex是一套全部开源的快速开发平台,使用MIT开源许可协议,毫无保留给个人及企业免费使用。基于RuoYi-Vue、RuoYi-Vue-Plus,集成MyBatis-Flex、JDK21、SpringBootV3.2.X+、Lombok、Sa-Token、SpringDoc、Hutool、SpringBoot Admin、PowerJob、Vue3、Element-Plus、MinIO等优秀开源软件。
|
||||
Ruoyi-Flex是一套全部开源的快速开发平台,针对”分布式集群与多租户“场景全方位升级,使用MIT开源许可协议,毫无保留给个人及企业免费使用。基于RuoYi-Vue、RuoYi-Vue-Plus,集成MyBatis-Flex、JDK21、SpringBootV3.2.X+、Lombok、Sa-Token、SpringDoc、Hutool、SpringBoot Admin、EasyRetry、PowerJob、Vue3、Element-Plus、AntDesign-Vben、MinIO、Flowable等优秀开源软件,支持PostgreSQL、MySQL开源数据库及其衍生分布式数据库。
|
||||
|
||||
## 2、系统特色
|
||||
Ruoyi-Flex秉承“写的更少、性能更好、出错更低、交流通畅、快速入门” 的理念,为您带来全方位的赋能与提升:
|
||||
@ -28,33 +28,53 @@ Ruoyi-Flex秉承“写的更少、性能更好、出错更低、交流通畅、
|
||||
### (4)交流通畅
|
||||
“非我族类,其心必异”。Ruoyi-Flex集成了一大波国产开源软件:MyBatis-Flex、Sa-Token、Hutool、PowerJob、Element-Plus等,同根同源,交流自然顺畅,开发中遇到问题可联系作者快速得到解决。例如,同一个领域的安全框架,一个中国人只需半天就可学会Sa-Token干活,如果是学Spring Security的话,七天也不一定能学会。
|
||||
|
||||
### (5)入门快速
|
||||
### (5)多端同步
|
||||
Ruoyi-Flex提供“1+3”端,1个后台端、3个前台端,熟悉js的可使用flex-elementplus-ui前端,熟悉ts的可使用ruoyiflex-elementplus-ts前端,既熟悉ts又熟悉antdesign的请使用ruoyiflex-antdesign-vben前端,总有一款适合您的前端供您选择!
|
||||
|
||||
### (6)入门快速
|
||||
Ruoyi-Flex已集成各种开源开发框架,扫平了技术障碍,可直接上手干活。使用者只需要设计好数据库表结构,系统能可视化生成前后端本地代码,单表、树表、主子表任你选,10分钟就能开发一个模块,快速入门,开发高效。
|
||||
|
||||
## 3、前端项目
|
||||
Ruoyi-Flex实行前后端分离仓库,本项目是java后端部分,前端项目是flex-elementplus-ui,前端项目地址: [flex-elementplus-ui](https://gitee.com/dataprince/flex-elementplus-ui)
|
||||
Ruoyi-Flex实行前后端分离仓库,本项目是java后端部分,目前有3个前端项目:
|
||||
|
||||
### (1)ruoyiflex-elementplus-ts
|
||||
使用elementplus、typescript构建,项目地址: [ruoyiflex-elementplus-ts](https://gitee.com/dataprince/ruoyiflex-elementplus-ts)
|
||||
|
||||
### (2)ruoyiflex-antdesign-vben
|
||||
使用antdesign、vben、typescript构建,项目地址: [ruoyiflex-antdesign-vben](https://gitee.com/dataprince/ruoyiflex-antdesign-vben)
|
||||
|
||||
### (3)flex-elementplus-ui
|
||||
使用elementplus、js构建,项目地址: [flex-elementplus-ui](https://gitee.com/dataprince/flex-elementplus-ui)
|
||||
|
||||
## 4、内置功能
|
||||
|
||||
1. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。
|
||||
2. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。
|
||||
3. 岗位管理:配置系统用户所属担任职务。
|
||||
4. 菜单管理:配置系统菜单,操作权限,按钮权限标识等。
|
||||
5. 角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。
|
||||
6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。
|
||||
7. 参数管理:对系统动态配置常用参数。
|
||||
8. 通知公告:系统通知公告信息发布维护。
|
||||
9. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。
|
||||
10. 登录日志:系统登录日志记录查询包含登录异常。
|
||||
11. 文件管理:引入云存储服务,将文件存储到MinIO、七牛、阿里、腾讯等OSS服务器上,支持上传、下载。
|
||||
12. 在线用户:当前系统中活跃用户状态监控。
|
||||
13. 调度中心:集成PowerJob全新一代分布式任务调度与计算框架。
|
||||
14. 代码生成:前后端代码的生成(java、html、vue、js),支持单表、树表、主子表,减少70%以上的开发工作量。
|
||||
15. 系统接口:集成springdoc,根据文档注释自动生成相关的api接口文档。
|
||||
16. 监控中心:集成Spring Boot Admin,监视集群系统CPU、内存、磁盘、堆栈、在线日志、Spring相关配置等。
|
||||
17. 缓存监控:对系统的缓存信息查询,命令统计等。
|
||||
18. 后台数据库支持:MySQL、PostgreSQL数据库。
|
||||
19. 演示模块:mybatis、mybatis-flex两种格式代码的单表、树表、主子表三种类型的演示程序。
|
||||
1. 租户管理:系统内租户的管理 如:租户套餐、过期时间、用户数量、企业信息等。
|
||||
2. 租户套餐管理:系统内租户所能使用的套餐管理 如:套餐内所包含的菜单等。
|
||||
3. 客户端管理:系统内对接的所有客户端管理 如: pc端、小程序端等支持动态授权登录方式 如: 短信登录、密码登录等 支持动态控制token时效。
|
||||
4. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。
|
||||
5. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。
|
||||
6. 岗位管理:配置系统用户所属担任职务。
|
||||
7. 菜单管理:配置系统菜单,操作权限,按钮权限标识等。
|
||||
8. 角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。
|
||||
9. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。
|
||||
10. 参数管理:对系统动态配置常用参数。
|
||||
11. 通知公告:系统通知公告信息发布维护。
|
||||
12. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。
|
||||
13. 登录日志:系统登录日志记录查询包含登录异常。
|
||||
14. 文件管理:引入云存储服务,将文件存储到MinIO、七牛、阿里、腾讯等OSS服务器上,支持上传、下载。
|
||||
15. 在线用户:当前系统中活跃用户状态监控。
|
||||
16. 调度中心:集成PowerJob全新一代分布式任务调度与计算框架。
|
||||
17. 代码生成:前后端代码的生成(java、html、vue、js),支持单表、树表、主子表,减少70%以上的开发工作量。
|
||||
18. 系统接口:集成springdoc,根据文档注释自动生成相关的api接口文档。
|
||||
19. 监控中心:集成Spring Boot Admin,监视集群系统CPU、内存、磁盘、堆栈、在线日志、Spring相关配置等。
|
||||
20. 缓存监控:对系统的缓存信息查询,命令统计等。
|
||||
21. 后台数据库:支持PostgreSQL、MySQL开源数据库及其衍生分布式数据库。
|
||||
22. 演示模块:mybatis、mybatis-flex两种格式代码的单表、树表、主子表三种类型的演示程序。
|
||||
23. 实现多租户功能。
|
||||
24. 实现乐观锁功能。
|
||||
25. 实现逻辑删除功能。
|
||||
26. 启用JAVA21虚拟线程、分代ZGC功能。
|
||||
27. 实现API接口加密功能,密码使用密文传输。
|
||||
|
||||
## 5、演示图
|
||||
|
||||
@ -88,14 +108,14 @@ Ruoyi-Flex实行前后端分离仓库,本项目是java后端部分,前端项
|
||||
|
||||
## 7、Ruoyi-Flex交流群
|
||||
|
||||
本软件完全开源,作者很忙,如果您在使用过程中遇到问题,请付点小费(扫码微信支付199元)后申请加入微信群寻求帮助:
|
||||
本软件完全开源,作者很忙,如果您在使用过程中遇到问题,请付点小费(扫码微信支付99元)后申请加入微信群寻求帮助:
|
||||
<table>
|
||||
<tr>
|
||||
<td>1、免费QQ交流群:</td>
|
||||
<td>762217712[交流1群]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2、付费微信交流群:</td>
|
||||
<td>2、付费微信VIP群(微信扫码支付99元加好友入群):</td>
|
||||
<td><img src="https://gitee.com/dataprince/ruoyi-flex/raw/master/image/dataprince.jpg"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
Binary file not shown.
BIN
doc/~$oyi-Flex-Guide.docx
Normal file
BIN
doc/~$oyi-Flex-Guide.docx
Normal file
Binary file not shown.
169
pom.xml
169
pom.xml
@ -13,53 +13,64 @@
|
||||
<description>Ruoyi-Flex管理系统</description>
|
||||
|
||||
<properties>
|
||||
<revision>4.2.0</revision>
|
||||
<revision>5.2.0-SNAPSHOT</revision>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>21</java.version>
|
||||
<spring-boot.version>3.2.0</spring-boot.version>
|
||||
<mybatis-flex.version>1.7.5</mybatis-flex.version>
|
||||
<mybatis-spring.version>3.0.3</mybatis-spring.version>
|
||||
<satoken.version>1.37.0</satoken.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
<HikariCP.version>5.0.1</HikariCP.version>
|
||||
<spring-boot.version>3.2.5</spring-boot.version>
|
||||
<mybatis-flex.version>1.9.4</mybatis-flex.version>
|
||||
<satoken.version>1.38.0</satoken.version>
|
||||
<HikariCP.version>5.1.0</HikariCP.version>
|
||||
<bitwalker.version>1.21</bitwalker.version>
|
||||
<caffeine.version>3.1.8</caffeine.version>
|
||||
<kaptcha.version>2.3.3</kaptcha.version>
|
||||
<pagehelper.version>5.3.3</pagehelper.version>
|
||||
<pagehelper.version>6.1.0</pagehelper.version>
|
||||
<fastjson.version>2.0.43</fastjson.version>
|
||||
<oshi.version>6.4.8</oshi.version>
|
||||
<commons.collections.version>3.2.2</commons.collections.version>
|
||||
<poi.version>5.2.3</poi.version>
|
||||
<easyexcel.version>3.3.2</easyexcel.version>
|
||||
<poi.version>5.2.5</poi.version>
|
||||
<easyexcel.version>3.3.3</easyexcel.version>
|
||||
<velocity.version>2.3</velocity.version>
|
||||
<jwt.version>0.9.1</jwt.version>
|
||||
<servlet-api.version>6.0.0</servlet-api.version>
|
||||
<guava.version>32.1.1-jre</guava.version>
|
||||
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
|
||||
<springdoc.version>2.2.0</springdoc.version>
|
||||
<springdoc-openapi-starter-common.version>2.2.0</springdoc-openapi-starter-common.version>
|
||||
<springdoc.version>2.4.0</springdoc.version>
|
||||
<springdoc-openapi-starter-common.version>2.4.0</springdoc-openapi-starter-common.version>
|
||||
<therapi-runtime-javadoc.version>0.15.0</therapi-runtime-javadoc.version>
|
||||
<snakeyaml.version>2.2</snakeyaml.version>
|
||||
<lombok.version>1.18.30</lombok.version>
|
||||
<mapstruct-plus.version>1.3.5</mapstruct-plus.version>
|
||||
<mapstruct-plus.version>1.3.6</mapstruct-plus.version>
|
||||
<mapstruct-plus.lombok.version>0.2.0</mapstruct-plus.lombok.version>
|
||||
<hutool.version>5.8.22</hutool.version>
|
||||
<redisson.version>3.25.1</redisson.version>
|
||||
<lock4j.version>2.2.4</lock4j.version>
|
||||
<alibaba-ttl.version>2.14.3</alibaba-ttl.version>
|
||||
<spring-boot-admin.version>3.1.6</spring-boot-admin.version>
|
||||
<hutool.version>5.8.27</hutool.version>
|
||||
<redisson.version>3.27.2</redisson.version>
|
||||
<lock4j.version>2.2.7</lock4j.version>
|
||||
<alibaba-ttl.version>2.14.4</alibaba-ttl.version>
|
||||
<spring-boot-admin.version>3.2.3</spring-boot-admin.version>
|
||||
<powerjob.version>4.3.6</powerjob.version>
|
||||
<easyretry.version>3.2.0</easyretry.version>
|
||||
<!-- 离线IP地址定位库 -->
|
||||
<ip2region.version>2.7.0</ip2region.version>
|
||||
<!-- OSS 配置 -->
|
||||
<aws-java-sdk-s3.version>1.12.540</aws-java-sdk-s3.version>
|
||||
<aws.sdk.version>2.25.15</aws.sdk.version>
|
||||
<aws.crt.version>0.29.13</aws.crt.version>
|
||||
<!-- 加解密依赖库 -->
|
||||
<bcprov-jdk.version>1.77</bcprov-jdk.version>
|
||||
<!-- SMS 配置 -->
|
||||
<sms4j.version>3.2.0</sms4j.version>
|
||||
<!-- findbugs消除打包警告 -->
|
||||
<jsr305.version>3.0.2</jsr305.version>
|
||||
<!-- 三方授权认证 -->
|
||||
<justauth.version>1.16.6</justauth.version>
|
||||
|
||||
<!-- 插件版本 -->
|
||||
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
|
||||
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
|
||||
<maven-compiler-plugin.verison>3.11.0</maven-compiler-plugin.verison>
|
||||
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
|
||||
<flatten-maven-plugin.version>1.3.0</flatten-maven-plugin.version>
|
||||
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
|
||||
|
||||
<!--工作流配置-->
|
||||
<flowable.version>7.0.0</flowable.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
@ -96,6 +107,13 @@
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- validation检验-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- hutool 的依赖配置-->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
@ -105,6 +123,15 @@
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- flowable 的依赖配置-->
|
||||
<dependency>
|
||||
<groupId>org.flowable</groupId>
|
||||
<artifactId>flowable-bom</artifactId>
|
||||
<version>${flowable.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- common 的依赖配置-->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
@ -122,11 +149,6 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 数据库连接池-->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
@ -137,21 +159,8 @@
|
||||
<!-- mybatis-flex -->
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||
<version>${mybatis-flex.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- 添加已适配 springboot 3.2 的 mybatis-spring 依赖-->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>${mybatis-spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token 权限认证,在线文档:https://sa-token.cc -->
|
||||
@ -178,6 +187,13 @@
|
||||
<version>${satoken.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- caffeine缓存 -->
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<version>${caffeine.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- servlet包 -->
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
@ -338,11 +354,44 @@
|
||||
<version>${ip2region.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- OSS 配置 -->
|
||||
<!-- AWS SDK for Java 2.x -->
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<version>${aws-java-sdk-s3.version}</version>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3</artifactId>
|
||||
<version>${aws.sdk.version}</version>
|
||||
</dependency>
|
||||
<!-- 使用AWS基于 CRT 的 S3 客户端 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk.crt</groupId>
|
||||
<artifactId>aws-crt</artifactId>
|
||||
<version>${aws.crt.version}</version>
|
||||
</dependency>
|
||||
<!-- 基于 AWS CRT 的 S3 客户端的性能增强的 S3 传输管理器 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3-transfer-manager</artifactId>
|
||||
<version>${aws.sdk.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 加解密依赖库 -->
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
<version>${bcprov-jdk.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- findbugs消除打包警告 -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>${jsr305.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JustAuth 的依赖配置-->
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>${justauth.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--Annotation Processor-->
|
||||
@ -358,6 +407,13 @@
|
||||
<version>${alibaba-ttl.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--短信sms4j-->
|
||||
<dependency>
|
||||
<groupId>org.dromara.sms4j</groupId>
|
||||
<artifactId>sms4j-spring-boot-starter</artifactId>
|
||||
<version>${sms4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- spring-boot-admin监控-->
|
||||
<dependency>
|
||||
<groupId>de.codecentric</groupId>
|
||||
@ -389,6 +445,23 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- EasyRetry Client -->
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-starter</artifactId>
|
||||
<version>${easyretry.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-core</artifactId>
|
||||
<version>${easyretry.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-job-core</artifactId>
|
||||
<version>${easyretry.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 代码生成-->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
@ -403,7 +476,6 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- demo模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
@ -411,6 +483,13 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 工作流模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-workflow</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
8
ruoyi-admin/Dockerfile
Normal file
8
ruoyi-admin/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
# 使用官方的 Java 运行时作为父镜像
|
||||
FROM registry.cn-qingdao.aliyuncs.com/yuzl1/jdk:21
|
||||
|
||||
# 将本地文件复制到容器中
|
||||
COPY target/ruoyi-admin.jar /ruoyi-admin.jar
|
||||
|
||||
# 运行应用
|
||||
ENTRYPOINT ["java","-jar","/ruoyi-admin.jar"]
|
@ -31,12 +31,23 @@
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 三方授权认证 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-social</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- PostgreSql -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-tenant</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- system模块-->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
@ -67,11 +78,18 @@
|
||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- powerjob 客户端 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>tech.powerjob</groupId>-->
|
||||
<!-- <artifactId>powerjob-worker-spring-boot-starter</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-job-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -2,20 +2,23 @@ package com.ruoyi;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = SpringDataWebAutoConfiguration.class)
|
||||
public class RuoYiApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.setProperty("spring.devtools.restart.enabled", "false");
|
||||
SpringApplication.run(RuoYiApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ RuoYi-Flex启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
SpringApplication application = new SpringApplication(RuoYiApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ RuoYi-Flex-Boot启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
" ███████ ██ ██ ██ ████████ ██ \n" +
|
||||
"░██░░░░██ ░░██ ██ ░░ ░██░░░░░ ░██ \n" +
|
||||
"░██ ░██ ██ ██ ██████ ░░████ ██ ░██ ░██ █████ ██ ██\n" +
|
||||
|
@ -1,33 +1,48 @@
|
||||
package com.ruoyi.web.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.core.domain.model.SocialLoginBody;
|
||||
import com.ruoyi.common.core.utils.*;
|
||||
import com.ruoyi.common.encrypt.annotation.ApiEncrypt;
|
||||
import com.ruoyi.common.json.utils.JsonUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.SysMenu;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.common.social.config.properties.SocialLoginConfigProperties;
|
||||
import com.ruoyi.common.social.config.properties.SocialProperties;
|
||||
import com.ruoyi.common.social.utils.SocialUtils;
|
||||
import com.ruoyi.common.websocket.dto.WebSocketMessageDto;
|
||||
import com.ruoyi.common.websocket.utils.WebSocketUtils;
|
||||
import com.ruoyi.system.domain.bo.SysTenantBo;
|
||||
import com.ruoyi.system.domain.vo.SysClientVo;
|
||||
import com.ruoyi.system.domain.vo.SysTenantVo;
|
||||
import com.ruoyi.system.service.*;
|
||||
import com.ruoyi.web.domain.vo.LoginTenantVo;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import com.ruoyi.web.domain.vo.TenantListVo;
|
||||
import com.ruoyi.web.service.SysRegisterService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.core.core.domain.R;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginBody;
|
||||
import com.ruoyi.common.core.core.domain.model.RegisterBody;
|
||||
import com.ruoyi.common.core.utils.MessageUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.SysClient;
|
||||
import com.ruoyi.web.service.IAuthStrategy;
|
||||
import com.ruoyi.web.service.SysLoginService;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.ruoyi.system.domain.table.SysClientTableDef.SYS_CLIENT;
|
||||
|
||||
@ -39,88 +54,115 @@ import static com.ruoyi.system.domain.table.SysClientTableDef.SYS_CLIENT;
|
||||
*/
|
||||
@Slf4j
|
||||
@SaIgnore
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/auth")
|
||||
public class AuthController {
|
||||
|
||||
@Resource
|
||||
private final SysLoginService loginService;
|
||||
private SysLoginService loginService;
|
||||
@Resource
|
||||
private final ISysClientService clientService;
|
||||
private ISysClientService clientService;
|
||||
@Resource
|
||||
private final ISysUserService sysUserService;
|
||||
private SysRegisterService registerService;
|
||||
@Resource
|
||||
private final ISysPermissionService permissionService;
|
||||
private ISysConfigService configService;
|
||||
@Resource
|
||||
private ISysMenuService menuService;
|
||||
private ISysTenantService tenantService;
|
||||
@Resource
|
||||
private ISysSocialService socialService;
|
||||
|
||||
private final ScheduledExecutorService scheduledExecutorService;
|
||||
private final SocialProperties socialProperties;
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
* @param loginBody 登录信息
|
||||
* @param body 登录信息
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiEncrypt
|
||||
@PostMapping("/login")
|
||||
public R<LoginVo> login(@Validated @RequestBody LoginBody loginBody) {
|
||||
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
public R<LoginVo> login(@RequestBody String body) {
|
||||
LoginBody loginBody = JsonUtils.parseObject(body, LoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
// 授权类型和客户端id
|
||||
String clientId = loginBody.getClientId();
|
||||
String grantType = loginBody.getGrantType();
|
||||
QueryWrapper query=QueryWrapper.create().from(SYS_CLIENT).where(SYS_CLIENT.CLIENT_ID.eq(clientId));
|
||||
SysClient client = clientService.getOne(query);
|
||||
SysClientVo client = clientService.getOneAs(query,SysClientVo.class);
|
||||
// 查询不到 client 或 client 内不包含 grantType
|
||||
if (ObjectUtil.isNull(client) || !StringUtils.contains(client.getGrantType(), grantType)) {
|
||||
log.info("客户端id: {} 认证类型:{} 异常!.", clientId, grantType);
|
||||
return R.fail(MessageUtils.message("auth.grant.type.error"));
|
||||
} else if (!UserConstants.NORMAL.equals(client.getStatus())) {
|
||||
return R.fail(MessageUtils.message("auth.grant.type.blocked"));
|
||||
}
|
||||
|
||||
// TODO:校验租户
|
||||
//loginService.checkTenant(loginBody.getTenantId());
|
||||
// 校验租户
|
||||
loginService.checkTenant(loginBody.getTenantId());
|
||||
|
||||
// 登录
|
||||
return R.ok(IAuthStrategy.login(loginBody, client));
|
||||
LoginVo loginVo =IAuthStrategy.login(body, client, grantType);
|
||||
|
||||
Long userId = LoginHelper.getUserId();
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
WebSocketMessageDto dto = new WebSocketMessageDto();
|
||||
dto.setMessage("欢迎登录RuoYi-Flex多租户管理系统");
|
||||
dto.setSessionKeys(List.of(userId));
|
||||
WebSocketUtils.publishMessage(dto);
|
||||
}, 3, TimeUnit.SECONDS);
|
||||
|
||||
return R.ok(loginVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* 第三方登录请求
|
||||
*
|
||||
* @return 用户信息
|
||||
* @param source 登录来源
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/getInfo")
|
||||
public AjaxResult getInfo() {
|
||||
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
|
||||
//TODO:多租户 超级管理员 如果重新加载用户信息需清除动态租户
|
||||
|
||||
SysUserVo user = sysUserService.selectUserById(loginUser.getUserId());
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(user.getUserId());
|
||||
// 权限集合
|
||||
Set<String> permissions = permissionService.getMenuPermission(user.getUserId());
|
||||
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("user", user);
|
||||
ajax.put("roles", roles);
|
||||
ajax.put("permissions", permissions);
|
||||
return ajax;
|
||||
@GetMapping("/binding/{source}")
|
||||
public R<String> authBinding(@PathVariable("source") String source) {
|
||||
SocialLoginConfigProperties obj = socialProperties.getType().get(source);
|
||||
if (ObjectUtil.isNull(obj)) {
|
||||
return R.fail(source + "平台账号暂不支持");
|
||||
}
|
||||
AuthRequest authRequest = SocialUtils.getAuthRequest(source, socialProperties);
|
||||
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
|
||||
return R.ok("操作成功", authorizeUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由信息
|
||||
* 第三方登录回调业务处理 绑定授权
|
||||
*
|
||||
* @return 路由信息
|
||||
* @param loginBody 请求体
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/getRouters")
|
||||
public AjaxResult getRouters()
|
||||
{
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
// 用户信息
|
||||
SysUserVo user = sysUserService.selectUserById(loginUser.getUserId());
|
||||
List<SysMenu> menus = menuService.selectMenuTreeByUserId(user.getUserId());
|
||||
return AjaxResult.success(menuService.buildMenus(menus));
|
||||
@PostMapping("/social/callback")
|
||||
public R<Void> socialCallback(@RequestBody SocialLoginBody loginBody) {
|
||||
// 获取第三方登录信息
|
||||
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
|
||||
loginBody.getSource(), loginBody.getSocialCode(),
|
||||
loginBody.getSocialState(), socialProperties);
|
||||
AuthUser authUserData = response.getData();
|
||||
// 判断授权响应是否成功
|
||||
if (!response.ok()) {
|
||||
return R.fail(response.getMsg());
|
||||
}
|
||||
loginService.socialRegister(authUserData);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消授权
|
||||
*
|
||||
* @param socialId socialId
|
||||
*/
|
||||
@DeleteMapping(value = "/unlock/{socialId}")
|
||||
public R<Void> unlockSocial(@PathVariable Long socialId) {
|
||||
Boolean rows = socialService.deleteWithValidById(socialId);
|
||||
return rows ? R.ok() : R.fail("取消授权失败");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,14 +177,42 @@ public class AuthController {
|
||||
/**
|
||||
* 用户注册
|
||||
*/
|
||||
@PostMapping("LoginHelper.getUserId()")
|
||||
@PostMapping("/register")
|
||||
public R<Void> register(@Validated @RequestBody RegisterBody user) {
|
||||
//if (!configService.selectRegisterEnabled(user.getTenantId())) // TODO:注册代码
|
||||
if (!configService.selectRegisterEnabled(user.getTenantId()))
|
||||
{
|
||||
return R.fail("当前系统没有开启注册功能!");
|
||||
}
|
||||
// registerService.register(user);
|
||||
// return R.ok();
|
||||
registerService.register(user);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录页面租户下拉框
|
||||
*
|
||||
* @return 租户列表
|
||||
*/
|
||||
@GetMapping("/tenant/list")
|
||||
public R<LoginTenantVo> tenantList(HttpServletRequest request) throws Exception {
|
||||
List<SysTenantVo> tenantList = tenantService.selectList(new SysTenantBo());
|
||||
List<TenantListVo> voList = MapstructUtils.convert(tenantList, TenantListVo.class);
|
||||
// 获取域名
|
||||
String host;
|
||||
String referer = request.getHeader("referer");
|
||||
if (StringUtils.isNotBlank(referer)) {
|
||||
// 这里从referer中取值是为了本地使用hosts添加虚拟域名,方便本地环境调试
|
||||
host = referer.split("//")[1].split("/")[0];
|
||||
} else {
|
||||
host = new URL(request.getRequestURL().toString()).getHost();
|
||||
}
|
||||
// 根据域名进行筛选
|
||||
List<TenantListVo> list = StreamUtils.filter(voList, vo ->
|
||||
StringUtils.equals(vo.getDomain(), host));
|
||||
// 返回对象
|
||||
LoginTenantVo vo = new LoginTenantVo();
|
||||
vo.setTenantEnabled(true);
|
||||
vo.setVoList(CollUtil.isNotEmpty(list) ? list : voList);
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,21 +2,35 @@ package com.ruoyi.web.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import cn.hutool.captcha.AbstractCaptcha;
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.ruoyi.common.core.annotation.RateLimiter;
|
||||
import com.ruoyi.common.core.constant.GlobalConstants;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.enums.LimitType;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.reflect.ReflectUtils;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.core.domain.R;
|
||||
import com.ruoyi.common.encrypt.utils.RSAUtils;
|
||||
import com.ruoyi.common.mail.config.properties.MailProperties;
|
||||
import com.ruoyi.common.mail.utils.MailUtils;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.web.enums.CaptchaType;
|
||||
import com.ruoyi.web.domain.vo.CaptchaVo;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
@ -30,6 +44,7 @@ import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
||||
* 验证码操作处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @author 数据小王子
|
||||
*/
|
||||
@SaIgnore
|
||||
@Slf4j
|
||||
@ -39,17 +54,19 @@ import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
||||
public class CaptchaController
|
||||
{
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final MailProperties mailProperties;
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
@GetMapping("/captchaImage")
|
||||
public AjaxResult getCode() {
|
||||
@RateLimiter(time = 60, count = 10, limitType = LimitType.IP)
|
||||
@GetMapping("/auth/code")
|
||||
public R<CaptchaVo> getCode() {
|
||||
CaptchaVo captchaVo = new CaptchaVo();
|
||||
boolean captchaEnabled = captchaProperties.getEnable();
|
||||
if (!captchaEnabled) {
|
||||
captchaVo.setCaptchaEnabled(false);
|
||||
return AjaxResult.success(captchaVo);
|
||||
return R.ok(captchaVo);
|
||||
}
|
||||
// 保存验证码信息
|
||||
String uuid = IdUtil.simpleUUID();
|
||||
@ -62,6 +79,7 @@ public class CaptchaController
|
||||
AbstractCaptcha captcha = SpringUtils.getBean(captchaProperties.getCategory().getClazz());
|
||||
captcha.setGenerator(codeGenerator);
|
||||
captcha.createCode();
|
||||
// 如果是数学验证码,使用SpEL表达式处理验证码结果
|
||||
String code = captcha.getCode();
|
||||
if (isMath) {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
@ -72,8 +90,76 @@ public class CaptchaController
|
||||
|
||||
captchaVo.setUuid(uuid);
|
||||
captchaVo.setImg(captcha.getImageBase64());
|
||||
return AjaxResult.success(captchaVo);
|
||||
return R.ok(captchaVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证码
|
||||
*
|
||||
* @param email 邮箱
|
||||
*/
|
||||
@RateLimiter(key = "#email", time = 60, count = 1)
|
||||
@GetMapping("/resource/email/code")
|
||||
public R<Void> emailCode(@NotBlank(message = "{user.email.not.blank}") String email) {
|
||||
if (!mailProperties.getEnabled()) {
|
||||
return R.fail("当前系统没有开启邮箱功能!");
|
||||
}
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + email;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
try {
|
||||
MailUtils.sendText(email, "登录验证码", "您本次验证码为:" + code + ",有效性为" + Constants.CAPTCHA_EXPIRATION + "分钟,请尽快填写。");
|
||||
} catch (Exception e) {
|
||||
log.error("验证码短信发送异常 => {}", e.getMessage());
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
*
|
||||
* @param phonenumber 用户手机号
|
||||
*/
|
||||
@RateLimiter(key = "#phonenumber", time = 60, count = 1)
|
||||
@GetMapping("/resource/sms/code")
|
||||
public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) {
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
// 验证码模板id 自行处理 (查数据库或写死均可)
|
||||
String templateId = "";
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
||||
map.put("code", code);
|
||||
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
||||
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
||||
if (!smsResponse.isSuccess()) {
|
||||
log.error("验证码短信发送异常 => {}", smsResponse);
|
||||
return R.fail(smsResponse.getData().toString());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/genKeyPair")
|
||||
public R genKeyPair() {
|
||||
Map<String,String> map=new HashMap<>();
|
||||
try {
|
||||
log.info("开始生产rsa秘钥");
|
||||
|
||||
Map<String, Object> keyPair = RSAUtils.genKeyPair();
|
||||
String publicKey = RSAUtils.getPublicKey(keyPair);
|
||||
String privateKey = RSAUtils.getPrivateKey(keyPair);
|
||||
log.info("privateKey:"+privateKey);
|
||||
String uuid="ruoyi_"+ UUID.randomUUID().toString().replace("-","");
|
||||
RedisUtils.setCacheMapValue("loginRsa",uuid,privateKey);
|
||||
RedisUtils.expire("loginRsa",60*60);
|
||||
log.info("写入redis完成");
|
||||
|
||||
map.put("uuidPrivateKey",uuid);
|
||||
map.put("RSA_PUBLIC_KEY",publicKey);
|
||||
} catch (Exception e) {
|
||||
return R.fail("生成RSA秘钥失败,"+e.getMessage());
|
||||
}
|
||||
return R.ok(map);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.ruoyi.web.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录租户对象
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
public class LoginTenantVo {
|
||||
|
||||
/**
|
||||
* 租户开关
|
||||
*/
|
||||
private Boolean tenantEnabled;
|
||||
|
||||
/**
|
||||
* 租户对象列表
|
||||
*/
|
||||
private List<TenantListVo> voList;
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.ruoyi.web.domain.vo;
|
||||
|
||||
import com.ruoyi.system.domain.vo.SysTenantVo;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 租户列表
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@AutoMapper(target = SysTenantVo.class)
|
||||
public class TenantListVo {
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 企业名称
|
||||
*/
|
||||
private String companyName;
|
||||
|
||||
/**
|
||||
* 域名
|
||||
*/
|
||||
private String domain;
|
||||
|
||||
}
|
@ -1,26 +1,30 @@
|
||||
package com.ruoyi.common.security.listener;
|
||||
package com.ruoyi.web.listener;
|
||||
|
||||
import cn.dev33.satoken.config.SaTokenConfig;
|
||||
import cn.dev33.satoken.listener.SaTokenListener;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import com.ruoyi.common.core.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.core.domain.dto.UserOnlineDTO;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.enums.UserType;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.common.core.utils.ip.AddressUtils;
|
||||
import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.core.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.core.domain.dto.UserOnlineDTO;
|
||||
import com.ruoyi.common.core.utils.MessageUtils;
|
||||
import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.utils.ip.AddressUtils;
|
||||
import com.ruoyi.common.log.event.LogininforEvent;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.common.tenant.helper.TenantHelper;
|
||||
import com.ruoyi.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* 用户行为 自定义侦听器
|
||||
* 用户行为 侦听器的实现
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@ -30,35 +34,46 @@ import java.time.Duration;
|
||||
public class UserActionListener implements SaTokenListener {
|
||||
|
||||
private final SaTokenConfig tokenConfig;
|
||||
private final SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 每次登录时触发
|
||||
*/
|
||||
@Override
|
||||
public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginModel loginModel) {
|
||||
UserType userType = UserType.getUserType(loginId.toString());
|
||||
if (userType == UserType.SYS_USER) {
|
||||
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
|
||||
String ip = ServletUtils.getClientIP();
|
||||
LoginUser user = LoginHelper.getLoginUser();
|
||||
UserOnlineDTO dto = new UserOnlineDTO();
|
||||
dto.setIpaddr(ip);
|
||||
dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
|
||||
dto.setBrowser(userAgent.getBrowser().getName());
|
||||
dto.setOs(userAgent.getOs().getName());
|
||||
dto.setLoginTime(System.currentTimeMillis());
|
||||
dto.setTokenId(tokenValue);
|
||||
dto.setUserName(user.getUsername());
|
||||
dto.setDeptName(user.getDeptName());
|
||||
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
|
||||
String ip = ServletUtils.getClientIP();
|
||||
UserOnlineDTO dto = new UserOnlineDTO();
|
||||
dto.setIpaddr(ip);
|
||||
dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
|
||||
dto.setBrowser(userAgent.getBrowser().getName());
|
||||
dto.setOs(userAgent.getOs().getName());
|
||||
dto.setLoginTime(System.currentTimeMillis());
|
||||
dto.setTokenId(tokenValue);
|
||||
String username = (String) loginModel.getExtra(LoginHelper.USER_NAME_KEY);
|
||||
Long tenantId = (Long) loginModel.getExtra(LoginHelper.TENANT_KEY);
|
||||
dto.setUserName(username);
|
||||
dto.setClientKey((String) loginModel.getExtra(LoginHelper.CLIENT_KEY));
|
||||
dto.setDeviceType(loginModel.getDevice());
|
||||
dto.setDeptName((String) loginModel.getExtra(LoginHelper.DEPT_NAME_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
if(tokenConfig.getTimeout() == -1) {
|
||||
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto);
|
||||
} else {
|
||||
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(tokenConfig.getTimeout()));
|
||||
}
|
||||
log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue);
|
||||
} else if (userType == UserType.APP_USER) {
|
||||
// app端 自行根据业务编写
|
||||
}
|
||||
});
|
||||
// 记录登录日志
|
||||
LogininforEvent logininforEvent = new LogininforEvent();
|
||||
logininforEvent.setTenantId(tenantId);
|
||||
logininforEvent.setUsername(username);
|
||||
logininforEvent.setStatus(Constants.LOGIN_SUCCESS);
|
||||
logininforEvent.setMessage(MessageUtils.message("user.login.success"));
|
||||
logininforEvent.setRequest(ServletUtils.getRequest());
|
||||
SpringUtils.context().publishEvent(logininforEvent);
|
||||
// 更新登录信息
|
||||
loginService.recordLoginInfo((Long) loginModel.getExtra(LoginHelper.USER_KEY), ip);
|
||||
log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
@ -6,6 +6,7 @@ import com.ruoyi.common.core.core.domain.model.LoginBody;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.system.domain.SysClient;
|
||||
import com.ruoyi.system.domain.vo.SysClientVo;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
|
||||
/**
|
||||
@ -19,28 +20,29 @@ public interface IAuthStrategy {
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @param body 登录对象
|
||||
* @param client 授权管理视图对象
|
||||
* @param grantType 授权类型
|
||||
* @return 登录验证信息
|
||||
*/
|
||||
static LoginVo login(LoginBody loginBody, SysClient client) {
|
||||
static LoginVo login(String body, SysClientVo client, String grantType) {
|
||||
// 授权类型和客户端id
|
||||
String clientId = loginBody.getClientId();
|
||||
String grantType = loginBody.getGrantType();
|
||||
String beanName = grantType + BASE_NAME;
|
||||
if (!SpringUtils.containsBean(beanName)) {
|
||||
throw new ServiceException("授权类型不正确!");
|
||||
}
|
||||
IAuthStrategy instance = SpringUtils.getBean(beanName);
|
||||
instance.validate(loginBody);
|
||||
return instance.login(clientId, loginBody, client);
|
||||
return instance.login(body,client);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验
|
||||
*/
|
||||
void validate(LoginBody loginBody);
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @param body 登录对象
|
||||
* @param client 授权管理视图对象
|
||||
* @return 登录验证信息
|
||||
*/
|
||||
LoginVo login(String clientId, LoginBody loginBody, SysClient client);
|
||||
LoginVo login(String body, SysClientVo client);
|
||||
|
||||
}
|
||||
|
@ -3,33 +3,37 @@ package com.ruoyi.web.service;
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.core.constant.*;
|
||||
import com.ruoyi.common.core.core.domain.dto.RoleDTO;
|
||||
import com.ruoyi.common.core.enums.LoginType;
|
||||
import com.ruoyi.common.core.enums.TenantStatus;
|
||||
import com.ruoyi.common.core.exception.user.*;
|
||||
import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.log.event.LogininforEvent;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.common.tenant.exception.TenantException;
|
||||
import com.ruoyi.common.tenant.helper.TenantHelper;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.bo.SysSocialBo;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.service.ISysPermissionService;
|
||||
import com.ruoyi.system.domain.vo.*;
|
||||
import com.ruoyi.system.service.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.MessageUtils;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -37,6 +41,7 @@ import java.util.function.Supplier;
|
||||
* 登录校验方法
|
||||
*
|
||||
* @author ruoyi
|
||||
* @author 数据小王子
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@ -49,11 +54,75 @@ public class SysLoginService {
|
||||
@Value("${user.password.lockTime}")
|
||||
private Integer lockTime;
|
||||
|
||||
private final ISysPermissionService permissionService;
|
||||
@Resource
|
||||
private ISysPermissionService permissionService;
|
||||
|
||||
@Resource
|
||||
private ISysSocialService sysSocialService;
|
||||
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
@Resource
|
||||
private ISysDeptService deptService;
|
||||
|
||||
@Resource
|
||||
private ISysRoleService roleService;
|
||||
|
||||
@Resource
|
||||
private ISysTenantService tenantService;
|
||||
|
||||
/**
|
||||
* 绑定第三方用户
|
||||
*
|
||||
* @param authUserData 授权响应实体
|
||||
* @return 统一响应实体
|
||||
*/
|
||||
public void socialRegister(AuthUser authUserData) {
|
||||
String authId = authUserData.getSource() + authUserData.getUuid();
|
||||
// 第三方用户信息
|
||||
SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class);
|
||||
BeanUtil.copyProperties(authUserData.getToken(), bo);
|
||||
bo.setUserId(LoginHelper.getUserId());
|
||||
bo.setAuthId(authId);
|
||||
bo.setOpenId(authUserData.getUuid());
|
||||
bo.setUserName(authUserData.getUsername());
|
||||
bo.setNickName(authUserData.getNickname());
|
||||
// 查询是否已经绑定用户
|
||||
List<SysSocialVo> list = sysSocialService.selectListByAuthId(authId);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
// 没有绑定用户, 新增用户信息
|
||||
sysSocialService.insertByBo(bo);
|
||||
} else {
|
||||
// 更新用户信息
|
||||
bo.setSocialId(list.get(0).getSocialId());
|
||||
sysSocialService.updateByBo(bo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public void logout() {
|
||||
try {
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (ObjectUtil.isNull(loginUser)) {
|
||||
return;
|
||||
}
|
||||
if (LoginHelper.isSuperAdmin()) {
|
||||
// 超级管理员 登出清除动态租户
|
||||
TenantHelper.clearDynamic();
|
||||
}
|
||||
recordLogininfor(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, MessageUtils.message("user.logout.success"));
|
||||
} catch (NotLoginException ignored) {
|
||||
} finally {
|
||||
try {
|
||||
StpUtil.logout();
|
||||
} catch (NotLoginException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录校验
|
||||
*/
|
||||
@ -91,17 +160,28 @@ public class SysLoginService {
|
||||
/**
|
||||
* 校验租户
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param tenantId 租户编号
|
||||
*/
|
||||
public void checkTenant(String tenantId) {
|
||||
if (!TenantHelper.isEnable()) {
|
||||
return;
|
||||
}
|
||||
public void checkTenant(Long tenantId) {
|
||||
if (TenantConstants.DEFAULT_TENANT_ID.equals(tenantId)) {
|
||||
return;
|
||||
}
|
||||
if (ObjectUtil.isNull(tenantId)) {
|
||||
throw new TenantException("tenant.number.not.blank");
|
||||
}
|
||||
SysTenantVo tenant = tenantService.selectById(tenantId);
|
||||
|
||||
//TODO:完善heckTenant功能
|
||||
if (ObjectUtil.isNull(tenant)) {
|
||||
log.info("登录租户:{} 不存在.", tenantId);
|
||||
throw new TenantException("tenant.not.exists");
|
||||
} else if (TenantStatus.DISABLE.getCode().equals(tenant.getStatus())) {
|
||||
log.info("登录租户:{} 已被停用.", tenantId);
|
||||
throw new TenantException("tenant.blocked");
|
||||
} else if (ObjectUtil.isNotNull(tenant.getExpireTime())
|
||||
&& new Date().after(tenant.getExpireTime())) {
|
||||
log.info("登录租户:{} 已超过有效期.", tenantId);
|
||||
throw new TenantException("tenant.expired");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,13 +207,15 @@ public class SysLoginService {
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param version 乐观锁
|
||||
*/
|
||||
public void recordLoginInfo(Long userId) {
|
||||
public void recordLoginInfo(Long userId,Integer version) {
|
||||
SysUserBo sysUser = new SysUserBo();
|
||||
sysUser.setUserId(userId);
|
||||
sysUser.setLoginIp(ServletUtils.getClientIP());
|
||||
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||
sysUser.setUpdateBy(userId);
|
||||
sysUser.setVersion(version);
|
||||
userService.updateUserProfile(sysUser);
|
||||
}
|
||||
|
||||
@ -156,22 +238,24 @@ public class SysLoginService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
public void logout() {
|
||||
try {
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) {
|
||||
// 超级管理员 登出清除动态租户
|
||||
TenantHelper.clearDynamic();
|
||||
}
|
||||
recordLogininfor(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, MessageUtils.message("user.logout.success"));
|
||||
} catch (NotLoginException ignored) {
|
||||
} finally {
|
||||
try {
|
||||
StpUtil.logout();
|
||||
} catch (NotLoginException ignored) {
|
||||
}
|
||||
public void recordLoginInfo(Long userId, String ip) {
|
||||
SysUserVo sysUserVo = userService.selectUserById(userId);
|
||||
if (ObjectUtil.isNull(sysUserVo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserId(userId);
|
||||
sysUser.setLoginIp(ip);
|
||||
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||
sysUser.setUpdateBy(userId);
|
||||
sysUser.setVersion(sysUserVo.getVersion());
|
||||
userService.updateById(sysUser);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.log.event.LogininforEvent;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.tenant.helper.TenantHelper;
|
||||
import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
@ -30,8 +31,7 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysRegisterService
|
||||
{
|
||||
public class SysRegisterService {
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
@ -43,33 +43,36 @@ public class SysRegisterService
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public void register(RegisterBody registerBody)
|
||||
{
|
||||
public void register(RegisterBody registerBody) {
|
||||
Long tenantId = registerBody.getTenantId();
|
||||
String username = registerBody.getUsername();
|
||||
String password = registerBody.getPassword();
|
||||
// 校验用户类型是否存在
|
||||
String userType = UserType.getUserType(registerBody.getUserType()).getUserType();
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
String username = registerBody.getUsername();
|
||||
String password = registerBody.getPassword();
|
||||
// 校验用户类型是否存在
|
||||
String userType = UserType.getUserType(registerBody.getUserType()).getUserType();
|
||||
|
||||
boolean captchaEnabled = captchaProperties.getEnable();
|
||||
// 验证码开关
|
||||
if (captchaEnabled) {
|
||||
validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid());
|
||||
}
|
||||
SysUserBo sysUser = new SysUserBo();
|
||||
sysUser.setUserName(username);
|
||||
sysUser.setNickName(username);
|
||||
sysUser.setPassword(BCrypt.hashpw(password));
|
||||
sysUser.setUserType(userType);
|
||||
boolean captchaEnabled = captchaProperties.getEnable();
|
||||
// 验证码开关
|
||||
if (captchaEnabled) {
|
||||
validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid());
|
||||
}
|
||||
SysUserBo sysUser = new SysUserBo();
|
||||
sysUser.setUserName(username);
|
||||
sysUser.setNickName(username);
|
||||
sysUser.setPassword(BCrypt.hashpw(password));
|
||||
sysUser.setUserType(userType);
|
||||
|
||||
if (!userService.checkUserNameUnique(sysUser)) {
|
||||
throw new UserException("user.register.save.error", username);
|
||||
}
|
||||
boolean regFlag = userService.registerUser(sysUser, tenantId);
|
||||
if (!regFlag) {
|
||||
throw new UserException("user.register.error");
|
||||
}
|
||||
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
|
||||
boolean unique = userService.checkUserNameUnique(sysUser);
|
||||
|
||||
if (!unique) {
|
||||
throw new UserException("user.register.save.error", username);
|
||||
}
|
||||
boolean regFlag = userService.registerUser(sysUser, tenantId);
|
||||
if (!regFlag) {
|
||||
throw new UserException("user.register.error");
|
||||
}
|
||||
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +84,7 @@ public class SysRegisterService
|
||||
* @param uuid 唯一标识
|
||||
*/
|
||||
public void validateCaptcha(Long tenantId, String username, String code, String uuid) {
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, "");
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.blankToDefault(uuid, "");
|
||||
String captcha = RedisUtils.getCacheObject(verifyKey);
|
||||
RedisUtils.deleteObject(verifyKey);
|
||||
if (captcha == null) {
|
||||
|
@ -3,7 +3,9 @@ package com.ruoyi.web.service.impl;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.core.domain.model.EmailLoginBody;
|
||||
import com.ruoyi.common.json.utils.JsonUtils;
|
||||
import com.ruoyi.system.domain.vo.SysClientVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
@ -12,7 +14,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.constant.GlobalConstants;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginBody;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.enums.LoginType;
|
||||
import com.ruoyi.common.core.enums.UserStatus;
|
||||
@ -21,12 +22,8 @@ import com.ruoyi.common.core.exception.user.UserException;
|
||||
import com.ruoyi.common.core.utils.MessageUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.ValidatorUtils;
|
||||
import com.ruoyi.common.core.validate.auth.EmailGroup;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.SysClient;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.web.service.IAuthStrategy;
|
||||
import com.ruoyi.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -43,18 +40,13 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
|
||||
@Resource
|
||||
private final SysLoginService loginService;
|
||||
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
// private final SysUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public void validate(LoginBody loginBody) {
|
||||
ValidatorUtils.validate(loginBody, EmailGroup.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginVo login(String clientId, LoginBody loginBody, SysClient client) {
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
EmailLoginBody loginBody = JsonUtils.parseObject(body, EmailLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
Long tenantId = loginBody.getTenantId();
|
||||
String email = loginBody.getEmail();
|
||||
String emailCode = loginBody.getEmailCode();
|
||||
@ -65,25 +57,23 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
loginService.checkLogin(LoginType.EMAIL, tenantId, user.getUserName(), () -> !validateEmailCode(tenantId, email, emailCode));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
LoginUser loginUser = loginService.buildLoginUser(user);
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, clientId);
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
loginService.recordLogininfor(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
loginService.recordLoginInfo(user.getUserId());
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(clientId);
|
||||
loginVo.setClientId(client.getClientId());
|
||||
return loginVo;
|
||||
// return StpUtil.getTokenValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,11 +89,7 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByEmail(Long tenantId, String email) {
|
||||
// SysUser user = userMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||
// .select(SysUser::getEmail, SysUser::getStatus)
|
||||
// .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId)
|
||||
// .eq(SysUser::getEmail, email));
|
||||
SysUserVo user =userService.selectUserByEmail(email);
|
||||
SysUserVo user = userService.selectTenantUserByEmail(tenantId, email);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", email);
|
||||
throw new UserException("user.not.exists", email);
|
||||
@ -111,10 +97,8 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
log.info("登录用户:{} 已被停用.", email);
|
||||
throw new UserException("user.blocked", email);
|
||||
}
|
||||
// if (TenantHelper.isEnable()) {
|
||||
// return userMapper.selectTenantUserByEmail(email, tenantId);
|
||||
// }
|
||||
return user;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,14 +4,15 @@ import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.core.domain.model.PasswordLoginBody;
|
||||
import com.ruoyi.common.json.utils.JsonUtils;
|
||||
import com.ruoyi.system.domain.vo.SysClientVo;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.constant.GlobalConstants;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginBody;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.enums.LoginType;
|
||||
import com.ruoyi.common.core.enums.UserStatus;
|
||||
@ -21,14 +22,10 @@ import com.ruoyi.common.core.exception.user.UserException;
|
||||
import com.ruoyi.common.core.utils.MessageUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.ValidatorUtils;
|
||||
import com.ruoyi.common.core.validate.auth.PasswordGroup;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
||||
import com.ruoyi.system.domain.SysClient;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import com.ruoyi.web.service.IAuthStrategy;
|
||||
import com.ruoyi.web.service.SysLoginService;
|
||||
@ -45,18 +42,15 @@ import org.springframework.stereotype.Service;
|
||||
public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final SysLoginService loginService;
|
||||
|
||||
@Resource
|
||||
private SysLoginService loginService;
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
@Override
|
||||
public void validate(LoginBody loginBody) {
|
||||
ValidatorUtils.validate(loginBody, PasswordGroup.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginVo login(String clientId, LoginBody loginBody, SysClient client) {
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
Long tenantId = loginBody.getTenantId();
|
||||
String username = loginBody.getUsername();
|
||||
String password = loginBody.getPassword();
|
||||
@ -73,27 +67,24 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword()));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser
|
||||
LoginUser loginUser = loginService.buildLoginUser(user);
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, clientId);
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
loginService.recordLogininfor(loginUser.getTenantId(), username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
loginService.recordLoginInfo(user.getUserId());
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(clientId);
|
||||
loginVo.setClientId(client.getClientId());
|
||||
|
||||
return loginVo;
|
||||
|
||||
//return StpUtil.getTokenValue();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,19 +109,15 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByUsername(Long tenantId, String username) {
|
||||
//TODO:以后根据tenantId条件过滤查询:
|
||||
SysUserVo user = userService.selectUserByUserName(username);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", username);
|
||||
throw new UserException("user.not.exists", username);
|
||||
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", username);
|
||||
throw new UserException("user.blocked", username);
|
||||
}
|
||||
// if (TenantHelper.isEnable()) {
|
||||
// return userMapper.selectTenantUserByUserName(username, tenantId);
|
||||
// }
|
||||
return user;
|
||||
SysUserVo user = userService.selectTenantUserByUserName(tenantId,username);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", username);
|
||||
throw new UserException("user.not.exists", username);
|
||||
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", username);
|
||||
throw new UserException("user.blocked", username);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,103 @@
|
||||
package com.ruoyi.web.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.core.domain.model.SmsLoginBody;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.constant.GlobalConstants;
|
||||
import com.ruoyi.common.core.enums.LoginType;
|
||||
import com.ruoyi.common.core.enums.UserStatus;
|
||||
import com.ruoyi.common.core.exception.user.CaptchaExpireException;
|
||||
import com.ruoyi.common.core.exception.user.UserException;
|
||||
import com.ruoyi.common.core.utils.MessageUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.ValidatorUtils;
|
||||
import com.ruoyi.common.json.utils.JsonUtils;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.vo.SysClientVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import com.ruoyi.web.service.IAuthStrategy;
|
||||
import com.ruoyi.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 短信认证策略
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("sms" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class SmsAuthStrategy implements IAuthStrategy {
|
||||
|
||||
@Resource
|
||||
private SysLoginService loginService;
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
Long tenantId = loginBody.getTenantId();
|
||||
String phonenumber = loginBody.getPhonenumber();
|
||||
String smsCode = loginBody.getSmsCode();
|
||||
|
||||
// 通过手机号查找用户
|
||||
SysUserVo user = loadUserByPhonenumber(tenantId, phonenumber);
|
||||
|
||||
loginService.checkLogin(LoginType.SMS, tenantId, user.getUserName(), () -> !validateSmsCode(tenantId, phonenumber, smsCode));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
LoginUser loginUser = loginService.buildLoginUser(user);
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验短信验证码
|
||||
*/
|
||||
private boolean validateSmsCode(Long tenantId, String phonenumber, String smsCode) {
|
||||
String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + phonenumber);
|
||||
if (StringUtils.isBlank(code)) {
|
||||
loginService.recordLogininfor(tenantId, phonenumber, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"));
|
||||
throw new CaptchaExpireException();
|
||||
}
|
||||
return code.equals(smsCode);
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByPhonenumber(Long tenantId, String phonenumber) {
|
||||
SysUserVo user = userService.selectTenantUserByPhonenumber(tenantId, phonenumber);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", phonenumber);
|
||||
throw new UserException("user.not.exists", phonenumber);
|
||||
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", phonenumber);
|
||||
throw new UserException("user.blocked", phonenumber);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package com.ruoyi.web.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.core.domain.model.SocialLoginBody;
|
||||
import com.ruoyi.common.core.enums.UserStatus;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.exception.user.UserException;
|
||||
import com.ruoyi.common.core.utils.ValidatorUtils;
|
||||
import com.ruoyi.common.json.utils.JsonUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.common.social.config.properties.SocialProperties;
|
||||
import com.ruoyi.common.social.utils.SocialUtils;
|
||||
import com.ruoyi.system.domain.vo.SysClientVo;
|
||||
import com.ruoyi.system.domain.vo.SysSocialVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.service.ISysSocialService;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import com.ruoyi.web.service.IAuthStrategy;
|
||||
import com.ruoyi.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 第三方授权策略
|
||||
*
|
||||
* @author thiszhc is 三三
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("social" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class SocialAuthStrategy implements IAuthStrategy {
|
||||
|
||||
private final SocialProperties socialProperties;
|
||||
@Resource
|
||||
private ISysSocialService sysSocialService;
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
@Resource
|
||||
private SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 登录-第三方授权登录
|
||||
*
|
||||
* @param body 登录信息
|
||||
* @param client 客户端信息
|
||||
*/
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
SocialLoginBody loginBody = JsonUtils.parseObject(body, SocialLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
|
||||
loginBody.getSource(), loginBody.getSocialCode(),
|
||||
loginBody.getSocialState(), socialProperties);
|
||||
if (!response.ok()) {
|
||||
throw new ServiceException(response.getMsg());
|
||||
}
|
||||
AuthUser authUserData = response.getData();
|
||||
|
||||
List<SysSocialVo> list = sysSocialService.selectListByAuthId(authUserData.getSource() + authUserData.getUuid());
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
throw new ServiceException("你还没有绑定第三方账号,绑定后才可以登录!");
|
||||
}
|
||||
Optional<SysSocialVo> opt = list.stream().filter(x -> x.getTenantId().equals(loginBody.getTenantId())).findAny();
|
||||
if (opt.isEmpty()) {
|
||||
throw new ServiceException("对不起,你没有权限登录当前租户!");
|
||||
}
|
||||
SysSocialVo social = opt.get();
|
||||
|
||||
// 查找用户
|
||||
SysUserVo user = loadUser(social.getTenantId(), social.getUserId());
|
||||
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
LoginUser loginUser = loginService.buildLoginUser(user);
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
private SysUserVo loadUser(Long tenantId, Long userId) {
|
||||
SysUserVo user = userService.selectTenantUserById(tenantId, userId);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", "");
|
||||
throw new UserException("user.not.exists", "");
|
||||
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", "");
|
||||
throw new UserException("user.blocked", "");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.ruoyi.web.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.core.core.domain.model.XcxLoginBody;
|
||||
import com.ruoyi.common.core.core.domain.model.XcxLoginUser;
|
||||
import com.ruoyi.common.core.enums.UserStatus;
|
||||
import com.ruoyi.common.core.utils.ValidatorUtils;
|
||||
import com.ruoyi.common.json.utils.JsonUtils;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.vo.SysClientVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import com.ruoyi.web.service.IAuthStrategy;
|
||||
import com.ruoyi.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 小程序认证策略
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("xcx" + IAuthStrategy.BASE_NAME)
|
||||
@RequiredArgsConstructor
|
||||
public class XcxAuthStrategy implements IAuthStrategy {
|
||||
|
||||
@Resource
|
||||
private SysLoginService loginService;
|
||||
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
XcxLoginBody loginBody = JsonUtils.parseObject(body, XcxLoginBody.class);
|
||||
ValidatorUtils.validate(loginBody);
|
||||
// xcxCode 为 小程序调用 wx.login 授权后获取
|
||||
String xcxCode = loginBody.getXcxCode();
|
||||
// 多个小程序识别使用
|
||||
String appid = loginBody.getAppid();
|
||||
|
||||
// todo 以下自行实现
|
||||
// 校验 appid + appsrcret + xcxCode 调用登录凭证校验接口 获取 session_key 与 openid
|
||||
String openid = "";
|
||||
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||
SysUserVo user = loadUserByOpenid(openid);
|
||||
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
XcxLoginUser loginUser = new XcxLoginUser();
|
||||
loginUser.setTenantId(user.getTenantId());
|
||||
loginUser.setUserId(user.getUserId());
|
||||
loginUser.setUsername(user.getUserName());
|
||||
loginUser.setNickname(user.getNickName());
|
||||
loginUser.setUserType(user.getUserType());
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
loginUser.setOpenid(openid);
|
||||
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(client.getClientId());
|
||||
loginVo.setOpenid(openid);
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByOpenid(String openid) {
|
||||
// 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户
|
||||
// todo 自行实现 userService.selectUserByOpenid(openid);
|
||||
SysUserVo user = new SysUserVo();
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", openid);
|
||||
// todo 用户不存在 业务逻辑自行实现
|
||||
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", openid);
|
||||
// todo 用户已被停用 业务逻辑自行实现
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
@ -1,110 +1,43 @@
|
||||
# 数据源及mybatis、mybatis-flex配置
|
||||
--- # 数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
# 最大连接池数量
|
||||
maximum-pool-size: 20
|
||||
# 最小空闲线程数量
|
||||
minimum-idle: 10
|
||||
# 配置获取连接等待超时的时间
|
||||
connectionTimeout: 30000
|
||||
# 校验超时时间
|
||||
validationTimeout: 5000
|
||||
# 空闲连接存活最大时间,默认10分钟
|
||||
idleTimeout: 600000
|
||||
# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认30分钟
|
||||
maxLifetime: 1800000
|
||||
# 多久检查一次连接的活性
|
||||
keepaliveTime: 30000
|
||||
mybatis-flex:
|
||||
# 搜索指定包别名
|
||||
typeAliasesPackage: com.ruoyi.**.domain
|
||||
# 不支持多包, 如有需要可在注解配置 或 提升扫包等级:com.**.**.mapper
|
||||
mapperPackage: com.ruoyi.**.mapper
|
||||
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||
|
||||
#本部分(Configuration)的配置都为 MyBatis 原生支持的配置,有关配置请参考:https://mybatis.org/mybatis-3/zh/configuration.html#%E8%AE%BE%E7%BD%AE%EF%BC%88settings%EF%BC%89
|
||||
configuration:
|
||||
# 自动驼峰命名规则(camel case)映射
|
||||
mapUnderscoreToCamelCase: true
|
||||
# MyBatis 自动映射策略
|
||||
# NONE:不启用 PARTIAL:只对非嵌套 resultMap 自动映射 FULL:对所有 resultMap 自动映射
|
||||
autoMappingBehavior: FULL
|
||||
# MyBatis 自动映射时未知列或未知属性处理策
|
||||
# NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息
|
||||
autoMappingUnknownColumnBehavior: NONE
|
||||
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 关闭日志记录 org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
cacheEnabled: true
|
||||
|
||||
# MyBatis-Flex全局配置
|
||||
global-config:
|
||||
# 是否控制台打印 MyBatis-Flex 的 LOGO 及版本号
|
||||
print-banner: true
|
||||
# 逻辑删除数据存在标记值
|
||||
normal-value-of-logic-delete: 0
|
||||
# 逻辑删除数据存在标记值
|
||||
deleted-value-of-logic-delete: 1
|
||||
|
||||
# sql审计
|
||||
audit_enable: true
|
||||
# sql打印
|
||||
sql_print: true
|
||||
datasource:
|
||||
# 数据源-1
|
||||
ds1:
|
||||
# 指定为HikariDataSource
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
|
||||
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
|
||||
type: ${spring.datasource.type}
|
||||
# mysql数据库
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/ruoyi-flex?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
|
||||
# username: root
|
||||
# password: Root@369
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/ruoyi-flex?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: Root@369
|
||||
#postgresql数据库
|
||||
driver-class-name: org.postgresql.Driver
|
||||
url: jdbc:postgresql://localhost:5432/ruoyi-flex?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
username: postgres
|
||||
password: postgres@369
|
||||
|
||||
hikari:
|
||||
#连接池名
|
||||
pool-name: HikariCP-ds1
|
||||
#最小空闲连接数
|
||||
minimum-idle: 5
|
||||
# 空闲连接存活最大时间,默认10分钟
|
||||
idle-timeout: 600000
|
||||
# 连接池最大连接数,默认是10
|
||||
maximum-pool-size: 10
|
||||
# 此属性控制从池返回的连接的默认自动提交行为,默认值:true
|
||||
auto-commit: true
|
||||
# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认30分钟
|
||||
max-lifetime: 1800000
|
||||
# 数据库连接超时时间,默认30秒
|
||||
connection-timeout: 30000
|
||||
# 校验超时时间
|
||||
validationTimeout: 5000
|
||||
# 多久检查一次连接的活性
|
||||
keepaliveTime: 30000
|
||||
# 连接测试query
|
||||
connection-test-query: SELECT 1
|
||||
# 数据源-2
|
||||
# ds2:
|
||||
# # 指定为HikariDataSource
|
||||
# type: com.zaxxer.hikari.HikariDataSource
|
||||
# # mysql数据库
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/ruoyi-flex?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
|
||||
# username: root
|
||||
# password: Root@369
|
||||
# #postgresql数据库
|
||||
## driver-class-name: org.postgresql.Driver
|
||||
## url: jdbc:postgresql://localhost:5432/ruoyi-flex?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
## username: postgres
|
||||
## password: postgres@369
|
||||
#
|
||||
# hikari:
|
||||
# #连接池名
|
||||
# pool-name: HikariCP-ds1
|
||||
# #最小空闲连接数
|
||||
# minimum-idle: 5
|
||||
# # 空闲连接存活最大时间,默认10分钟
|
||||
# idle-timeout: 600000
|
||||
# # 连接池最大连接数,默认是10
|
||||
# maximum-pool-size: 10
|
||||
# # 此属性控制从池返回的连接的默认自动提交行为,默认值:true
|
||||
# auto-commit: true
|
||||
# # 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认30分钟
|
||||
# max-lifetime: 1800000
|
||||
# # 数据库连接超时时间,默认30秒
|
||||
# connection-timeout: 30000
|
||||
# # 校验超时时间
|
||||
# validationTimeout: 5000
|
||||
# # 多久检查一次连接的活性
|
||||
# keepaliveTime: 30000
|
||||
# # 连接测试query
|
||||
# connection-test-query: SELECT 1
|
||||
# driver-class-name: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/ruoyi-flex?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: postgres
|
||||
# password: postgres@369
|
||||
|
||||
# redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||
spring.data:
|
||||
@ -144,22 +77,10 @@ redisson:
|
||||
# 发布和订阅连接池大小
|
||||
subscriptionConnectionPoolSize: 50
|
||||
|
||||
--- # Actuator 监控端点的配置项
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: '*'
|
||||
endpoint:
|
||||
health:
|
||||
show-details: ALWAYS
|
||||
logfile:
|
||||
external-file: ./logs/ruoyi-monitor.log
|
||||
|
||||
--- # 监控中心客户端配置
|
||||
spring.boot.admin.client:
|
||||
# 增加客户端开关
|
||||
enabled: true
|
||||
enabled: false
|
||||
url: http://localhost:9090/admin
|
||||
instance:
|
||||
service-host-type: IP
|
||||
@ -170,7 +91,7 @@ spring.boot.admin.client:
|
||||
powerjob:
|
||||
worker:
|
||||
# 如何开启调度中心请查看文档教程
|
||||
enabled: true
|
||||
enabled: false
|
||||
# 需要先在 powerjob 登录页执行应用注册后才能使用
|
||||
app-name: ruoyi-worker
|
||||
# 28080 端口 随着主应用端口飘逸 避免集群冲突
|
||||
@ -178,8 +99,149 @@ powerjob:
|
||||
protocol: http
|
||||
server-address: 127.0.0.1:7700
|
||||
store-strategy: disk
|
||||
enable-test-mode: false
|
||||
allow-lazy-connect-server: false
|
||||
max-appended-wf-context-length: 4096
|
||||
max-result-length: 4096
|
||||
|
||||
--- # easy-retry 配置
|
||||
easy-retry:
|
||||
enabled: false
|
||||
# 需要在EasyRetry后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
|
||||
group-name: "ruoyi_group"
|
||||
# EasyRetry接入验证令牌 详见 script/sql/easy_retry.sql `er_group_config` 表
|
||||
token: "ER_cKqBTPzCsWA3VyuCfFoccmuIEGXjr5KT"
|
||||
server:
|
||||
host: 127.0.0.1
|
||||
port: 1788
|
||||
# 详见 script/sql/easy_retry.sql `er_namespace` 表
|
||||
namespace: ${spring.profiles.active}
|
||||
|
||||
--- # mail 邮件发送
|
||||
mail:
|
||||
enabled: false
|
||||
host: smtp.163.com
|
||||
port: 465
|
||||
# 是否需要用户名密码验证
|
||||
auth: true
|
||||
# 发送方,遵循RFC-822标准
|
||||
from: xxx@163.com
|
||||
# 用户名(注意:如果使用foxmail邮箱,此处user为qq号)
|
||||
user: xxx@163.com
|
||||
# 密码(注意,某些邮箱需要为SMTP服务单独设置密码,详情查看相关帮助)
|
||||
pass: xxxxxxxxxx
|
||||
# 使用 STARTTLS安全连接,STARTTLS是对纯文本通信协议的扩展。
|
||||
starttlsEnable: true
|
||||
# 使用SSL安全连接
|
||||
sslEnable: true
|
||||
# SMTP超时时长,单位毫秒,缺省值不超时
|
||||
timeout: 0
|
||||
# Socket连接超时值,单位毫秒,缺省值不超时
|
||||
connectionTimeout: 0
|
||||
|
||||
--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
|
||||
# https://sms4j.com/doc3/ 差异配置文档地址 支持单厂商多配置,可以配置多个同时使用
|
||||
sms:
|
||||
# 配置源类型用于标定配置来源(interface,yaml)
|
||||
config-type: yaml
|
||||
# 用于标定yml中的配置是否开启短信拦截,接口配置不受此限制
|
||||
restricted: true
|
||||
# 短信拦截限制单手机号每分钟最大发送,只对开启了拦截的配置有效
|
||||
minute-max: 1
|
||||
# 短信拦截限制单手机号每日最大发送量,只对开启了拦截的配置有效
|
||||
account-max: 30
|
||||
# 以下配置来自于 org.dromara.sms4j.provider.config.BaseConfig类中
|
||||
blends:
|
||||
# 唯一ID 用于发送短信寻找具体配置 随便定义别用中文即可
|
||||
# 可以同时存在两个相同厂商 例如: ali1 ali2 两个不同的阿里短信账号 也可用于区分租户
|
||||
config1:
|
||||
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: alibaba
|
||||
# 有些称为accessKey有些称之为apiKey,也有称为sdkKey或者appId。
|
||||
access-key-id: 您的accessKey
|
||||
# 称为accessSecret有些称之为apiSecret
|
||||
access-key-secret: 您的accessKeySecret
|
||||
signature: 您的短信签名
|
||||
sdk-app-id: 您的sdkAppId
|
||||
config2:
|
||||
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: tencent
|
||||
access-key-id: 您的accessKey
|
||||
access-key-secret: 您的accessKeySecret
|
||||
signature: 您的短信签名
|
||||
sdk-app-id: 您的sdkAppId
|
||||
|
||||
--- # 三方授权
|
||||
justauth:
|
||||
# 前端外网访问地址
|
||||
address: http://localhost:80
|
||||
type:
|
||||
maxkey:
|
||||
# maxkey 服务器地址
|
||||
# 注意 如下均配置均不需要修改 maxkey 已经内置好了数据
|
||||
server-url: http://sso.maxkey.top
|
||||
client-id: 876892492581044224
|
||||
client-secret: x1Y5MTMwNzIwMjMxNTM4NDc3Mzche8
|
||||
redirect-uri: ${justauth.address}/social-callback?source=maxkey
|
||||
topiam:
|
||||
# topiam 服务器地址
|
||||
server-url: http://127.0.0.1:1989/api/v1/authorize/y0q************spq***********8ol
|
||||
client-id: 449c4*********937************759
|
||||
client-secret: ac7***********1e0************28d
|
||||
redirect-uri: ${justauth.address}/social-callback?source=topiam
|
||||
scopes: [openid, email, phone, profile]
|
||||
qq:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=qq
|
||||
union-id: false
|
||||
weibo:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=weibo
|
||||
gitee:
|
||||
client-id: 91436b7940090**********d67eea73acbf61b6b590751a98
|
||||
client-secret: 02c6fcfd70342980cd8**********c754d7a264c4e125f9ba915ac
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitee
|
||||
dingtalk:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=dingtalk
|
||||
baidu:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=baidu
|
||||
csdn:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=csdn
|
||||
coding:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=coding
|
||||
coding-group-name: xx
|
||||
oschina:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=oschina
|
||||
alipay_wallet:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=alipay_wallet
|
||||
alipay-public-key: MIIB**************DAQAB
|
||||
wechat_open:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=wechat_open
|
||||
wechat_mp:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=wechat_mp
|
||||
wechat_enterprise:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=wechat_enterprise
|
||||
agent-id: 1000002
|
||||
gitlab:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitlab
|
||||
|
@ -1,48 +1,33 @@
|
||||
# 临时文件存储位置 避免临时文件被系统清理报错
|
||||
spring.servlet.multipart.location: /ruoyi/server/temp
|
||||
|
||||
# 数据源及mybatis、mybatis-flex配置
|
||||
--- # 数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
# 最大连接池数量
|
||||
maximum-pool-size: 20
|
||||
# 最小空闲线程数量
|
||||
minimum-idle: 10
|
||||
# 配置获取连接等待超时的时间
|
||||
connectionTimeout: 30000
|
||||
# 校验超时时间
|
||||
validationTimeout: 5000
|
||||
# 空闲连接存活最大时间,默认10分钟
|
||||
idleTimeout: 600000
|
||||
# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认30分钟
|
||||
maxLifetime: 1800000
|
||||
# 多久检查一次连接的活性
|
||||
keepaliveTime: 30000
|
||||
mybatis-flex:
|
||||
# 搜索指定包别名
|
||||
typeAliasesPackage: com.ruoyi.**.domain
|
||||
# 不支持多包, 如有需要可在注解配置 或 提升扫包等级:com.**.**.mapper
|
||||
mapperPackage: com.ruoyi.**.mapper
|
||||
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||
cacheEnabled: true
|
||||
|
||||
#本部分(Configuration)的配置都为 MyBatis 原生支持的配置,有关配置请参考:https://mybatis.org/mybatis-3/zh/configuration.html#%E8%AE%BE%E7%BD%AE%EF%BC%88settings%EF%BC%89
|
||||
configuration:
|
||||
# 自动驼峰命名规则(camel case)映射
|
||||
mapUnderscoreToCamelCase: true
|
||||
# MyBatis 自动映射策略
|
||||
# NONE:不启用 PARTIAL:只对非嵌套 resultMap 自动映射 FULL:对所有 resultMap 自动映射
|
||||
autoMappingBehavior: FULL
|
||||
# MyBatis 自动映射时未知列或未知属性处理策
|
||||
# NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息
|
||||
autoMappingUnknownColumnBehavior: NONE
|
||||
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
cacheEnabled: true
|
||||
|
||||
|
||||
# MyBatis-Flex全局配置
|
||||
global-config:
|
||||
# 是否控制台打印 MyBatis-Flex 的 LOGO 及版本号
|
||||
print-banner: false
|
||||
# 逻辑删除数据存在标记值
|
||||
normal-value-of-logic-delete: 0
|
||||
# 逻辑删除数据存在标记值
|
||||
deleted-value-of-logic-delete: 1
|
||||
|
||||
|
||||
# sql审计
|
||||
audit_enable: false
|
||||
# sql打印
|
||||
sql_print: false
|
||||
datasource:
|
||||
# 数据源-1
|
||||
PrimaryDS:
|
||||
# 指定为HikariDataSource
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
ds1:
|
||||
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
|
||||
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
|
||||
type: ${spring.datasource.type}
|
||||
# mysql数据库
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/ruoyi-flex?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
|
||||
@ -54,28 +39,6 @@ mybatis-flex:
|
||||
# username: postgres
|
||||
# password: postgres@369
|
||||
|
||||
hikari:
|
||||
#连接池名
|
||||
pool-name: HikariCP-PrimaryDS
|
||||
#最小空闲连接数
|
||||
minimum-idle: 10
|
||||
# 空闲连接存活最大时间,默认10分钟
|
||||
idle-timeout: 600000
|
||||
# 连接池最大连接数,默认是10
|
||||
maximum-pool-size: 20
|
||||
# 此属性控制从池返回的连接的默认自动提交行为,默认值:true
|
||||
auto-commit: true
|
||||
# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认30分钟
|
||||
max-lifetime: 1800000
|
||||
# 数据库连接超时时间,默认30秒
|
||||
connection-timeout: 30000
|
||||
# 校验超时时间
|
||||
validationTimeout: 5000
|
||||
# 多久检查一次连接的活性
|
||||
keepaliveTime: 30000
|
||||
# 连接测试query
|
||||
connection-test-query: SELECT 1
|
||||
|
||||
# redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||
spring.data:
|
||||
redis:
|
||||
@ -114,19 +77,7 @@ redisson:
|
||||
# 发布和订阅连接池大小
|
||||
subscriptionConnectionPoolSize: 50
|
||||
|
||||
--- # Actuator 监控端点的配置项
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: '*'
|
||||
endpoint:
|
||||
health:
|
||||
show-details: ALWAYS
|
||||
logfile:
|
||||
external-file: ./logs/ruoyi-monitor.log
|
||||
|
||||
--- # 监控中心配置
|
||||
--- # 监控中心客户端配置
|
||||
spring.boot.admin.client:
|
||||
# 增加客户端开关
|
||||
enabled: true
|
||||
@ -143,12 +94,155 @@ powerjob:
|
||||
enabled: true
|
||||
# 需要先在 powerjob 登录页执行应用注册后才能使用
|
||||
app-name: ruoyi-worker
|
||||
enable-test-mode: false
|
||||
max-appended-wf-context-length: 4096
|
||||
max-result-length: 4096
|
||||
# 28080 端口 随着主应用端口飘逸 避免集群冲突
|
||||
port: 2${server.port}
|
||||
protocol: http
|
||||
server-address: 127.0.0.1:7700
|
||||
store-strategy: disk
|
||||
allow-lazy-connect-server: false
|
||||
max-appended-wf-context-length: 4096
|
||||
max-result-length: 4096
|
||||
|
||||
--- # easy-retry 配置
|
||||
easy-retry:
|
||||
enabled: false
|
||||
# 需要在EasyRetry后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
|
||||
group-name: "ruoyi_group"
|
||||
# EasyRetry接入验证令牌 详见 script/sql/easy_retry.sql `er_group_config` 表
|
||||
token: "ER_cKqBTPzCsWA3VyuCfFoccmuIEGXjr5KT"
|
||||
server:
|
||||
host: 127.0.0.1
|
||||
port: 1788
|
||||
# 详见 script/sql/easy_retry.sql `er_namespace` 表
|
||||
namespace: ${spring.profiles.active}
|
||||
|
||||
--- # mail 邮件发送
|
||||
mail:
|
||||
enabled: false
|
||||
host: smtp.163.com
|
||||
port: 465
|
||||
# 是否需要用户名密码验证
|
||||
auth: true
|
||||
# 发送方,遵循RFC-822标准
|
||||
from: xxx@163.com
|
||||
# 用户名(注意:如果使用foxmail邮箱,此处user为qq号)
|
||||
user: xxx@163.com
|
||||
# 密码(注意,某些邮箱需要为SMTP服务单独设置密码,详情查看相关帮助)
|
||||
pass: xxxxxxxxxx
|
||||
# 使用 STARTTLS安全连接,STARTTLS是对纯文本通信协议的扩展。
|
||||
starttlsEnable: true
|
||||
# 使用SSL安全连接
|
||||
sslEnable: true
|
||||
# SMTP超时时长,单位毫秒,缺省值不超时
|
||||
timeout: 0
|
||||
# Socket连接超时值,单位毫秒,缺省值不超时
|
||||
connectionTimeout: 0
|
||||
|
||||
--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
|
||||
# https://sms4j.com/doc3/ 差异配置文档地址 支持单厂商多配置,可以配置多个同时使用
|
||||
sms:
|
||||
# 配置源类型用于标定配置来源(interface,yaml)
|
||||
config-type: yaml
|
||||
# 用于标定yml中的配置是否开启短信拦截,接口配置不受此限制
|
||||
restricted: true
|
||||
# 短信拦截限制单手机号每分钟最大发送,只对开启了拦截的配置有效
|
||||
minute-max: 1
|
||||
# 短信拦截限制单手机号每日最大发送量,只对开启了拦截的配置有效
|
||||
account-max: 30
|
||||
# 以下配置来自于 org.dromara.sms4j.provider.config.BaseConfig类中
|
||||
blends:
|
||||
# 唯一ID 用于发送短信寻找具体配置 随便定义别用中文即可
|
||||
# 可以同时存在两个相同厂商 例如: ali1 ali2 两个不同的阿里短信账号 也可用于区分租户
|
||||
config1:
|
||||
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: alibaba
|
||||
# 有些称为accessKey有些称之为apiKey,也有称为sdkKey或者appId。
|
||||
access-key-id: 您的accessKey
|
||||
# 称为accessSecret有些称之为apiSecret
|
||||
access-key-secret: 您的accessKeySecret
|
||||
signature: 您的短信签名
|
||||
sdk-app-id: 您的sdkAppId
|
||||
config2:
|
||||
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: tencent
|
||||
access-key-id: 您的accessKey
|
||||
access-key-secret: 您的accessKeySecret
|
||||
signature: 您的短信签名
|
||||
sdk-app-id: 您的sdkAppId
|
||||
|
||||
|
||||
--- # 三方授权
|
||||
justauth:
|
||||
# 前端外网访问地址
|
||||
address: http://localhost:80
|
||||
type:
|
||||
maxkey:
|
||||
# maxkey 服务器地址
|
||||
# 注意 如下均配置均不需要修改 maxkey 已经内置好了数据
|
||||
server-url: http://sso.maxkey.top
|
||||
client-id: 876892492581044224
|
||||
client-secret: x1Y5MTMwNzIwMjMxNTM4NDc3Mzche8
|
||||
redirect-uri: ${justauth.address}/social-callback?source=maxkey
|
||||
topiam:
|
||||
# topiam 服务器地址
|
||||
server-url: http://127.0.0.1:1989/api/v1/authorize/y0q************spq***********8ol
|
||||
client-id: 449c4*********937************759
|
||||
client-secret: ac7***********1e0************28d
|
||||
redirect-uri: ${justauth.address}/social-callback?source=topiam
|
||||
scopes: [openid, email, phone, profile]
|
||||
qq:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=qq
|
||||
union-id: false
|
||||
weibo:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=weibo
|
||||
gitee:
|
||||
client-id: 91436b7940090**********d67eea73acbf61b6b590751a98
|
||||
client-secret: 02c6fcfd70342980cd8**********c754d7a264c4e125f9ba915ac
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitee
|
||||
dingtalk:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=dingtalk
|
||||
baidu:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=baidu
|
||||
csdn:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=csdn
|
||||
coding:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=coding
|
||||
coding-group-name: xx
|
||||
oschina:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=oschina
|
||||
alipay_wallet:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=alipay_wallet
|
||||
alipay-public-key: MIIB**************DAQAB
|
||||
wechat_open:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=wechat_open
|
||||
wechat_mp:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=wechat_mp
|
||||
wechat_enterprise:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=wechat_enterprise
|
||||
agent-id: 1000002
|
||||
gitlab:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitlab
|
||||
|
@ -3,13 +3,13 @@ ruoyi:
|
||||
# 名称
|
||||
name: Ruoyi-Flex
|
||||
# 版本
|
||||
version: 4.2.0
|
||||
version: ${revision}
|
||||
# 版权年份
|
||||
copyrightYear: 2023
|
||||
copyrightYear: 2023 ~ 2024
|
||||
# 实例演示开关
|
||||
demoEnabled: true
|
||||
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
|
||||
profile: D:/ruoyi/uploadPath
|
||||
profile: /home/ruoyi/uploadPath
|
||||
# 获取ip地址开关
|
||||
addressEnabled: false
|
||||
|
||||
@ -33,27 +33,35 @@ server:
|
||||
# 应用的访问路径
|
||||
context-path: /
|
||||
|
||||
# tomcat web容器配置
|
||||
tomcat:
|
||||
# tomcat的URI编码
|
||||
uri-encoding: UTF-8
|
||||
# 连接数满后的排队数,默认为100
|
||||
accept-count: 1000
|
||||
|
||||
# undertow web容器配置
|
||||
undertow:
|
||||
# HTTP post内容的最大大小。当值为-1时,默认值为大小是无限的
|
||||
max-http-post-size: -1
|
||||
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
|
||||
# 每块buffer的空间大小,越小的空间被利用越充分
|
||||
buffer-size: 512
|
||||
# 是否分配的直接内存
|
||||
direct-buffers: true
|
||||
threads:
|
||||
# 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
|
||||
io: 8
|
||||
# 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
|
||||
worker: 256
|
||||
# undertow:
|
||||
# # HTTP post内容的最大大小。当值为-1时,默认值为大小是无限的
|
||||
# max-http-post-size: -1
|
||||
# # 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
|
||||
# # 每块buffer的空间大小,越小的空间被利用越充分
|
||||
# buffer-size: 512
|
||||
# # 是否分配的直接内存
|
||||
# direct-buffers: true
|
||||
# threads:
|
||||
# # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
|
||||
# io: 8
|
||||
# # 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
|
||||
# worker: 256
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
com.ruoyi: debug
|
||||
com.ruoyi: @logging.level@
|
||||
org.springframework: warn
|
||||
tech.powerjob.worker.background: warn
|
||||
org.mybatis.spring.mapper: error
|
||||
config: classpath:logback.xml
|
||||
|
||||
# 用户配置
|
||||
@ -68,6 +76,10 @@ user:
|
||||
spring:
|
||||
application:
|
||||
name: ${ruoyi.name}
|
||||
threads:
|
||||
# 启用JAVA21虚拟线程
|
||||
virtual:
|
||||
enabled: true
|
||||
# 资源信息
|
||||
messages:
|
||||
# 国际化资源文件路径
|
||||
@ -101,30 +113,90 @@ spring:
|
||||
# 热部署开关
|
||||
enabled: true
|
||||
|
||||
# token配置
|
||||
token:
|
||||
# 令牌自定义标识
|
||||
header: Authorization
|
||||
# 令牌密钥
|
||||
secret: abcdefghijklmnopqrstuvwxyz
|
||||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 30
|
||||
|
||||
# PageHelper分页插件
|
||||
pagehelper:
|
||||
helperDialect: mysql
|
||||
#helperDialect: mysql、postgresql pagehelper分页插件会自动检测当前的数据库链接,自动选择合适的分页方式。
|
||||
supportMethodsArguments: true
|
||||
params: count=countSql
|
||||
|
||||
# MyBatisFlex公共配置
|
||||
# https://mybatis-flex.com/zh/base/configuration.html
|
||||
mybatis-flex:
|
||||
# 搜索指定包别名
|
||||
type-aliases-package: com.ruoyi.**.domain
|
||||
# 多包名使用 例如 org.dromara.**.mapper,org.xxx.**.mapper
|
||||
mapper-package: com.ruoyi.**.mapper
|
||||
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||
mapper-locations: classpath*:mapper/**/*Mapper.xml
|
||||
configuration:
|
||||
## 以下为mybatis原生配置 https://mybatis.org/mybatis-3/zh/configuration.html
|
||||
# 自动驼峰命名规则(camel case)映射
|
||||
map_underscore_to_camel_case: true
|
||||
# MyBatis 自动映射策略
|
||||
# NONE:不启用 PARTIAL:只对非嵌套 resultMap 自动映射 FULL:对所有 resultMap 自动映射
|
||||
auto_mapping_behavior: FULL
|
||||
# MyBatis 自动映射时未知列或未知属性处理策
|
||||
# NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息
|
||||
auto_mapping_unknown_column_behavior: NONE
|
||||
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 关闭日志记录 org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
#log_impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
logImpl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
cacheEnabled: true
|
||||
global-config:
|
||||
# 是否控制台打印 MyBatis-Flex 的 LOGO 及版本号
|
||||
print-banner: true
|
||||
# 全局的 ID 生成策略配置:雪花算法
|
||||
key-config:
|
||||
key-type: Generator
|
||||
value: snowFlakeId
|
||||
# 逻辑未删除值
|
||||
normal-value-of-logic-delete: 0
|
||||
# 逻辑已删除值(框架表均使用此值 禁止随意修改)
|
||||
deleted-value-of-logic-delete: 1
|
||||
# 默认的逻辑删除字段
|
||||
logic-delete-column: del_flag
|
||||
# 默认的多租户字段
|
||||
tenant-column: tenant_id
|
||||
# 默认的乐观锁字段
|
||||
version-column: version
|
||||
|
||||
# 数据加密
|
||||
mybatis-encryptor:
|
||||
# 是否开启加密
|
||||
enable: false
|
||||
# 默认加密算法
|
||||
algorithm: BASE64
|
||||
# 编码方式 BASE64/HEX。默认BASE64
|
||||
encode: BASE64
|
||||
# 安全秘钥 对称算法的秘钥 如:AES,SM4
|
||||
password:
|
||||
# 公私钥 非对称算法的公私钥 如:SM2,RSA
|
||||
publicKey:
|
||||
privateKey:
|
||||
|
||||
# api接口加密
|
||||
api-decrypt:
|
||||
# 是否开启全局接口加密
|
||||
enabled: true
|
||||
# AES 加密头标识
|
||||
headerFlag: encrypt-key
|
||||
# 响应加密公钥 非对称算法的公私钥 如:SM2,RSA 使用者请自行更换
|
||||
# 对应前端解密私钥 MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAmc3CuPiGL/LcIIm7zryCEIbl1SPzBkr75E2VMtxegyZ1lYRD+7TZGAPkvIsBcaMs6Nsy0L78n2qh+lIZMpLH8wIDAQABAkEAk82Mhz0tlv6IVCyIcw/s3f0E+WLmtPFyR9/WtV3Y5aaejUkU60JpX4m5xNR2VaqOLTZAYjW8Wy0aXr3zYIhhQQIhAMfqR9oFdYw1J9SsNc+CrhugAvKTi0+BF6VoL6psWhvbAiEAxPPNTmrkmrXwdm/pQQu3UOQmc2vCZ5tiKpW10CgJi8kCIFGkL6utxw93Ncj4exE/gPLvKcT+1Emnoox+O9kRXss5AiAMtYLJDaLEzPrAWcZeeSgSIzbL+ecokmFKSDDcRske6QIgSMkHedwND1olF8vlKsJUGK3BcdtM8w4Xq7BpSBwsloE=
|
||||
publicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJnNwrj4hi/y3CCJu868ghCG5dUj8wZK++RNlTLcXoMmdZWEQ/u02RgD5LyLAXGjLOjbMtC+/J9qofpSGTKSx/MCAwEAAQ==
|
||||
# 请求解密私钥 非对称算法的公私钥 如:SM2,RSA 使用者请自行更换
|
||||
# 对应前端加密公钥 MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==
|
||||
privateKey: MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y=
|
||||
|
||||
# SpringDoc配置
|
||||
springdoc:
|
||||
#需要扫描的包,可以配置多个,使用逗号分割
|
||||
packages-to-scan: com.ruoyi
|
||||
paths-to-exclude: #配置不包含在swagger文档中的api
|
||||
- /api/test/**
|
||||
- /api/mockito/data
|
||||
swagger-ui:
|
||||
enabled: true #开启/禁止swagger,prod可以设置为false
|
||||
version: 5.11.8 #指定swagger-ui的版本号
|
||||
disable-swagger-default-url: true #禁用default petstore url
|
||||
path: /swagger-ui.html #swagger页面
|
||||
persistAuthorization: true # 持久化认证数据,如果设置为 true,它会保留授权数据并且不会在浏览器关闭/刷新时丢失
|
||||
@ -147,20 +219,24 @@ springdoc:
|
||||
email: 738981257@qq.com
|
||||
url: https://gitee.com/dataprince/ruoyi-flex
|
||||
components:
|
||||
# 鉴权方式配置
|
||||
# 鉴权方式配置
|
||||
security-schemes:
|
||||
apiKey:
|
||||
type: APIKEY
|
||||
in: HEADER
|
||||
name: ${sa-token.token-name}
|
||||
group-configs:
|
||||
- group: 1.演示模块
|
||||
packages-to-scan: com.ruoyi.demo
|
||||
- group: 2.通用模块
|
||||
- group: 1.web模块
|
||||
packages-to-scan: com.ruoyi.web
|
||||
- group: 2.演示模块
|
||||
packages-to-scan:
|
||||
- com.ruoyi.demo
|
||||
- com.ruoyi.mf
|
||||
- group: 3.通用模块
|
||||
packages-to-scan: com.ruoyi.common
|
||||
- group: 3.系统模块
|
||||
- group: 4.系统模块
|
||||
packages-to-scan: com.ruoyi.system
|
||||
- group: 4.代码生成模块
|
||||
- group: 5.代码生成模块
|
||||
packages-to-scan: com.ruoyi.generator
|
||||
|
||||
# 防止XSS攻击
|
||||
@ -172,15 +248,6 @@ xss:
|
||||
# 匹配链接
|
||||
urlPatterns: /system/*,/monitor/*,/tool/*,/demo/*
|
||||
|
||||
# 全局线程池相关配置
|
||||
thread-pool:
|
||||
# 是否开启线程池
|
||||
enabled: false
|
||||
# 队列最大长度
|
||||
queueCapacity: 128
|
||||
# 线程池维护线程所允许的空闲时间
|
||||
keepAliveSeconds: 300
|
||||
|
||||
# 分布式锁 lock4j 全局配置
|
||||
lock4j:
|
||||
# 获取分布式锁超时时间,默认为 3000 毫秒
|
||||
@ -233,21 +300,8 @@ security:
|
||||
- /captchaImage
|
||||
- /captcha/get
|
||||
- /captcha/check
|
||||
|
||||
# 多租户配置
|
||||
tenant:
|
||||
# 是否开启
|
||||
enable: false
|
||||
# 排除表
|
||||
excludes:
|
||||
- sys_menu
|
||||
- sys_tenant
|
||||
- sys_tenant_package
|
||||
- sys_role_dept
|
||||
- sys_role_menu
|
||||
- sys_user_post
|
||||
- sys_user_role
|
||||
- sys_client
|
||||
- /genKeyPair
|
||||
- /job/**
|
||||
|
||||
--- # Actuator 监控端点的配置项
|
||||
management:
|
||||
|
@ -29,6 +29,7 @@ user.notfound=请重新登录
|
||||
user.forcelogout=管理员强制退出,请重新登录
|
||||
user.unknown.error=未知错误,请重新登录
|
||||
auth.grant.type.error=认证权限类型错误
|
||||
auth.grant.type.blocked=认证权限类型已禁用
|
||||
auth.grant.type.not.blank=认证权限类型不能为空
|
||||
auth.clientid.not.blank=认证客户端id不能为空
|
||||
##文件上传消息
|
||||
@ -49,7 +50,10 @@ sms.code.retry.limit.exceed=短信验证码输入错误{0}次,帐户锁定{1}
|
||||
email.code.not.blank=邮箱验证码不能为空
|
||||
email.code.retry.limit.count=邮箱验证码输入错误{0}次
|
||||
email.code.retry.limit.exceed=邮箱验证码输入错误{0}次,帐户锁定{1}分钟
|
||||
xcx.code.not.blank=小程序code不能为空
|
||||
xcx.code.not.blank=小程序[code]不能为空
|
||||
social.source.not.blank=第三方登录平台[source]不能为空
|
||||
social.code.not.blank=第三方登录平台[code]不能为空
|
||||
social.state.not.blank=第三方登录平台[state]不能为空
|
||||
##租户
|
||||
tenant.number.not.blank=租户编号不能为空
|
||||
tenant.not.exists=对不起, 您的租户不存在,请联系管理员
|
||||
|
@ -29,6 +29,7 @@ user.notfound=Please login again
|
||||
user.forcelogout=The administrator is forced to exit,please login again
|
||||
user.unknown.error=Unknown error, please login again
|
||||
auth.grant.type.error=Auth grant type error
|
||||
auth.grant.type.blocked=Auth grant type disabled
|
||||
auth.grant.type.not.blank=Auth grant type cannot be blank
|
||||
auth.clientid.not.blank=Auth clientid cannot be blank
|
||||
##文件上传消息
|
||||
@ -49,7 +50,10 @@ sms.code.retry.limit.exceed=Sms code input error {0} times, account locked for {
|
||||
email.code.not.blank=Email code cannot be blank
|
||||
email.code.retry.limit.count=Email code input error {0} times
|
||||
email.code.retry.limit.exceed=Email code input error {0} times, account locked for {1} minutes
|
||||
xcx.code.not.blank=Mini program code cannot be blank
|
||||
xcx.code.not.blank=Mini program [code] cannot be blank
|
||||
social.source.not.blank=Social login platform [source] cannot be blank
|
||||
social.code.not.blank=Social login platform [code] cannot be blank
|
||||
social.state.not.blank=Social login platform [state] cannot be blank
|
||||
##租户
|
||||
tenant.number.not.blank=Tenant number cannot be blank
|
||||
tenant.not.exists=Sorry, your tenant does not exist. Please contact the administrator
|
||||
|
@ -29,6 +29,7 @@ user.notfound=请重新登录
|
||||
user.forcelogout=管理员强制退出,请重新登录
|
||||
user.unknown.error=未知错误,请重新登录
|
||||
auth.grant.type.error=认证权限类型错误
|
||||
auth.grant.type.blocked=认证权限类型已禁用
|
||||
auth.grant.type.not.blank=认证权限类型不能为空
|
||||
auth.clientid.not.blank=认证客户端id不能为空
|
||||
##文件上传消息
|
||||
@ -49,7 +50,10 @@ sms.code.retry.limit.exceed=短信验证码输入错误{0}次,帐户锁定{1}
|
||||
email.code.not.blank=邮箱验证码不能为空
|
||||
email.code.retry.limit.count=邮箱验证码输入错误{0}次
|
||||
email.code.retry.limit.exceed=邮箱验证码输入错误{0}次,帐户锁定{1}分钟
|
||||
xcx.code.not.blank=小程序code不能为空
|
||||
xcx.code.not.blank=小程序[code]不能为空
|
||||
social.source.not.blank=第三方登录平台[source]不能为空
|
||||
social.code.not.blank=第三方登录平台[code]不能为空
|
||||
social.state.not.blank=第三方登录平台[state]不能为空
|
||||
##租户
|
||||
tenant.number.not.blank=租户编号不能为空
|
||||
tenant.not.exists=对不起, 您的租户不存在,请联系管理员
|
||||
|
BIN
ruoyi-admin/src/main/resources/ip2region.xdb
Normal file
BIN
ruoyi-admin/src/main/resources/ip2region.xdb
Normal file
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="/home/ruoyi/logs" />
|
||||
<property name="log.path" value="./home/ruoyi/logs" />
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
||||
|
||||
|
@ -13,18 +13,23 @@
|
||||
<modules>
|
||||
<module>ruoyi-common-bom</module>
|
||||
<module>ruoyi-common-core</module>
|
||||
<module>ruoyi-common-encrypt</module>
|
||||
<module>ruoyi-common-excel</module>
|
||||
<module>ruoyi-common-job</module>
|
||||
<module>ruoyi-common-json</module>
|
||||
<module>ruoyi-common-log</module>
|
||||
<module>ruoyi-common-mail</module>
|
||||
<module>ruoyi-common-orm</module>
|
||||
<module>ruoyi-common-oss</module>
|
||||
<module>ruoyi-common-ratelimiter</module>
|
||||
<module>ruoyi-common-redis</module>
|
||||
<module>ruoyi-common-security</module>
|
||||
<module>ruoyi-common-sms</module>
|
||||
<module>ruoyi-common-social</module>
|
||||
<module>ruoyi-common-springdoc</module>
|
||||
<module>ruoyi-common-tenant</module>
|
||||
<module>ruoyi-common-web</module>
|
||||
<module>ruoyi-common-websocket</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
|
@ -14,7 +14,7 @@
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<revision>4.2.0</revision>
|
||||
<revision>5.2.0-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -26,6 +26,13 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 加解密模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-encrypt</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- excel模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
@ -54,6 +61,13 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 邮件模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-mail</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 数据库映射模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
@ -89,6 +103,20 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 短信模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-sms</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 三方授权认证模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-social</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
@ -110,6 +138,13 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- WebSocket模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-websocket</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
@ -125,12 +125,6 @@
|
||||
<artifactId>hutool-extra</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-json</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- mapstruct-plus -->
|
||||
<dependency>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
@ -149,6 +143,16 @@
|
||||
<artifactId>ip2region</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- findbugs消除打包警告 -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.ruoyi.common.core.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
/**
|
||||
* 程序注解配置
|
||||
@ -11,7 +12,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
@AutoConfiguration
|
||||
// 表示通过aop框架暴露该代理对象,AopContext能够访问
|
||||
@EnableAspectJAutoProxy(exposeProxy = true)
|
||||
// 指定要扫描的Mapper类的包的路径
|
||||
@EnableAsync(proxyTargetClass = true)
|
||||
public class ApplicationConfig
|
||||
{
|
||||
|
||||
|
@ -5,6 +5,8 @@ import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@ -13,10 +15,10 @@ import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* 异步配置
|
||||
*
|
||||
* <p>
|
||||
* 如果未使用虚拟线程则生效
|
||||
* @author Lion Li
|
||||
*/
|
||||
@EnableAsync(proxyTargetClass = true)
|
||||
@AutoConfiguration
|
||||
public class AsyncConfig implements AsyncConfigurer {
|
||||
|
||||
@ -25,6 +27,9 @@ public class AsyncConfig implements AsyncConfigurer {
|
||||
*/
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
if(SpringUtils.isVirtual()) {
|
||||
return new VirtualThreadTaskExecutor("async-");
|
||||
}
|
||||
return SpringUtils.getBean("scheduledExecutorService");
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,11 @@
|
||||
package com.ruoyi.common.core.config;
|
||||
|
||||
import com.ruoyi.common.core.config.properties.ThreadPoolProperties;
|
||||
import com.ruoyi.common.core.utils.Threads;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
@ -21,7 +17,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
**/
|
||||
@Slf4j
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(ThreadPoolProperties.class)
|
||||
public class ThreadPoolConfig
|
||||
{
|
||||
/**
|
||||
@ -31,18 +26,6 @@ public class ThreadPoolConfig
|
||||
|
||||
private ScheduledExecutorService scheduledExecutorService;
|
||||
|
||||
@Bean(name = "threadPoolTaskExecutor")
|
||||
@ConditionalOnProperty(prefix = "thread-pool", name = "enabled", havingValue = "true")
|
||||
public ThreadPoolTaskExecutor threadPoolTaskExecutor(ThreadPoolProperties threadPoolProperties) {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(core);
|
||||
executor.setMaxPoolSize(core * 2);
|
||||
executor.setQueueCapacity(threadPoolProperties.getQueueCapacity());
|
||||
executor.setKeepAliveSeconds(threadPoolProperties.getKeepAliveSeconds());
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行周期性或定时任务
|
||||
*/
|
||||
|
@ -1,30 +0,0 @@
|
||||
package com.ruoyi.common.core.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* 线程池 配置属性
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "thread-pool")
|
||||
public class ThreadPoolProperties {
|
||||
|
||||
/**
|
||||
* 是否开启线程池
|
||||
*/
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* 队列最大长度
|
||||
*/
|
||||
private int queueCapacity;
|
||||
|
||||
/**
|
||||
* 线程池维护线程所允许的空闲时间
|
||||
*/
|
||||
private int keepAliveSeconds;
|
||||
|
||||
}
|
@ -35,6 +35,11 @@ public interface CacheNames {
|
||||
*/
|
||||
String SYS_TENANT = GlobalConstants.GLOBAL_REDIS_KEY + "sys_tenant#30d";
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
String SYS_CLIENT = GlobalConstants.GLOBAL_REDIS_KEY + "sys_client#30d";
|
||||
|
||||
/**
|
||||
* 用户账户
|
||||
*/
|
||||
@ -53,7 +58,7 @@ public interface CacheNames {
|
||||
/**
|
||||
* OSS配置
|
||||
*/
|
||||
String SYS_OSS_CONFIG = "sys_oss_config";
|
||||
String SYS_OSS_CONFIG = GlobalConstants.GLOBAL_REDIS_KEY + "sys_oss_config";
|
||||
|
||||
/**
|
||||
* 在线用户
|
||||
|
@ -80,68 +80,14 @@ public class Constants
|
||||
public static final String TOKEN = "token";
|
||||
|
||||
/**
|
||||
* 令牌前缀
|
||||
* 顶级部门id
|
||||
*/
|
||||
public static final String TOKEN_PREFIX = "Bearer ";
|
||||
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
public static final String LOGIN_USER_KEY = "login_user_key";
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
public static final String JWT_USERID = "userid";
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
public static final String JWT_USERNAME = Claims.SUBJECT;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
public static final String JWT_AVATAR = "avatar";
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
public static final String JWT_CREATED = "created";
|
||||
|
||||
/**
|
||||
* 用户权限
|
||||
*/
|
||||
public static final String JWT_AUTHORITIES = "authorities";
|
||||
public static final Long TOP_PARENT_ID = 0L;
|
||||
|
||||
/**
|
||||
* 资源映射路径 前缀
|
||||
*/
|
||||
public static final String RESOURCE_PREFIX = "/profile";
|
||||
|
||||
/**
|
||||
* RMI 远程方法调用
|
||||
*/
|
||||
public static final String LOOKUP_RMI = "rmi:";
|
||||
|
||||
/**
|
||||
* LDAP 远程方法调用
|
||||
*/
|
||||
public static final String LOOKUP_LDAP = "ldap:";
|
||||
|
||||
/**
|
||||
* LDAPS 远程方法调用
|
||||
*/
|
||||
public static final String LOOKUP_LDAPS = "ldaps:";
|
||||
|
||||
/**
|
||||
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
|
||||
*/
|
||||
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
|
||||
|
||||
/**
|
||||
* 定时任务违规的字符
|
||||
*/
|
||||
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
|
||||
"org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config" };
|
||||
}
|
||||
|
@ -5,120 +5,193 @@ package com.ruoyi.common.core.constant;
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class GenConstants
|
||||
{
|
||||
/** 单表(增删改查) */
|
||||
public class GenConstants {
|
||||
/**
|
||||
* 单表(增删改查)
|
||||
*/
|
||||
public static final String TPL_CRUD = "crud";
|
||||
|
||||
/** 树表(增删改查) */
|
||||
/**
|
||||
* 树表(增删改查)
|
||||
*/
|
||||
public static final String TPL_TREE = "tree";
|
||||
|
||||
/** 主子表(增删改查) */
|
||||
/**
|
||||
* 主子表(增删改查)
|
||||
*/
|
||||
public static final String TPL_SUB = "sub";
|
||||
|
||||
/** 树编码字段 */
|
||||
/**
|
||||
* 树编码字段
|
||||
*/
|
||||
public static final String TREE_CODE = "treeCode";
|
||||
|
||||
/** 树父编码字段 */
|
||||
/**
|
||||
* 树父编码字段
|
||||
*/
|
||||
public static final String TREE_PARENT_CODE = "treeParentCode";
|
||||
|
||||
/** 树名称字段 */
|
||||
/**
|
||||
* 树名称字段
|
||||
*/
|
||||
public static final String TREE_NAME = "treeName";
|
||||
|
||||
/** 上级菜单ID字段 */
|
||||
/**
|
||||
* 上级菜单ID字段
|
||||
*/
|
||||
public static final String PARENT_MENU_ID = "parentMenuId";
|
||||
|
||||
/** 上级菜单名称字段 */
|
||||
/**
|
||||
* 上级菜单名称字段
|
||||
*/
|
||||
public static final String PARENT_MENU_NAME = "parentMenuName";
|
||||
|
||||
/** 数据库字符串类型 */
|
||||
public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2","character","character varying" };
|
||||
/**
|
||||
* 数据库字符串类型
|
||||
*/
|
||||
public static final String[] COLUMNTYPE_STR = {"char", "varchar", "nvarchar", "enum", "set", "nchar", "nvarchar", "varchar2", "nvarchar2", "character", "character varying"};
|
||||
|
||||
/** 数据库文本类型 */
|
||||
public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext", "binary", "varbinary", "blob",
|
||||
"ntext", "image", "bytea" };
|
||||
/**
|
||||
* 数据库文本类型
|
||||
*/
|
||||
public static final String[] COLUMNTYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext", "binary", "varbinary", "blob",
|
||||
"ntext", "image", "bytea"};
|
||||
|
||||
/** 数据库时间类型 */
|
||||
public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp","timestamp without time zone","year", "interval",
|
||||
"smalldatetime", "datetime2", "datetimeoffset" };
|
||||
/**
|
||||
* 数据库时间类型
|
||||
*/
|
||||
public static final String[] COLUMNTYPE_TIME = {"datetime", "time", "date", "timestamp", "timestamp without time zone", "year", "interval",
|
||||
"smalldatetime", "datetime2", "datetimeoffset"};
|
||||
|
||||
/** 数据库数字类型 */
|
||||
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||
/**
|
||||
* 数据库integer类型
|
||||
*/
|
||||
public static final String[] COLUMNTYPE_INTEGER = {"tinyint", "smallint", "mediumint", "int", "number", "integer", "bit"};
|
||||
|
||||
/**
|
||||
* 数据库数字类型
|
||||
*/
|
||||
public static final String[] COLUMNTYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||
"bit", "bigint", "float", "double", "decimal", "numeric", "real", "double precision",
|
||||
"smallserial", "serial", "bigserial", "money", "smallmoney" };
|
||||
"smallserial", "serial", "bigserial", "money", "smallmoney"};
|
||||
|
||||
/**
|
||||
* BO对象 不需要添加字段
|
||||
*/
|
||||
public static final String[] COLUMNNAME_NOT_ADD = {"create_by", "create_time", "update_by", "update_time" };
|
||||
public static final String[] COLUMNNAME_NOT_ADD = {"tenant_id", "version", "del_flag", "create_by", "create_time", "update_by", "update_time"};
|
||||
|
||||
/** BO对象 不需要编辑字段 */
|
||||
public static final String[] COLUMNNAME_NOT_EDIT = { "create_by", "create_time", "update_by", "update_time" };
|
||||
/**
|
||||
* BO对象 不需要编辑字段
|
||||
*/
|
||||
public static final String[] COLUMNNAME_NOT_EDIT = {"tenant_id","del_flag", "create_by", "create_time", "update_by", "update_time"};
|
||||
|
||||
/** VO对象 不需要显示的列表字段 */
|
||||
public static final String[] COLUMNNAME_NOT_LIST = { "create_by", "create_time", "update_by", "update_time" };
|
||||
/**
|
||||
* VO对象 不需要显示的列表字段
|
||||
*/
|
||||
public static final String[] COLUMNNAME_NOT_LIST = {"tenant_id", "version", "del_flag", "create_by", "create_time", "update_by", "update_time"};
|
||||
|
||||
/** BO对象 不需要查询字段 */
|
||||
public static final String[] COLUMNNAME_NOT_QUERY = { "create_by", "create_time", "update_by",
|
||||
"update_time", "del_flag", "remark", "version" };
|
||||
/**
|
||||
* BO对象 不需要查询字段
|
||||
*/
|
||||
public static final String[] COLUMNNAME_NOT_QUERY = {"tenant_id", "version", "del_flag", "create_by", "create_time", "update_by", "update_time", "remark", "id"};
|
||||
|
||||
/** Entity基类字段 */
|
||||
public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime"};
|
||||
/**
|
||||
* Entity基类字段
|
||||
*/
|
||||
public static final String[] BASE_ENTITY = {"tenantId", "version", "createBy", "createTime", "updateBy", "updateTime"};
|
||||
|
||||
/** Tree基类字段 */
|
||||
public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" };
|
||||
/**
|
||||
* Tree基类字段
|
||||
*/
|
||||
public static final String[] TREE_ENTITY = {"parentName", "parentId", "orderNum", "ancestors", "children"};
|
||||
|
||||
/** 文本框 */
|
||||
/**
|
||||
* 文本框
|
||||
*/
|
||||
public static final String HTML_INPUT = "input";
|
||||
|
||||
/** 文本域 */
|
||||
/**
|
||||
* 文本域
|
||||
*/
|
||||
public static final String HTML_TEXTAREA = "textarea";
|
||||
|
||||
/** 下拉框 */
|
||||
/**
|
||||
* 下拉框
|
||||
*/
|
||||
public static final String HTML_SELECT = "select";
|
||||
|
||||
/** 单选框 */
|
||||
/**
|
||||
* 单选框
|
||||
*/
|
||||
public static final String HTML_RADIO = "radio";
|
||||
|
||||
/** 复选框 */
|
||||
/**
|
||||
* 复选框
|
||||
*/
|
||||
public static final String HTML_CHECKBOX = "checkbox";
|
||||
|
||||
/** 日期控件 */
|
||||
/**
|
||||
* 日期控件
|
||||
*/
|
||||
public static final String HTML_DATETIME = "datetime";
|
||||
|
||||
/** 图片上传控件 */
|
||||
/**
|
||||
* 图片上传控件
|
||||
*/
|
||||
public static final String HTML_IMAGE_UPLOAD = "imageUpload";
|
||||
|
||||
/** 文件上传控件 */
|
||||
/**
|
||||
* 文件上传控件
|
||||
*/
|
||||
public static final String HTML_FILE_UPLOAD = "fileUpload";
|
||||
|
||||
/** 富文本控件 */
|
||||
/**
|
||||
* 富文本控件
|
||||
*/
|
||||
public static final String HTML_EDITOR = "editor";
|
||||
|
||||
/** 字符串类型 */
|
||||
/**
|
||||
* 字符串类型
|
||||
*/
|
||||
public static final String TYPE_STRING = "String";
|
||||
|
||||
/** 整型 */
|
||||
/**
|
||||
* 整型
|
||||
*/
|
||||
public static final String TYPE_INTEGER = "Integer";
|
||||
|
||||
/** 长整型 */
|
||||
/**
|
||||
* 长整型
|
||||
*/
|
||||
public static final String TYPE_LONG = "Long";
|
||||
|
||||
/** 浮点型 */
|
||||
/**
|
||||
* 浮点型
|
||||
*/
|
||||
public static final String TYPE_DOUBLE = "Double";
|
||||
|
||||
/** 高精度计算类型 */
|
||||
/**
|
||||
* 高精度计算类型
|
||||
*/
|
||||
public static final String TYPE_BIGDECIMAL = "BigDecimal";
|
||||
|
||||
/** 时间类型 */
|
||||
/**
|
||||
* 时间类型
|
||||
*/
|
||||
public static final String TYPE_DATE = "Date";
|
||||
|
||||
/** 模糊查询 */
|
||||
/**
|
||||
* 模糊查询
|
||||
*/
|
||||
public static final String QUERY_LIKE = "LIKE";
|
||||
|
||||
/** 相等查询 */
|
||||
/**
|
||||
* 相等查询
|
||||
*/
|
||||
public static final String QUERY_EQ = "EQ";
|
||||
|
||||
/** 需要 */
|
||||
/**
|
||||
* 需要
|
||||
*/
|
||||
public static final String REQUIRE = "1";
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.ruoyi.common.core.constant;
|
||||
|
||||
import cn.hutool.core.lang.RegexPool;
|
||||
|
||||
/**
|
||||
* 常用正则表达式字符串
|
||||
* <p>
|
||||
* 常用正则表达式集合,更多正则见: https://any86.github.io/any-rule/
|
||||
*
|
||||
* @author Feng
|
||||
*/
|
||||
public interface RegexConstants extends RegexPool {
|
||||
|
||||
/**
|
||||
* 字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)
|
||||
*/
|
||||
public static final String DICTIONARY_TYPE = "^[a-z][a-z0-9_]*$";
|
||||
|
||||
/**
|
||||
* 身份证号码(后6位)
|
||||
*/
|
||||
public static final String ID_CARD_LAST_6 = "^(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
|
||||
|
||||
/**
|
||||
* QQ号码
|
||||
*/
|
||||
public static final String QQ_NUMBER = "^[1-9][0-9]\\d{4,9}$";
|
||||
|
||||
/**
|
||||
* 邮政编码
|
||||
*/
|
||||
public static final String POSTAL_CODE = "^[1-9]\\d{5}$";
|
||||
|
||||
/**
|
||||
* 注册账号
|
||||
*/
|
||||
public static final String ACCOUNT = "^[a-zA-Z][a-zA-Z0-9_]{4,15}$";
|
||||
|
||||
/**
|
||||
* 密码:包含至少8个字符,包括大写字母、小写字母、数字和特殊字符
|
||||
*/
|
||||
public static final String PASSWORD = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$";
|
||||
|
||||
/**
|
||||
* 通用状态(0表示正常,1表示停用)
|
||||
*/
|
||||
public static final String STATUS = "^[01]$";
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ package com.ruoyi.common.core.constant;
|
||||
* 租户常量信息
|
||||
*
|
||||
* @author Lion Li
|
||||
* @author 数据小王子
|
||||
*/
|
||||
public interface TenantConstants {
|
||||
|
||||
@ -25,21 +26,21 @@ public interface TenantConstants {
|
||||
/**
|
||||
* 超级管理员角色 roleKey
|
||||
*/
|
||||
String SUPER_ADMIN_ROLE_KEY = "superadmin";
|
||||
String SUPER_ADMIN_ROLE_KEY = "SuperAminRole";
|
||||
|
||||
/**
|
||||
* 租户管理员角色 roleKey
|
||||
*/
|
||||
String TENANT_ADMIN_ROLE_KEY = "admin";
|
||||
String TENANT_ADMIN_ROLE_KEY = "AdminRole";
|
||||
|
||||
/**
|
||||
* 租户管理员角色名称
|
||||
*/
|
||||
String TENANT_ADMIN_ROLE_NAME = "管理员";
|
||||
String TENANT_ADMIN_ROLE_NAME = "管理员角色";
|
||||
|
||||
/**
|
||||
* 默认租户ID
|
||||
*/
|
||||
String DEFAULT_TENANT_ID = "000000";
|
||||
Long DEFAULT_TENANT_ID = 1L;
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,16 @@ public class UserOnlineDTO implements Serializable {
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 登录IP地址
|
||||
*/
|
||||
|
@ -11,13 +11,7 @@ import lombok.Data;
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class EmailLoginBody {
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
@NotBlank(message = "{tenant.number.not.blank}")
|
||||
private String tenantId;
|
||||
public class EmailLoginBody extends LoginBody {
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
|
@ -111,6 +111,16 @@ public class LoginUser
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 获取登录id
|
||||
*/
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.ruoyi.common.core.core.domain.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import static com.ruoyi.common.core.constant.UserConstants.*;
|
||||
|
||||
/**
|
||||
* 密码登录对象
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PasswordLoginBody extends LoginBody {
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message = "{user.username.not.blank}")
|
||||
@Length(min = USERNAME_MIN_LENGTH, max = USERNAME_MAX_LENGTH, message = "{user.username.length.valid}")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
@NotBlank(message = "{user.password.not.blank}")
|
||||
@Length(min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH, message = "{user.password.length.valid}")
|
||||
private String password;
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.ruoyi.common.core.core.domain.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 短信登录对象
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SmsLoginBody extends LoginBody {
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@NotBlank(message = "{user.phonenumber.not.blank}")
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 短信code
|
||||
*/
|
||||
@NotBlank(message = "{sms.code.not.blank}")
|
||||
private String smsCode;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.ruoyi.common.core.core.domain.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 三方登录对象
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SocialLoginBody extends LoginBody {
|
||||
|
||||
/**
|
||||
* 第三方登录平台
|
||||
*/
|
||||
@NotBlank(message = "{social.source.not.blank}")
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 第三方登录code
|
||||
*/
|
||||
@NotBlank(message = "{social.code.not.blank}")
|
||||
private String socialCode;
|
||||
|
||||
/**
|
||||
* 第三方登录socialState
|
||||
*/
|
||||
@NotBlank(message = "{social.state.not.blank}")
|
||||
private String socialState;
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.ruoyi.common.core.core.domain.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 三方登录对象
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class XcxLoginBody extends LoginBody {
|
||||
|
||||
/**
|
||||
* 小程序id(多个小程序时使用)
|
||||
*/
|
||||
private String appid;
|
||||
|
||||
/**
|
||||
* 小程序code
|
||||
*/
|
||||
@NotBlank(message = "{xcx.code.not.blank}")
|
||||
private String xcxCode;
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.ruoyi.common.core.core.domain.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 小程序登录用户身份权限
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
public class XcxLoginUser extends LoginUser {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* openid
|
||||
*/
|
||||
private String openid;
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.ruoyi.common.core.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
* @author LionLi
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum TenantStatus {
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
OK("0", "正常"),
|
||||
/**
|
||||
* 停用
|
||||
*/
|
||||
DISABLE("1", "停用"),
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
DELETED("2", "删除");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.ruoyi.common.core.exception;
|
||||
|
||||
/**
|
||||
* 演示模式异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DemoModeException extends RuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public DemoModeException()
|
||||
{
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package com.ruoyi.common.core.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 全局异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class GlobalException extends RuntimeException
|
||||
{
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 错误提示
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 错误明细,内部调试错误
|
||||
*
|
||||
*/
|
||||
private String detailMessage;
|
||||
|
||||
/**
|
||||
* 空构造方法,避免反序列化问题
|
||||
*/
|
||||
public GlobalException()
|
||||
{
|
||||
}
|
||||
|
||||
public GlobalException(String message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getDetailMessage()
|
||||
{
|
||||
return detailMessage;
|
||||
}
|
||||
|
||||
public GlobalException setDetailMessage(String detailMessage)
|
||||
{
|
||||
this.detailMessage = detailMessage;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
public GlobalException setMessage(String message)
|
||||
{
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.ruoyi.common.core.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 工具类异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UtilException extends RuntimeException
|
||||
{
|
||||
@Serial
|
||||
private static final long serialVersionUID = 8247610319171014183L;
|
||||
|
||||
public UtilException(Throwable e)
|
||||
{
|
||||
super(e.getMessage(), e);
|
||||
}
|
||||
|
||||
public UtilException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UtilException(String message, Throwable throwable)
|
||||
{
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.ruoyi.common.core.exception.user;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 用户密码不正确或不符合规范异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserPasswordNotMatchException extends UserException
|
||||
{
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserPasswordNotMatchException()
|
||||
{
|
||||
super("user.password.not.match", (Object)null);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.ruoyi.common.core.exception.user;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 用户错误最大次数异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserPasswordRetryLimitExceedException extends UserException
|
||||
{
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserPasswordRetryLimitExceedException(int retryLimitCount, int lockTime)
|
||||
{
|
||||
super("user.password.retry.limit.exceed", new Object[] { retryLimitCount, lockTime });
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.ruoyi.common.core.factory;
|
||||
|
||||
import cn.hutool.core.lang.PatternPool;
|
||||
import com.ruoyi.common.core.constant.RegexConstants;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 正则表达式模式池工厂
|
||||
* <p>初始化的时候将正则表达式加入缓存池当中</p>
|
||||
* <p>提高正则表达式的性能,避免重复编译相同的正则表达式</p>
|
||||
*
|
||||
* @author 21001
|
||||
*/
|
||||
public class RegexPatternPoolFactory extends PatternPool {
|
||||
|
||||
/**
|
||||
* 字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)
|
||||
*/
|
||||
public static final Pattern DICTIONARY_TYPE = get(RegexConstants.DICTIONARY_TYPE);
|
||||
|
||||
/**
|
||||
* 身份证号码(后6位)
|
||||
*/
|
||||
public static final Pattern ID_CARD_LAST_6 = get(RegexConstants.ID_CARD_LAST_6);
|
||||
|
||||
/**
|
||||
* QQ号码
|
||||
*/
|
||||
public static final Pattern QQ_NUMBER = get(RegexConstants.QQ_NUMBER);
|
||||
|
||||
/**
|
||||
* 邮政编码
|
||||
*/
|
||||
public static final Pattern POSTAL_CODE = get(RegexConstants.POSTAL_CODE);
|
||||
|
||||
/**
|
||||
* 注册账号
|
||||
*/
|
||||
public static final Pattern ACCOUNT = get(RegexConstants.ACCOUNT);
|
||||
|
||||
/**
|
||||
* 密码:包含至少8个字符,包括大写字母、小写字母、数字和特殊字符
|
||||
*/
|
||||
public static final Pattern PASSWORD = get(RegexConstants.PASSWORD);
|
||||
|
||||
/**
|
||||
* 通用状态(0表示正常,1表示停用)
|
||||
*/
|
||||
public static final Pattern STATUS = get(RegexConstants.STATUS);
|
||||
|
||||
}
|
@ -3,7 +3,9 @@ package com.ruoyi.common.core.utils;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import org.springframework.aop.framework.AopContext;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.autoconfigure.thread.Threading;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -98,4 +100,8 @@ public final class SpringUtils extends SpringUtil
|
||||
return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null;
|
||||
}
|
||||
|
||||
public static boolean isVirtual() {
|
||||
return Threading.VIRTUAL.isActive(getBean(Environment.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,9 +26,21 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
{
|
||||
public static final String SEPARATOR = ",";
|
||||
|
||||
public static final String SLASH = "/";
|
||||
|
||||
/** 空字符串 */
|
||||
private static final String NULLSTR = "";
|
||||
|
||||
/**
|
||||
* 获取参数不为空值
|
||||
*
|
||||
* @param str defaultValue 要判断的value
|
||||
* @return value 返回值
|
||||
*/
|
||||
public static String blankToDefault(String str, String defaultValue) {
|
||||
return StrUtil.blankToDefault(str, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数不为空值
|
||||
*
|
||||
|
@ -76,7 +76,6 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.core.config.RuoYiConfig;
|
||||
import com.ruoyi.common.core.exception.UtilException;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.file.FileTypeUtils;
|
||||
import com.ruoyi.common.core.utils.file.FileUtils;
|
||||
@ -540,7 +539,7 @@ public class ExcelUtil<T> {
|
||||
return AjaxResult.success(filename);
|
||||
} catch (Exception e) {
|
||||
log.error("导出Excel异常{}", e.getMessage());
|
||||
throw new UtilException("导出Excel失败,请联系网站管理员!");
|
||||
throw new IllegalArgumentException("导出Excel失败,请联系网站管理员!");
|
||||
} finally {
|
||||
IOUtils.closeQuietly(wb);
|
||||
IOUtils.closeQuietly(out);
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.ruoyi.common.core.utils.regex;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import com.ruoyi.common.core.constant.RegexConstants;
|
||||
|
||||
/**
|
||||
* 正则相关工具类
|
||||
*
|
||||
* @author Feng
|
||||
*/
|
||||
public final class RegexUtils extends ReUtil {
|
||||
|
||||
/**
|
||||
* 从输入字符串中提取匹配的部分,如果没有匹配则返回默认值
|
||||
*
|
||||
* @param input 要提取的输入字符串
|
||||
* @param regex 用于匹配的正则表达式,可以使用 {@link RegexConstants} 中定义的常量
|
||||
* @param defaultInput 如果没有匹配时返回的默认值
|
||||
* @return 如果找到匹配的部分,则返回匹配的部分,否则返回默认值
|
||||
*/
|
||||
public static String extractFromString(String input, String regex, String defaultInput) {
|
||||
try {
|
||||
return ReUtil.get(regex, input, 1);
|
||||
} catch (Exception e) {
|
||||
return defaultInput;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package com.ruoyi.common.core.utils.regex;
|
||||
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import com.ruoyi.common.core.factory.RegexPatternPoolFactory;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 正则字段校验器
|
||||
* 主要验证字段非空、是否为满足指定格式等
|
||||
*
|
||||
* @author Feng
|
||||
*/
|
||||
public class RegexValidator extends Validator {
|
||||
|
||||
/**
|
||||
* 字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)
|
||||
*/
|
||||
public static final Pattern DICTIONARY_TYPE = RegexPatternPoolFactory.DICTIONARY_TYPE;
|
||||
|
||||
/**
|
||||
* 身份证号码(后6位)
|
||||
*/
|
||||
public static final Pattern ID_CARD_LAST_6 = RegexPatternPoolFactory.ID_CARD_LAST_6;
|
||||
|
||||
/**
|
||||
* QQ号码
|
||||
*/
|
||||
public static final Pattern QQ_NUMBER = RegexPatternPoolFactory.QQ_NUMBER;
|
||||
|
||||
/**
|
||||
* 邮政编码
|
||||
*/
|
||||
public static final Pattern POSTAL_CODE = RegexPatternPoolFactory.POSTAL_CODE;
|
||||
|
||||
/**
|
||||
* 注册账号
|
||||
*/
|
||||
public static final Pattern ACCOUNT = RegexPatternPoolFactory.ACCOUNT;
|
||||
|
||||
/**
|
||||
* 密码:包含至少8个字符,包括大写字母、小写字母、数字和特殊字符
|
||||
*/
|
||||
public static final Pattern PASSWORD = RegexPatternPoolFactory.PASSWORD;
|
||||
|
||||
/**
|
||||
* 通用状态(0表示正常,1表示停用)
|
||||
*/
|
||||
public static final Pattern STATUS = RegexPatternPoolFactory.STATUS;
|
||||
|
||||
|
||||
/**
|
||||
* 检查输入的账号是否匹配预定义的规则
|
||||
*
|
||||
* @param value 要验证的账号
|
||||
* @return 如果账号符合规则,返回 true;否则,返回 false。
|
||||
*/
|
||||
public static boolean isAccount(CharSequence value) {
|
||||
return isMatchRegex(ACCOUNT, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证输入的账号是否符合规则,如果不符合,则抛出 ValidateException 异常
|
||||
*
|
||||
* @param value 要验证的账号
|
||||
* @param errorMsg 验证失败时抛出的异常消息
|
||||
* @param <T> CharSequence 的子类型
|
||||
* @return 如果验证通过,返回输入的账号
|
||||
* @throws ValidateException 如果验证失败
|
||||
*/
|
||||
public static <T extends CharSequence> T validateAccount(T value, String errorMsg) throws ValidateException {
|
||||
if (!isAccount(value)) {
|
||||
throw new ValidateException(errorMsg);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查输入的状态是否匹配预定义的规则
|
||||
*
|
||||
* @param value 要验证的状态
|
||||
* @return 如果状态符合规则,返回 true;否则,返回 false。
|
||||
*/
|
||||
public static boolean isStatus(CharSequence value) {
|
||||
return isMatchRegex(STATUS, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证输入的状态是否符合规则,如果不符合,则抛出 ValidateException 异常
|
||||
*
|
||||
* @param value 要验证的状态
|
||||
* @param errorMsg 验证失败时抛出的异常消息
|
||||
* @param <T> CharSequence 的子类型
|
||||
* @return 如果验证通过,返回输入的状态
|
||||
* @throws ValidateException 如果验证失败
|
||||
*/
|
||||
public static <T extends CharSequence> T validateStatus(T value, String errorMsg) throws ValidateException {
|
||||
if (!isStatus(value)) {
|
||||
throw new ValidateException(errorMsg);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.ruoyi.common.core.utils.sql;
|
||||
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.exception.UtilException;
|
||||
|
||||
/**
|
||||
* sql操作工具类
|
||||
@ -32,11 +31,11 @@ public class SqlUtil
|
||||
{
|
||||
if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value))
|
||||
{
|
||||
throw new UtilException("参数不符合规范,不能进行查询");
|
||||
throw new IllegalArgumentException("参数不符合规范,不能进行查询");
|
||||
}
|
||||
if (StringUtils.length(value) > ORDER_BY_MAX_LENGTH)
|
||||
{
|
||||
throw new UtilException("参数已超过最大限制,不能进行查询");
|
||||
throw new IllegalArgumentException("参数已超过最大限制,不能进行查询");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -63,7 +62,7 @@ public class SqlUtil
|
||||
{
|
||||
if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1)
|
||||
{
|
||||
throw new UtilException("参数存在SQL注入风险");
|
||||
throw new IllegalArgumentException("参数存在SQL注入风险");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import com.ruoyi.common.core.exception.UtilException;
|
||||
|
||||
/**
|
||||
* 提供通用唯一识别码(universally unique identifier)(UUID)实现
|
||||
@ -467,7 +466,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
throw new UtilException(e);
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
46
ruoyi-common/ruoyi-common-encrypt/pom.xml
Normal file
46
ruoyi-common/ruoyi-common-encrypt/pom.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-common-encrypt</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-common-encrypt 数据加解密模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-crypto</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-orm</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
package com.ruoyi.common.encrypt.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 强制加密注解
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Documented
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ApiEncrypt {
|
||||
|
||||
/**
|
||||
* 响应加密忽略,默认不加密,为 true 时加密
|
||||
*/
|
||||
boolean response() default false;
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.ruoyi.common.encrypt.annotation;
|
||||
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 字段加密注解
|
||||
*
|
||||
* @author 老马
|
||||
*/
|
||||
@Documented
|
||||
@Inherited
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface EncryptField {
|
||||
|
||||
/**
|
||||
* 加密算法
|
||||
*/
|
||||
AlgorithmType algorithm() default AlgorithmType.DEFAULT;
|
||||
|
||||
/**
|
||||
* 秘钥。AES、SM4需要
|
||||
*/
|
||||
String password() default "";
|
||||
|
||||
/**
|
||||
* 公钥。RSA、SM2需要
|
||||
*/
|
||||
String publicKey() default "";
|
||||
|
||||
/**
|
||||
* 私钥。RSA、SM2需要
|
||||
*/
|
||||
String privateKey() default "";
|
||||
|
||||
/**
|
||||
* 编码方式。对加密算法为BASE64的不起作用
|
||||
*/
|
||||
EncodeType encode() default EncodeType.DEFAULT;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.ruoyi.common.encrypt.config;
|
||||
|
||||
import com.ruoyi.common.encrypt.filter.CryptoFilter;
|
||||
import jakarta.servlet.DispatcherType;
|
||||
import com.ruoyi.common.encrypt.properties.ApiDecryptProperties;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* api 解密自动配置
|
||||
*
|
||||
* @author wdhcr
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(ApiDecryptProperties.class)
|
||||
@ConditionalOnProperty(value = "api-decrypt.enabled", havingValue = "true")
|
||||
public class ApiDecryptAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<CryptoFilter> cryptoFilterRegistration(ApiDecryptProperties properties) {
|
||||
FilterRegistrationBean<CryptoFilter> registration = new FilterRegistrationBean<>();
|
||||
registration.setDispatcherTypes(DispatcherType.REQUEST);
|
||||
registration.setFilter(new CryptoFilter(properties));
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("cryptoFilter");
|
||||
registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
|
||||
return registration;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.ruoyi.common.encrypt.config;
|
||||
|
||||
import com.ruoyi.common.encrypt.core.EncryptorManager;
|
||||
import com.ruoyi.common.encrypt.interceptor.MybatisDecryptInterceptor;
|
||||
import com.ruoyi.common.encrypt.interceptor.MybatisEncryptInterceptor;
|
||||
import com.ruoyi.common.encrypt.properties.EncryptorProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* 加解密配置
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(EncryptorProperties.class)
|
||||
@ConditionalOnProperty(value = "mybatis-encryptor.enable", havingValue = "true")
|
||||
public class EncryptorAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private EncryptorProperties properties;
|
||||
|
||||
@Bean
|
||||
public EncryptorManager encryptorManager() {
|
||||
return new EncryptorManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MybatisEncryptInterceptor mybatisEncryptInterceptor(EncryptorManager encryptorManager) {
|
||||
return new MybatisEncryptInterceptor(encryptorManager, properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MybatisDecryptInterceptor mybatisDecryptInterceptor(EncryptorManager encryptorManager) {
|
||||
return new MybatisDecryptInterceptor(encryptorManager, properties);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.ruoyi.common.encrypt.core;
|
||||
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import lombok.Data;
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
|
||||
/**
|
||||
* 加密上下文 用于encryptor传递必要的参数。
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@Data
|
||||
public class EncryptContext {
|
||||
|
||||
/**
|
||||
* 默认算法
|
||||
*/
|
||||
private AlgorithmType algorithm;
|
||||
|
||||
/**
|
||||
* 安全秘钥
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 公钥
|
||||
*/
|
||||
private String publicKey;
|
||||
|
||||
/**
|
||||
* 私钥
|
||||
*/
|
||||
private String privateKey;
|
||||
|
||||
/**
|
||||
* 编码方式,base64/hex
|
||||
*/
|
||||
private EncodeType encode;
|
||||
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package com.ruoyi.common.encrypt.core;
|
||||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.encrypt.annotation.EncryptField;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 加密管理类
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@Slf4j
|
||||
@NoArgsConstructor
|
||||
public class EncryptorManager {
|
||||
|
||||
/**
|
||||
* 缓存加密器
|
||||
*/
|
||||
Map<EncryptContext, IEncryptor> encryptorMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 类加密字段缓存
|
||||
*/
|
||||
Map<Class<?>, Set<Field>> fieldCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 获取类加密字段缓存
|
||||
*/
|
||||
public Set<Field> getFieldCache(Class<?> sourceClazz) {
|
||||
return fieldCache.computeIfAbsent(sourceClazz, clazz -> {
|
||||
Set<Field> fieldSet = new HashSet<>();
|
||||
while (clazz != null) {
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
fieldSet.addAll(Arrays.asList(fields));
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
fieldSet = fieldSet.stream().filter(field ->
|
||||
field.isAnnotationPresent(EncryptField.class) && field.getType() == String.class)
|
||||
.collect(Collectors.toSet());
|
||||
for (Field field : fieldSet) {
|
||||
field.setAccessible(true);
|
||||
}
|
||||
return fieldSet;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册加密执行者到缓存
|
||||
*
|
||||
* @param encryptContext 加密执行者需要的相关配置参数
|
||||
*/
|
||||
public IEncryptor registAndGetEncryptor(EncryptContext encryptContext) {
|
||||
if (encryptorMap.containsKey(encryptContext)) {
|
||||
return encryptorMap.get(encryptContext);
|
||||
}
|
||||
IEncryptor encryptor = ReflectUtil.newInstance(encryptContext.getAlgorithm().getClazz(), encryptContext);
|
||||
encryptorMap.put(encryptContext, encryptor);
|
||||
return encryptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除缓存中的加密执行者
|
||||
*
|
||||
* @param encryptContext 加密执行者需要的相关配置参数
|
||||
*/
|
||||
public void removeEncryptor(EncryptContext encryptContext) {
|
||||
this.encryptorMap.remove(encryptContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置进行加密。会进行本地缓存对应的算法和对应的秘钥信息。
|
||||
*
|
||||
* @param value 待加密的值
|
||||
* @param encryptContext 加密相关的配置信息
|
||||
*/
|
||||
public String encrypt(String value, EncryptContext encryptContext) {
|
||||
IEncryptor encryptor = this.registAndGetEncryptor(encryptContext);
|
||||
return encryptor.encrypt(value, encryptContext.getEncode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置进行解密
|
||||
*
|
||||
* @param value 待解密的值
|
||||
* @param encryptContext 加密相关的配置信息
|
||||
*/
|
||||
public String decrypt(String value, EncryptContext encryptContext) {
|
||||
IEncryptor encryptor = this.registAndGetEncryptor(encryptContext);
|
||||
return encryptor.decrypt(value);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.ruoyi.common.encrypt.core;
|
||||
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
|
||||
/**
|
||||
* 加解者
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
public interface IEncryptor {
|
||||
|
||||
/**
|
||||
* 获得当前算法
|
||||
*/
|
||||
AlgorithmType algorithm();
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
* @param encodeType 加密后的编码格式
|
||||
* @return 加密后的字符串
|
||||
*/
|
||||
String encrypt(String value, EncodeType encodeType);
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
* @return 解密后的字符串
|
||||
*/
|
||||
String decrypt(String value);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.ruoyi.common.encrypt.core.encryptor;
|
||||
|
||||
import com.ruoyi.common.encrypt.core.IEncryptor;
|
||||
import com.ruoyi.common.encrypt.core.EncryptContext;
|
||||
|
||||
/**
|
||||
* 所有加密执行者的基类
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
public abstract class AbstractEncryptor implements IEncryptor {
|
||||
|
||||
public AbstractEncryptor(EncryptContext context) {
|
||||
// 用户配置校验与配置注入
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.ruoyi.common.encrypt.core.encryptor;
|
||||
|
||||
import com.ruoyi.common.encrypt.core.EncryptContext;
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import com.ruoyi.common.encrypt.utils.EncryptUtils;
|
||||
|
||||
/**
|
||||
* AES算法实现
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
public class AesEncryptor extends AbstractEncryptor {
|
||||
|
||||
private final EncryptContext context;
|
||||
|
||||
public AesEncryptor(EncryptContext context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前算法
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmType algorithm() {
|
||||
return AlgorithmType.AES;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
* @param encodeType 加密后的编码格式
|
||||
*/
|
||||
@Override
|
||||
public String encrypt(String value, EncodeType encodeType) {
|
||||
if (encodeType == EncodeType.HEX) {
|
||||
return EncryptUtils.encryptByAesHex(value, context.getPassword());
|
||||
} else {
|
||||
return EncryptUtils.encryptByAes(value, context.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
*/
|
||||
@Override
|
||||
public String decrypt(String value) {
|
||||
return EncryptUtils.decryptByAes(value, context.getPassword());
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.ruoyi.common.encrypt.core.encryptor;
|
||||
|
||||
import com.ruoyi.common.encrypt.core.EncryptContext;
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import com.ruoyi.common.encrypt.utils.EncryptUtils;
|
||||
|
||||
/**
|
||||
* Base64算法实现
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
public class Base64Encryptor extends AbstractEncryptor {
|
||||
|
||||
public Base64Encryptor(EncryptContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前算法
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmType algorithm() {
|
||||
return AlgorithmType.BASE64;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
* @param encodeType 加密后的编码格式
|
||||
*/
|
||||
@Override
|
||||
public String encrypt(String value, EncodeType encodeType) {
|
||||
return EncryptUtils.encryptByBase64(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
*/
|
||||
@Override
|
||||
public String decrypt(String value) {
|
||||
return EncryptUtils.decryptByBase64(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.ruoyi.common.encrypt.core.encryptor;
|
||||
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.encrypt.core.EncryptContext;
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import com.ruoyi.common.encrypt.utils.EncryptUtils;
|
||||
|
||||
|
||||
/**
|
||||
* RSA算法实现
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
public class RsaEncryptor extends AbstractEncryptor {
|
||||
|
||||
private final EncryptContext context;
|
||||
|
||||
public RsaEncryptor(EncryptContext context) {
|
||||
super(context);
|
||||
String privateKey = context.getPrivateKey();
|
||||
String publicKey = context.getPublicKey();
|
||||
if (StringUtils.isAnyEmpty(privateKey, publicKey)) {
|
||||
throw new IllegalArgumentException("RSA公私钥均需要提供,公钥加密,私钥解密。");
|
||||
}
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前算法
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmType algorithm() {
|
||||
return AlgorithmType.RSA;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
* @param encodeType 加密后的编码格式
|
||||
*/
|
||||
@Override
|
||||
public String encrypt(String value, EncodeType encodeType) {
|
||||
if (encodeType == EncodeType.HEX) {
|
||||
return EncryptUtils.encryptByRsaHex(value, context.getPublicKey());
|
||||
} else {
|
||||
return EncryptUtils.encryptByRsa(value, context.getPublicKey());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
*/
|
||||
@Override
|
||||
public String decrypt(String value) {
|
||||
return EncryptUtils.decryptByRsa(value, context.getPrivateKey());
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.ruoyi.common.encrypt.core.encryptor;
|
||||
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.encrypt.core.EncryptContext;
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import com.ruoyi.common.encrypt.utils.EncryptUtils;
|
||||
|
||||
/**
|
||||
* sm2算法实现
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
public class Sm2Encryptor extends AbstractEncryptor {
|
||||
|
||||
private final EncryptContext context;
|
||||
|
||||
public Sm2Encryptor(EncryptContext context) {
|
||||
super(context);
|
||||
String privateKey = context.getPrivateKey();
|
||||
String publicKey = context.getPublicKey();
|
||||
if (StringUtils.isAnyEmpty(privateKey, publicKey)) {
|
||||
throw new IllegalArgumentException("SM2公私钥均需要提供,公钥加密,私钥解密。");
|
||||
}
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前算法
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmType algorithm() {
|
||||
return AlgorithmType.SM2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
* @param encodeType 加密后的编码格式
|
||||
*/
|
||||
@Override
|
||||
public String encrypt(String value, EncodeType encodeType) {
|
||||
if (encodeType == EncodeType.HEX) {
|
||||
return EncryptUtils.encryptBySm2Hex(value, context.getPublicKey());
|
||||
} else {
|
||||
return EncryptUtils.encryptBySm2(value, context.getPublicKey());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
*/
|
||||
@Override
|
||||
public String decrypt(String value) {
|
||||
return EncryptUtils.decryptBySm2(value, context.getPrivateKey());
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.ruoyi.common.encrypt.core.encryptor;
|
||||
|
||||
import com.ruoyi.common.encrypt.core.EncryptContext;
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import com.ruoyi.common.encrypt.utils.EncryptUtils;
|
||||
|
||||
/**
|
||||
* sm4算法实现
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
public class Sm4Encryptor extends AbstractEncryptor {
|
||||
|
||||
private final EncryptContext context;
|
||||
|
||||
public Sm4Encryptor(EncryptContext context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前算法
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmType algorithm() {
|
||||
return AlgorithmType.SM4;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
* @param encodeType 加密后的编码格式
|
||||
*/
|
||||
@Override
|
||||
public String encrypt(String value, EncodeType encodeType) {
|
||||
if (encodeType == EncodeType.HEX) {
|
||||
return EncryptUtils.encryptBySm4Hex(value, context.getPassword());
|
||||
} else {
|
||||
return EncryptUtils.encryptBySm4(value, context.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param value 待加密字符串
|
||||
*/
|
||||
@Override
|
||||
public String decrypt(String value) {
|
||||
return EncryptUtils.decryptBySm4(value, context.getPassword());
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.ruoyi.common.encrypt.enumd;
|
||||
|
||||
import com.ruoyi.common.encrypt.core.encryptor.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import com.ruoyi.common.encrypt.core.encryptor.*;
|
||||
|
||||
/**
|
||||
* 算法名称
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AlgorithmType {
|
||||
|
||||
/**
|
||||
* 默认走yml配置
|
||||
*/
|
||||
DEFAULT(null),
|
||||
|
||||
/**
|
||||
* base64
|
||||
*/
|
||||
BASE64(Base64Encryptor.class),
|
||||
|
||||
/**
|
||||
* aes
|
||||
*/
|
||||
AES(AesEncryptor.class),
|
||||
|
||||
/**
|
||||
* rsa
|
||||
*/
|
||||
RSA(RsaEncryptor.class),
|
||||
|
||||
/**
|
||||
* sm2
|
||||
*/
|
||||
SM2(Sm2Encryptor.class),
|
||||
|
||||
/**
|
||||
* sm4
|
||||
*/
|
||||
SM4(Sm4Encryptor.class);
|
||||
|
||||
private final Class<? extends AbstractEncryptor> clazz;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.ruoyi.common.encrypt.enumd;
|
||||
|
||||
/**
|
||||
* 编码类型
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
public enum EncodeType {
|
||||
|
||||
/**
|
||||
* 默认使用yml配置
|
||||
*/
|
||||
DEFAULT,
|
||||
|
||||
/**
|
||||
* base64编码
|
||||
*/
|
||||
BASE64,
|
||||
|
||||
/**
|
||||
* 16进制编码
|
||||
*/
|
||||
HEX;
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package com.ruoyi.common.encrypt.filter;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import com.ruoyi.common.core.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.encrypt.annotation.ApiEncrypt;
|
||||
import com.ruoyi.common.encrypt.properties.ApiDecryptProperties;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.HandlerExecutionChain;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Crypto 过滤器
|
||||
*
|
||||
* @author wdhcr
|
||||
*/
|
||||
public class CryptoFilter implements Filter {
|
||||
private final ApiDecryptProperties properties;
|
||||
|
||||
public CryptoFilter(ApiDecryptProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest servletRequest = (HttpServletRequest) request;
|
||||
HttpServletResponse servletResponse = (HttpServletResponse) response;
|
||||
// 获取加密注解
|
||||
ApiEncrypt apiEncrypt = this.getApiEncryptAnnotation(servletRequest);
|
||||
boolean responseFlag = apiEncrypt != null && apiEncrypt.response();
|
||||
ServletRequest requestWrapper = null;
|
||||
ServletResponse responseWrapper = null;
|
||||
EncryptResponseBodyWrapper responseBodyWrapper = null;
|
||||
|
||||
// 是否为 json 请求
|
||||
if (StringUtils.startsWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE)) {
|
||||
// 是否为 put 或者 post 请求
|
||||
if (HttpMethod.PUT.matches(servletRequest.getMethod()) || HttpMethod.POST.matches(servletRequest.getMethod())) {
|
||||
// 是否存在加密标头
|
||||
String headerValue = servletRequest.getHeader(properties.getHeaderFlag());
|
||||
if (StringUtils.isNotBlank(headerValue)) {
|
||||
// 请求解密
|
||||
requestWrapper = new DecryptRequestBodyWrapper(servletRequest, headerValue);
|
||||
} else {
|
||||
// 是否有注解,有就报错,没有放行
|
||||
if (ObjectUtil.isNotNull(apiEncrypt)) {
|
||||
HandlerExceptionResolver exceptionResolver = SpringUtils.getBean("handlerExceptionResolver", HandlerExceptionResolver.class);
|
||||
exceptionResolver.resolveException(
|
||||
servletRequest, servletResponse, null,
|
||||
new ServiceException("没有访问权限,请联系管理员授权", HttpStatus.FORBIDDEN));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 判断是否响应加密
|
||||
if (responseFlag) {
|
||||
responseBodyWrapper = new EncryptResponseBodyWrapper(servletResponse);
|
||||
responseWrapper = responseBodyWrapper;
|
||||
}
|
||||
|
||||
chain.doFilter(
|
||||
ObjectUtil.defaultIfNull(requestWrapper, request),
|
||||
ObjectUtil.defaultIfNull(responseWrapper, response));
|
||||
|
||||
if (responseFlag) {
|
||||
servletResponse.reset();
|
||||
// 对原始内容加密
|
||||
String encryptContent = responseBodyWrapper.getEncryptContent(
|
||||
servletResponse, properties.getPublicKey(), properties.getHeaderFlag());
|
||||
// 对加密后的内容写出
|
||||
servletResponse.getWriter().write(encryptContent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 ApiEncrypt 注解
|
||||
*/
|
||||
private ApiEncrypt getApiEncryptAnnotation(HttpServletRequest servletRequest) {
|
||||
RequestMappingHandlerMapping handlerMapping = SpringUtils.getBean("requestMappingHandlerMapping", RequestMappingHandlerMapping.class);
|
||||
// 获取注解
|
||||
try {
|
||||
HandlerExecutionChain mappingHandler = handlerMapping.getHandler(servletRequest);
|
||||
if (ObjectUtil.isNotNull(mappingHandler)) {
|
||||
Object handler = mappingHandler.getHandler();
|
||||
if (ObjectUtil.isNotNull(handler)) {
|
||||
// 从handler获取注解
|
||||
if (handler instanceof HandlerMethod handlerMethod) {
|
||||
return handlerMethod.getMethodAnnotation(ApiEncrypt.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.ruoyi.common.encrypt.filter;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import com.ruoyi.common.encrypt.utils.EncryptUtils;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import jakarta.servlet.ReadListener;
|
||||
import jakarta.servlet.ServletInputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequestWrapper;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 解密请求参数工具类
|
||||
*
|
||||
* @author wdhcr
|
||||
*/
|
||||
public class DecryptRequestBodyWrapper extends HttpServletRequestWrapper {
|
||||
|
||||
private final byte[] body;
|
||||
|
||||
public DecryptRequestBodyWrapper(HttpServletRequest request, String privateKey) throws IOException {
|
||||
super(request);
|
||||
// 获取 AES 密码 采用 RSA 加密
|
||||
String privateKeyValue = RedisUtils.getCacheMapValue("loginRsa", privateKey);
|
||||
|
||||
byte[] readBytes = IoUtil.readBytes(request.getInputStream(), false);
|
||||
String requestBody = new String(readBytes, StandardCharsets.UTF_8);
|
||||
// 解密 body 采用 AES 加密
|
||||
String decryptBody = EncryptUtils.decryptByRsa(requestBody, privateKeyValue);
|
||||
body = UriUtils.decode(decryptBody, StandardCharsets.UTF_8).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BufferedReader getReader() {
|
||||
return new BufferedReader(new InputStreamReader(getInputStream()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getContentLength() {
|
||||
return body.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getContentLengthLong() {
|
||||
return body.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return MediaType.APPLICATION_JSON_VALUE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ServletInputStream getInputStream() {
|
||||
final ByteArrayInputStream bais = new ByteArrayInputStream(body);
|
||||
return new ServletInputStream() {
|
||||
@Override
|
||||
public int read() {
|
||||
return bais.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() {
|
||||
return body.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadListener(ReadListener readListener) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package com.ruoyi.common.encrypt.filter;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.ruoyi.common.encrypt.utils.EncryptUtils;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.WriteListener;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpServletResponseWrapper;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 加密响应参数包装类
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
public class EncryptResponseBodyWrapper extends HttpServletResponseWrapper {
|
||||
|
||||
private final ByteArrayOutputStream byteArrayOutputStream;
|
||||
private final ServletOutputStream servletOutputStream;
|
||||
private final PrintWriter printWriter;
|
||||
|
||||
public EncryptResponseBodyWrapper(HttpServletResponse response) throws IOException {
|
||||
super(response);
|
||||
this.byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
this.servletOutputStream = this.getOutputStream();
|
||||
this.printWriter = new PrintWriter(new OutputStreamWriter(byteArrayOutputStream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getWriter() {
|
||||
return printWriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushBuffer() throws IOException {
|
||||
if (servletOutputStream != null) {
|
||||
servletOutputStream.flush();
|
||||
}
|
||||
if (printWriter != null) {
|
||||
printWriter.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
byteArrayOutputStream.reset();
|
||||
}
|
||||
|
||||
public byte[] getResponseData() throws IOException {
|
||||
flushBuffer();
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
|
||||
public String getContent() throws IOException {
|
||||
flushBuffer();
|
||||
return byteArrayOutputStream.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加密内容
|
||||
*
|
||||
* @param servletResponse response
|
||||
* @param publicKey RSA公钥 (用于加密 AES 秘钥)
|
||||
* @param headerFlag 请求头标志
|
||||
* @return 加密内容
|
||||
* @throws IOException
|
||||
*/
|
||||
public String getEncryptContent(HttpServletResponse servletResponse, String publicKey, String headerFlag) throws IOException {
|
||||
// 生成秘钥
|
||||
String aesPassword = RandomUtil.randomString(32);
|
||||
// 秘钥使用 Base64 编码
|
||||
String encryptAes = EncryptUtils.encryptByBase64(aesPassword);
|
||||
// Rsa 公钥加密 Base64 编码
|
||||
String encryptPassword = EncryptUtils.encryptByRsa(encryptAes, publicKey);
|
||||
|
||||
// 设置响应头
|
||||
servletResponse.setHeader(headerFlag, encryptPassword);
|
||||
servletResponse.setHeader("Access-Control-Allow-Origin", "*");
|
||||
servletResponse.setHeader("Access-Control-Allow-Methods", "*");
|
||||
servletResponse.setCharacterEncoding(StandardCharsets.UTF_8.toString());
|
||||
|
||||
// 获取原始内容
|
||||
String originalBody = this.getContent();
|
||||
// 对内容进行加密
|
||||
return EncryptUtils.encryptByAes(originalBody, aesPassword);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletOutputStream getOutputStream() throws IOException {
|
||||
return new ServletOutputStream() {
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWriteListener(WriteListener writeListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
byteArrayOutputStream.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
byteArrayOutputStream.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
byteArrayOutputStream.write(b, off, len);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package com.ruoyi.common.encrypt.interceptor;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.executor.resultset.ResultSetHandler;
|
||||
import org.apache.ibatis.plugin.*;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.encrypt.annotation.EncryptField;
|
||||
import com.ruoyi.common.encrypt.core.EncryptContext;
|
||||
import com.ruoyi.common.encrypt.core.EncryptorManager;
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import com.ruoyi.common.encrypt.properties.EncryptorProperties;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Statement;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 出参解密拦截器
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Intercepts({@Signature(
|
||||
type = ResultSetHandler.class,
|
||||
method = "handleResultSets",
|
||||
args = {Statement.class})
|
||||
})
|
||||
@AllArgsConstructor
|
||||
public class MybatisDecryptInterceptor implements Interceptor {
|
||||
|
||||
private final EncryptorManager encryptorManager;
|
||||
private final EncryptorProperties defaultProperties;
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
// 获取执行mysql执行结果
|
||||
Object result = invocation.proceed();
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
decryptHandler(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密对象
|
||||
*
|
||||
* @param sourceObject 待加密对象
|
||||
*/
|
||||
private void decryptHandler(Object sourceObject) {
|
||||
if (ObjectUtil.isNull(sourceObject)) {
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof Map<?, ?> map) {
|
||||
new HashSet<>(map.values()).forEach(this::decryptHandler);
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof List<?> list) {
|
||||
if(CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
// 判断第一个元素是否含有注解。如果没有直接返回,提高效率
|
||||
Object firstItem = list.get(0);
|
||||
if (ObjectUtil.isNull(firstItem) || CollUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) {
|
||||
return;
|
||||
}
|
||||
list.forEach(this::decryptHandler);
|
||||
return;
|
||||
}
|
||||
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
field.set(sourceObject, this.decryptField(Convert.toStr(field.get(sourceObject)), field));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理解密字段时出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段值进行加密。通过字段的批注注册新的加密算法
|
||||
*
|
||||
* @param value 待加密的值
|
||||
* @param field 待加密字段
|
||||
* @return 加密后结果
|
||||
*/
|
||||
private String decryptField(String value, Field field) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return null;
|
||||
}
|
||||
EncryptField encryptField = field.getAnnotation(EncryptField.class);
|
||||
EncryptContext encryptContext = new EncryptContext();
|
||||
encryptContext.setAlgorithm(encryptField.algorithm() == AlgorithmType.DEFAULT ? defaultProperties.getAlgorithm() : encryptField.algorithm());
|
||||
encryptContext.setEncode(encryptField.encode() == EncodeType.DEFAULT ? defaultProperties.getEncode() : encryptField.encode());
|
||||
encryptContext.setPassword(StringUtils.isBlank(encryptField.password()) ? defaultProperties.getPassword() : encryptField.password());
|
||||
encryptContext.setPrivateKey(StringUtils.isBlank(encryptField.privateKey()) ? defaultProperties.getPrivateKey() : encryptField.privateKey());
|
||||
encryptContext.setPublicKey(StringUtils.isBlank(encryptField.publicKey()) ? defaultProperties.getPublicKey() : encryptField.publicKey());
|
||||
return this.encryptorManager.decrypt(value, encryptContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
return Plugin.wrap(target, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperties(Properties properties) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package com.ruoyi.common.encrypt.interceptor;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.encrypt.annotation.EncryptField;
|
||||
import com.ruoyi.common.encrypt.core.EncryptContext;
|
||||
import com.ruoyi.common.encrypt.core.EncryptorManager;
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import com.ruoyi.common.encrypt.properties.EncryptorProperties;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.executor.parameter.ParameterHandler;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.plugin.Intercepts;
|
||||
import org.apache.ibatis.plugin.Invocation;
|
||||
import org.apache.ibatis.plugin.Signature;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 入参加密拦截器
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Intercepts({@Signature(
|
||||
type = ParameterHandler.class,
|
||||
method = "setParameters",
|
||||
args = {PreparedStatement.class})
|
||||
})
|
||||
@AllArgsConstructor
|
||||
public class MybatisEncryptInterceptor implements Interceptor {
|
||||
|
||||
private final EncryptorManager encryptorManager;
|
||||
private final EncryptorProperties defaultProperties;
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
return invocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
if (target instanceof ParameterHandler parameterHandler) {
|
||||
// 进行加密操作
|
||||
Object parameterObject = parameterHandler.getParameterObject();
|
||||
if (ObjectUtil.isNotNull(parameterObject) && !(parameterObject instanceof String)) {
|
||||
this.encryptHandler(parameterObject);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密对象
|
||||
*
|
||||
* @param sourceObject 待加密对象
|
||||
*/
|
||||
private void encryptHandler(Object sourceObject) {
|
||||
if (ObjectUtil.isNull(sourceObject)) {
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof Map<?, ?> map) {
|
||||
new HashSet<>(map.values()).forEach(this::encryptHandler);
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof List<?> list) {
|
||||
if(CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
// 判断第一个元素是否含有注解。如果没有直接返回,提高效率
|
||||
Object firstItem = list.get(0);
|
||||
if (ObjectUtil.isNull(firstItem) || CollUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) {
|
||||
return;
|
||||
}
|
||||
list.forEach(this::encryptHandler);
|
||||
return;
|
||||
}
|
||||
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
field.set(sourceObject, this.encryptField(Convert.toStr(field.get(sourceObject)), field));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理加密字段时出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段值进行加密。通过字段的批注注册新的加密算法
|
||||
*
|
||||
* @param value 待加密的值
|
||||
* @param field 待加密字段
|
||||
* @return 加密后结果
|
||||
*/
|
||||
private String encryptField(String value, Field field) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return null;
|
||||
}
|
||||
EncryptField encryptField = field.getAnnotation(EncryptField.class);
|
||||
EncryptContext encryptContext = new EncryptContext();
|
||||
encryptContext.setAlgorithm(encryptField.algorithm() == AlgorithmType.DEFAULT ? defaultProperties.getAlgorithm() : encryptField.algorithm());
|
||||
encryptContext.setEncode(encryptField.encode() == EncodeType.DEFAULT ? defaultProperties.getEncode() : encryptField.encode());
|
||||
encryptContext.setPassword(StringUtils.isBlank(encryptField.password()) ? defaultProperties.getPassword() : encryptField.password());
|
||||
encryptContext.setPrivateKey(StringUtils.isBlank(encryptField.privateKey()) ? defaultProperties.getPrivateKey() : encryptField.privateKey());
|
||||
encryptContext.setPublicKey(StringUtils.isBlank(encryptField.publicKey()) ? defaultProperties.getPublicKey() : encryptField.publicKey());
|
||||
return this.encryptorManager.encrypt(value, encryptContext);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setProperties(Properties properties) {
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.ruoyi.common.encrypt.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* api解密属性配置类
|
||||
* @author wdhcr
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "api-decrypt")
|
||||
public class ApiDecryptProperties {
|
||||
|
||||
/**
|
||||
* 加密开关
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 头部标识
|
||||
*/
|
||||
private String headerFlag;
|
||||
|
||||
/**
|
||||
* 响应加密公钥
|
||||
*/
|
||||
private String publicKey;
|
||||
|
||||
/**
|
||||
* 请求解密私钥
|
||||
*/
|
||||
private String privateKey;
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.ruoyi.common.encrypt.properties;
|
||||
|
||||
import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* 加解密属性配置类
|
||||
*
|
||||
* @author 老马
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "mybatis-encryptor")
|
||||
public class EncryptorProperties {
|
||||
|
||||
/**
|
||||
* 过滤开关
|
||||
*/
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 默认算法
|
||||
*/
|
||||
private AlgorithmType algorithm;
|
||||
|
||||
/**
|
||||
* 安全秘钥
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 公钥
|
||||
*/
|
||||
private String publicKey;
|
||||
|
||||
/**
|
||||
* 私钥
|
||||
*/
|
||||
private String privateKey;
|
||||
|
||||
/**
|
||||
* 编码方式,base64/hex
|
||||
*/
|
||||
private EncodeType encode;
|
||||
|
||||
}
|
@ -0,0 +1,311 @@
|
||||
package com.ruoyi.common.encrypt.utils;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.SmUtil;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import cn.hutool.crypto.asymmetric.SM2;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 安全相关工具类
|
||||
*
|
||||
* @author 老马
|
||||
*/
|
||||
public class EncryptUtils {
|
||||
/**
|
||||
* 公钥
|
||||
*/
|
||||
public static final String PUBLIC_KEY = "publicKey";
|
||||
/**
|
||||
* 私钥
|
||||
*/
|
||||
public static final String PRIVATE_KEY = "privateKey";
|
||||
|
||||
/**
|
||||
* Base64加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @return 加密后字符串
|
||||
*/
|
||||
public static String encryptByBase64(String data) {
|
||||
return Base64.encode(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64解密
|
||||
*
|
||||
* @param data 待解密数据
|
||||
* @return 解密后字符串
|
||||
*/
|
||||
public static String decryptByBase64(String data) {
|
||||
return Base64.decodeStr(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* AES加密
|
||||
*
|
||||
* @param data 待解密数据
|
||||
* @param password 秘钥字符串
|
||||
* @return 加密后字符串, 采用Base64编码
|
||||
*/
|
||||
public static String encryptByAes(String data, String password) {
|
||||
if (StrUtil.isBlank(password)) {
|
||||
throw new IllegalArgumentException("AES需要传入秘钥信息");
|
||||
}
|
||||
// aes算法的秘钥要求是16位、24位、32位
|
||||
int[] array = {16, 24, 32};
|
||||
if (!ArrayUtil.contains(array, password.length())) {
|
||||
throw new IllegalArgumentException("AES秘钥长度要求为16位、24位、32位");
|
||||
}
|
||||
return SecureUtil.aes(password.getBytes(StandardCharsets.UTF_8)).encryptBase64(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* AES加密
|
||||
*
|
||||
* @param data 待解密数据
|
||||
* @param password 秘钥字符串
|
||||
* @return 加密后字符串, 采用Hex编码
|
||||
*/
|
||||
public static String encryptByAesHex(String data, String password) {
|
||||
if (StrUtil.isBlank(password)) {
|
||||
throw new IllegalArgumentException("AES需要传入秘钥信息");
|
||||
}
|
||||
// aes算法的秘钥要求是16位、24位、32位
|
||||
int[] array = {16, 24, 32};
|
||||
if (!ArrayUtil.contains(array, password.length())) {
|
||||
throw new IllegalArgumentException("AES秘钥长度要求为16位、24位、32位");
|
||||
}
|
||||
return SecureUtil.aes(password.getBytes(StandardCharsets.UTF_8)).encryptHex(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* AES解密
|
||||
*
|
||||
* @param data 待解密数据
|
||||
* @param password 秘钥字符串
|
||||
* @return 解密后字符串
|
||||
*/
|
||||
public static String decryptByAes(String data, String password) {
|
||||
if (StrUtil.isBlank(password)) {
|
||||
throw new IllegalArgumentException("AES需要传入秘钥信息");
|
||||
}
|
||||
// aes算法的秘钥要求是16位、24位、32位
|
||||
int[] array = {16, 24, 32};
|
||||
if (!ArrayUtil.contains(array, password.length())) {
|
||||
throw new IllegalArgumentException("AES秘钥长度要求为16位、24位、32位");
|
||||
}
|
||||
return SecureUtil.aes(password.getBytes(StandardCharsets.UTF_8)).decryptStr(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* sm4加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param password 秘钥字符串
|
||||
* @return 加密后字符串, 采用Base64编码
|
||||
*/
|
||||
public static String encryptBySm4(String data, String password) {
|
||||
if (StrUtil.isBlank(password)) {
|
||||
throw new IllegalArgumentException("SM4需要传入秘钥信息");
|
||||
}
|
||||
// sm4算法的秘钥要求是16位长度
|
||||
int sm4PasswordLength = 16;
|
||||
if (sm4PasswordLength != password.length()) {
|
||||
throw new IllegalArgumentException("SM4秘钥长度要求为16位");
|
||||
}
|
||||
return SmUtil.sm4(password.getBytes(StandardCharsets.UTF_8)).encryptBase64(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* sm4加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param password 秘钥字符串
|
||||
* @return 加密后字符串, 采用Base64编码
|
||||
*/
|
||||
public static String encryptBySm4Hex(String data, String password) {
|
||||
if (StrUtil.isBlank(password)) {
|
||||
throw new IllegalArgumentException("SM4需要传入秘钥信息");
|
||||
}
|
||||
// sm4算法的秘钥要求是16位长度
|
||||
int sm4PasswordLength = 16;
|
||||
if (sm4PasswordLength != password.length()) {
|
||||
throw new IllegalArgumentException("SM4秘钥长度要求为16位");
|
||||
}
|
||||
return SmUtil.sm4(password.getBytes(StandardCharsets.UTF_8)).encryptHex(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* sm4解密
|
||||
*
|
||||
* @param data 待解密数据
|
||||
* @param password 秘钥字符串
|
||||
* @return 解密后字符串
|
||||
*/
|
||||
public static String decryptBySm4(String data, String password) {
|
||||
if (StrUtil.isBlank(password)) {
|
||||
throw new IllegalArgumentException("SM4需要传入秘钥信息");
|
||||
}
|
||||
// sm4算法的秘钥要求是16位长度
|
||||
int sm4PasswordLength = 16;
|
||||
if (sm4PasswordLength != password.length()) {
|
||||
throw new IllegalArgumentException("SM4秘钥长度要求为16位");
|
||||
}
|
||||
return SmUtil.sm4(password.getBytes(StandardCharsets.UTF_8)).decryptStr(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 产生sm2加解密需要的公钥和私钥
|
||||
*
|
||||
* @return 公私钥Map
|
||||
*/
|
||||
public static Map<String, String> generateSm2Key() {
|
||||
Map<String, String> keyMap = new HashMap<>(2);
|
||||
SM2 sm2 = SmUtil.sm2();
|
||||
keyMap.put(PRIVATE_KEY, sm2.getPrivateKeyBase64());
|
||||
keyMap.put(PUBLIC_KEY, sm2.getPublicKeyBase64());
|
||||
return keyMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* sm2公钥加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param publicKey 公钥
|
||||
* @return 加密后字符串, 采用Base64编码
|
||||
*/
|
||||
public static String encryptBySm2(String data, String publicKey) {
|
||||
if (StrUtil.isBlank(publicKey)) {
|
||||
throw new IllegalArgumentException("SM2需要传入公钥进行加密");
|
||||
}
|
||||
SM2 sm2 = SmUtil.sm2(null, publicKey);
|
||||
return sm2.encryptBase64(data, StandardCharsets.UTF_8, KeyType.PublicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* sm2公钥加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param publicKey 公钥
|
||||
* @return 加密后字符串, 采用Hex编码
|
||||
*/
|
||||
public static String encryptBySm2Hex(String data, String publicKey) {
|
||||
if (StrUtil.isBlank(publicKey)) {
|
||||
throw new IllegalArgumentException("SM2需要传入公钥进行加密");
|
||||
}
|
||||
SM2 sm2 = SmUtil.sm2(null, publicKey);
|
||||
return sm2.encryptHex(data, StandardCharsets.UTF_8, KeyType.PublicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* sm2私钥解密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param privateKey 私钥
|
||||
* @return 解密后字符串
|
||||
*/
|
||||
public static String decryptBySm2(String data, String privateKey) {
|
||||
if (StrUtil.isBlank(privateKey)) {
|
||||
throw new IllegalArgumentException("SM2需要传入私钥进行解密");
|
||||
}
|
||||
SM2 sm2 = SmUtil.sm2(privateKey, null);
|
||||
return sm2.decryptStr(data, KeyType.PrivateKey, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 产生RSA加解密需要的公钥和私钥
|
||||
*
|
||||
* @return 公私钥Map
|
||||
*/
|
||||
public static Map<String, String> generateRsaKey() {
|
||||
Map<String, String> keyMap = new HashMap<>(2);
|
||||
RSA rsa = SecureUtil.rsa();
|
||||
keyMap.put(PRIVATE_KEY, rsa.getPrivateKeyBase64());
|
||||
keyMap.put(PUBLIC_KEY, rsa.getPublicKeyBase64());
|
||||
return keyMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* rsa公钥加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param publicKey 公钥
|
||||
* @return 加密后字符串, 采用Base64编码
|
||||
*/
|
||||
public static String encryptByRsa(String data, String publicKey) {
|
||||
if (StrUtil.isBlank(publicKey)) {
|
||||
throw new IllegalArgumentException("RSA需要传入公钥进行加密");
|
||||
}
|
||||
RSA rsa = SecureUtil.rsa(null, publicKey);
|
||||
return rsa.encryptBase64(data, StandardCharsets.UTF_8, KeyType.PublicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* rsa公钥加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param publicKey 公钥
|
||||
* @return 加密后字符串, 采用Hex编码
|
||||
*/
|
||||
public static String encryptByRsaHex(String data, String publicKey) {
|
||||
if (StrUtil.isBlank(publicKey)) {
|
||||
throw new IllegalArgumentException("RSA需要传入公钥进行加密");
|
||||
}
|
||||
RSA rsa = SecureUtil.rsa(null, publicKey);
|
||||
return rsa.encryptHex(data, StandardCharsets.UTF_8, KeyType.PublicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* rsa私钥解密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param privateKey 私钥
|
||||
* @return 解密后字符串
|
||||
*/
|
||||
public static String decryptByRsa(String data, String privateKey) {
|
||||
if (StrUtil.isBlank(privateKey)) {
|
||||
throw new IllegalArgumentException("RSA需要传入私钥进行解密");
|
||||
}
|
||||
RSA rsa = SecureUtil.rsa(privateKey, null);
|
||||
return rsa.decryptStr(data, KeyType.PrivateKey, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* md5加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @return 加密后字符串, 采用Hex编码
|
||||
*/
|
||||
public static String encryptByMd5(String data) {
|
||||
return SecureUtil.md5(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* sha256加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @return 加密后字符串, 采用Hex编码
|
||||
*/
|
||||
public static String encryptBySha256(String data) {
|
||||
return SecureUtil.sha256(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* sm3加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @return 加密后字符串, 采用Hex编码
|
||||
*/
|
||||
public static String encryptBySm3(String data) {
|
||||
return SmUtil.sm3(data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,363 @@
|
||||
package com.ruoyi.common.encrypt.utils;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.security.*;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @NAME: RSAEncryptUtils
|
||||
* @AUTHOR: gaoly
|
||||
* @DATE: 2021/1/26 15:15
|
||||
* @DES:
|
||||
**/
|
||||
public class RSAUtils {
|
||||
/** */
|
||||
/**
|
||||
* 加密算法RSA
|
||||
*/
|
||||
public static final String KEY_ALGORITHM = "RSA";
|
||||
|
||||
/** */
|
||||
/**
|
||||
* 签名算法
|
||||
*/
|
||||
public static final String SIGNATURE_ALGORITHM = "MD5withRSA";
|
||||
|
||||
/** */
|
||||
/**
|
||||
* 获取公钥的key
|
||||
*/
|
||||
private static final String PUBLIC_KEY = "RSAPublicKey";
|
||||
|
||||
/** */
|
||||
/**
|
||||
* 获取私钥的key
|
||||
*/
|
||||
private static final String PRIVATE_KEY = "RSAPrivateKey";
|
||||
|
||||
/** */
|
||||
/**
|
||||
* RSA最大加密明文大小
|
||||
*/
|
||||
private static final int MAX_ENCRYPT_BLOCK = 117;
|
||||
|
||||
/** */
|
||||
/**
|
||||
* RSA最大解密密文大小
|
||||
*/
|
||||
private static final int MAX_DECRYPT_BLOCK = 128;
|
||||
|
||||
/** */
|
||||
/**
|
||||
* RSA 位数 如果采用2048 上面最大加密和最大解密则须填写: 245 256
|
||||
*/
|
||||
private static final int INITIALIZE_LENGTH = 1024;
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <p>
|
||||
* 生成密钥对(公钥和私钥)
|
||||
* </p>
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Map<String, Object> genKeyPair() throws Exception {
|
||||
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
|
||||
keyPairGen.initialize(INITIALIZE_LENGTH);
|
||||
KeyPair keyPair = keyPairGen.generateKeyPair();
|
||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
||||
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
|
||||
Map<String, Object> keyMap = new HashMap<String, Object>(2);
|
||||
keyMap.put(PUBLIC_KEY, publicKey);
|
||||
keyMap.put(PRIVATE_KEY, privateKey);
|
||||
return keyMap;
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <p>
|
||||
* 用私钥对信息生成数字签名
|
||||
* </p>
|
||||
*
|
||||
* @param data
|
||||
* 已加密数据
|
||||
* @param privateKey
|
||||
* 私钥(BASE64编码)
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String sign(byte[] data, String privateKey) throws Exception {
|
||||
byte[] keyBytes = Base64.decodeBase64(privateKey);
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
PrivateKey privateK = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
|
||||
signature.initSign(privateK);
|
||||
signature.update(data);
|
||||
return Base64.encodeBase64String(signature.sign());
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <p>
|
||||
* 校验数字签名
|
||||
* </p>
|
||||
*
|
||||
* @param data
|
||||
* 已加密数据
|
||||
* @param publicKey
|
||||
* 公钥(BASE64编码)
|
||||
* @param sign
|
||||
* 数字签名
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*
|
||||
*/
|
||||
public static boolean verify(byte[] data, String publicKey, String sign) throws Exception {
|
||||
byte[] keyBytes = Base64.decodeBase64(publicKey);
|
||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
PublicKey publicK = keyFactory.generatePublic(keySpec);
|
||||
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
|
||||
signature.initVerify(publicK);
|
||||
signature.update(data);
|
||||
return signature.verify(Base64.decodeBase64(sign));
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <P>
|
||||
* 私钥解密
|
||||
* </p>
|
||||
*
|
||||
* @param encryptedData
|
||||
* 已加密数据
|
||||
* @param privateKey
|
||||
* 私钥(BASE64编码)
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decryptByPrivateKey(byte[] encryptedData, String privateKey) throws Exception {
|
||||
byte[] keyBytes = Base64.decodeBase64(privateKey);
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
Key privateK = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
cipher.init(Cipher.DECRYPT_MODE, privateK);
|
||||
int inputLen = encryptedData.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
// 对数据分段解密
|
||||
while (inputLen - offSet > 0) {
|
||||
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offSet = i * MAX_DECRYPT_BLOCK;
|
||||
}
|
||||
byte[] decryptedData = out.toByteArray();
|
||||
out.close();
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <p>
|
||||
* 公钥解密
|
||||
* </p>
|
||||
*
|
||||
* @param encryptedData
|
||||
* 已加密数据
|
||||
* @param publicKey
|
||||
* 公钥(BASE64编码)
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decryptByPublicKey(byte[] encryptedData, String publicKey) throws Exception {
|
||||
byte[] keyBytes = Base64.decodeBase64(publicKey);
|
||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
Key publicK = keyFactory.generatePublic(x509KeySpec);
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
cipher.init(Cipher.DECRYPT_MODE, publicK);
|
||||
int inputLen = encryptedData.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
// 对数据分段解密
|
||||
while (inputLen - offSet > 0) {
|
||||
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offSet = i * MAX_DECRYPT_BLOCK;
|
||||
}
|
||||
byte[] decryptedData = out.toByteArray();
|
||||
out.close();
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <p>
|
||||
* 公钥加密
|
||||
* </p>
|
||||
*
|
||||
* @param data
|
||||
* 源数据
|
||||
* @param publicKey
|
||||
* 公钥(BASE64编码)
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception {
|
||||
byte[] keyBytes = Base64.decodeBase64(publicKey);
|
||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
Key publicK = keyFactory.generatePublic(x509KeySpec);
|
||||
// 对数据加密
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicK);
|
||||
int inputLen = data.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
// 对数据分段加密
|
||||
while (inputLen - offSet > 0) {
|
||||
if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(data, offSet, inputLen - offSet);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offSet = i * MAX_ENCRYPT_BLOCK;
|
||||
}
|
||||
byte[] encryptedData = out.toByteArray();
|
||||
out.close();
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <p>
|
||||
* 私钥加密
|
||||
* </p>
|
||||
*
|
||||
* @param data
|
||||
* 源数据
|
||||
* @param privateKey
|
||||
* 私钥(BASE64编码)
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] encryptByPrivateKey(byte[] data, String privateKey) throws Exception {
|
||||
byte[] keyBytes = Base64.decodeBase64(privateKey);
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
Key privateK = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, privateK);
|
||||
int inputLen = data.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
// 对数据分段加密
|
||||
while (inputLen - offSet > 0) {
|
||||
if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(data, offSet, inputLen - offSet);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offSet = i * MAX_ENCRYPT_BLOCK;
|
||||
}
|
||||
byte[] encryptedData = out.toByteArray();
|
||||
out.close();
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <p>
|
||||
* 获取私钥
|
||||
* </p>
|
||||
*
|
||||
* @param keyMap
|
||||
* 密钥对
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String getPrivateKey(Map<String, Object> keyMap) throws Exception {
|
||||
Key key = (Key) keyMap.get(PRIVATE_KEY);
|
||||
return Base64.encodeBase64String(key.getEncoded());
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* <p>
|
||||
* 获取公钥
|
||||
* </p>
|
||||
*
|
||||
* @param keyMap
|
||||
* 密钥对
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String getPublicKey(Map<String, Object> keyMap) throws Exception {
|
||||
Key key = (Key) keyMap.get(PUBLIC_KEY);
|
||||
return Base64.encodeBase64String(key.getEncoded());
|
||||
}
|
||||
|
||||
/**
|
||||
* java端公钥加密
|
||||
*/
|
||||
public static String encryptedDataOnJava(String data, String PUBLICKEY) {
|
||||
try {
|
||||
data = Base64.encodeBase64String(encryptByPublicKey(data.getBytes(), PUBLICKEY));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* java端私钥解密
|
||||
*/
|
||||
public static String decryptDataOnJava(String data, String PRIVATEKEY) {
|
||||
String temp = "";
|
||||
try {
|
||||
byte[] rs = Base64.decodeBase64(data);
|
||||
temp = new String(RSAUtils.decryptByPrivateKey(rs, PRIVATEKEY),"UTF-8");
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
com.ruoyi.common.encrypt.config.EncryptorAutoConfiguration
|
||||
com.ruoyi.common.encrypt.config.ApiDecryptAutoConfiguration
|
||||
|
@ -98,9 +98,30 @@ public class CellMergeStrategy extends AbstractMergeStrategy {
|
||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex - 1, colNum, colNum));
|
||||
}
|
||||
map.put(field, new RepeatCell(val, i));
|
||||
} else if (i == list.size() - 1) {
|
||||
if (i > repeatCell.getCurrent()) {
|
||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum));
|
||||
} else if (j == 0) {
|
||||
if (i == list.size() - 1) {
|
||||
if (i > repeatCell.getCurrent()) {
|
||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 判断前面的是否合并了
|
||||
RepeatCell firstCell = map.get(mergeFields.get(0));
|
||||
if (repeatCell.getCurrent() != firstCell.getCurrent()) {
|
||||
if (i == list.size() - 1) {
|
||||
if (i > repeatCell.getCurrent()) {
|
||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum));
|
||||
}
|
||||
} else if (repeatCell.getCurrent() < firstCell.getCurrent()) {
|
||||
if (i - repeatCell.getCurrent() > 1) {
|
||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex - 1, colNum, colNum));
|
||||
}
|
||||
map.put(field, new RepeatCell(val, i));
|
||||
}
|
||||
} else if (i == list.size() - 1) {
|
||||
if (i > repeatCell.getCurrent()) {
|
||||
cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.alibaba.excel.util.ClassUtils;
|
||||
import com.alibaba.excel.write.handler.SheetWriteHandler;
|
||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
||||
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
@ -99,15 +100,16 @@ public class ExcelDownHandler implements SheetWriteHandler {
|
||||
ExcelDictFormat format = field.getDeclaredAnnotation(ExcelDictFormat.class);
|
||||
String dictType = format.dictType();
|
||||
String converterExp = format.readConverterExp();
|
||||
if (StrUtil.isNotBlank(dictType)) {
|
||||
if (StringUtils.isNotBlank(dictType)) {
|
||||
// 如果传递了字典名,则依据字典建立下拉
|
||||
Collection<String> values = Optional.ofNullable(dictService.getAllDictByDictType(dictType))
|
||||
.orElseThrow(() -> new ServiceException(String.format("字典 %s 不存在", dictType)))
|
||||
.values();
|
||||
options = new ArrayList<>(values);
|
||||
} else if (StrUtil.isNotBlank(converterExp)) {
|
||||
} else if (StringUtils.isNotBlank(converterExp)) {
|
||||
// 如果指定了确切的值,则直接解析确切的值
|
||||
options = StrUtil.split(converterExp, format.separator(), true, true);
|
||||
List<String> strList = StringUtils.splitList(converterExp, format.separator());
|
||||
options = StreamUtils.toList(strList, s -> StringUtils.split(s, "=")[1]);
|
||||
}
|
||||
} else if (field.isAnnotationPresent(ExcelEnumFormat.class)) {
|
||||
// 否则如果指定了@ExcelEnumFormat,则使用枚举的逻辑
|
||||
|
@ -269,6 +269,27 @@ public class ExcelUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 多sheet模板导出 模板格式为 {key.属性}
|
||||
*
|
||||
* @param filename 文件名
|
||||
* @param templatePath 模板路径 resource 目录下的路径包括模板文件名
|
||||
* 例如: excel/temp.xlsx
|
||||
* 重点: 模板文件必须放置到启动类对应的 resource 目录下
|
||||
* @param data 模板需要的数据
|
||||
* @param response 响应体
|
||||
*/
|
||||
public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String filename, String templatePath, HttpServletResponse response) {
|
||||
try {
|
||||
resetResponse(filename, response);
|
||||
ServletOutputStream os = response.getOutputStream();
|
||||
exportTemplateMultiSheet(data, templatePath, os);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出Excel异常");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 多表多数据模板导出 模板格式为 {key.属性}
|
||||
*
|
||||
@ -303,6 +324,42 @@ public class ExcelUtil {
|
||||
excelWriter.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* 多sheet模板导出 模板格式为 {key.属性}
|
||||
*
|
||||
* @param templatePath 模板路径 resource 目录下的路径包括模板文件名
|
||||
* 例如: excel/temp.xlsx
|
||||
* 重点: 模板文件必须放置到启动类对应的 resource 目录下
|
||||
* @param data 模板需要的数据
|
||||
* @param os 输出流
|
||||
*/
|
||||
public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String templatePath, OutputStream os) {
|
||||
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
||||
ExcelWriter excelWriter = EasyExcel.write(os)
|
||||
.withTemplate(templateResource.getStream())
|
||||
.autoCloseStream(false)
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.build();
|
||||
if (CollUtil.isEmpty(data)) {
|
||||
throw new IllegalArgumentException("数据为空");
|
||||
}
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet(i).build();
|
||||
for (Map.Entry<String, Object> map : data.get(i).entrySet()) {
|
||||
// 设置列表后续还有数据
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||
if (map.getValue() instanceof Collection) {
|
||||
// 多表导出必须使用 FillWrapper
|
||||
excelWriter.fill(new FillWrapper(map.getKey(), (Collection<?>) map.getValue()), fillConfig, writeSheet);
|
||||
} else {
|
||||
excelWriter.fill(map.getValue(), writeSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
excelWriter.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置响应体
|
||||
*/
|
||||
|
@ -38,6 +38,20 @@
|
||||
<artifactId>powerjob-official-processors</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- EasyRetry client -->
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-job-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.ruoyi.common.job.config;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import com.aizuda.easy.retry.client.common.appender.EasyRetryLogbackAppender;
|
||||
import com.aizuda.easy.retry.client.common.event.EasyRetryStartingEvent;
|
||||
import com.aizuda.easy.retry.client.starter.EnableEasyRetry;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 启动定时任务
|
||||
*
|
||||
* @author dhb52
|
||||
* @since 2024/3/12
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@ConditionalOnProperty(prefix = "easy-retry", name = "enabled", havingValue = "true")
|
||||
@EnableScheduling
|
||||
@EnableEasyRetry(group = "${easy-retry.group-name}")
|
||||
public class EasyRetryConfig {
|
||||
|
||||
@EventListener(EasyRetryStartingEvent.class)
|
||||
public void onStarting(EasyRetryStartingEvent event) {
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
EasyRetryLogbackAppender<ILoggingEvent> ca = new EasyRetryLogbackAppender<>();
|
||||
ca.setName("easy_log_appender");
|
||||
ca.start();
|
||||
Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||
rootLogger.addAppender(ca);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
com.ruoyi.common.job.config.PowerJobConfig
|
||||
com.ruoyi.common.job.config.EasyRetryConfig
|
@ -27,11 +27,6 @@
|
||||
<artifactId>ruoyi-common-json</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -204,7 +204,7 @@ public class LogAspect {
|
||||
public boolean isFilterObject(final Object o) {
|
||||
Class<?> clazz = o.getClass();
|
||||
if (clazz.isArray()) {
|
||||
return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
|
||||
return MultipartFile.class.isAssignableFrom(clazz.getComponentType());
|
||||
} else if (Collection.class.isAssignableFrom(clazz)) {
|
||||
Collection collection = (Collection) o;
|
||||
for (Object value : collection) {
|
||||
|
@ -26,7 +26,7 @@ public class OperLogEvent implements Serializable {
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 操作模块
|
||||
|
34
ruoyi-common/ruoyi-common-mail/pom.xml
Normal file
34
ruoyi-common/ruoyi-common-mail/pom.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-common-mail</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-common-mail 邮件模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jakarta.mail</groupId>
|
||||
<artifactId>jakarta.mail-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>jakarta.mail</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,37 @@
|
||||
package com.ruoyi.common.mail.config;
|
||||
|
||||
import com.ruoyi.common.mail.config.properties.MailProperties;
|
||||
import com.ruoyi.common.mail.utils.MailAccount;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* JavaMail 配置
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(MailProperties.class)
|
||||
public class MailConfig {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "mail.enabled", havingValue = "true")
|
||||
public MailAccount mailAccount(MailProperties mailProperties) {
|
||||
MailAccount account = new MailAccount();
|
||||
account.setHost(mailProperties.getHost());
|
||||
account.setPort(mailProperties.getPort());
|
||||
account.setAuth(mailProperties.getAuth());
|
||||
account.setFrom(mailProperties.getFrom());
|
||||
account.setUser(mailProperties.getUser());
|
||||
account.setPass(mailProperties.getPass());
|
||||
account.setSocketFactoryPort(mailProperties.getPort());
|
||||
account.setStarttlsEnable(mailProperties.getStarttlsEnable());
|
||||
account.setSslEnable(mailProperties.getSslEnable());
|
||||
account.setTimeout(mailProperties.getTimeout());
|
||||
account.setConnectionTimeout(mailProperties.getConnectionTimeout());
|
||||
return account;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.ruoyi.common.mail.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* JavaMail 配置属性
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "mail")
|
||||
public class MailProperties {
|
||||
|
||||
/**
|
||||
* 过滤开关
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* SMTP服务器域名
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* SMTP服务端口
|
||||
*/
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 是否需要用户名密码验证
|
||||
*/
|
||||
private Boolean auth;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String pass;
|
||||
|
||||
/**
|
||||
* 发送方,遵循RFC-822标准
|
||||
*/
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* 使用 STARTTLS安全连接,STARTTLS是对纯文本通信协议的扩展。它将纯文本连接升级为加密连接(TLS或SSL), 而不是使用一个单独的加密通信端口。
|
||||
*/
|
||||
private Boolean starttlsEnable;
|
||||
|
||||
/**
|
||||
* 使用 SSL安全连接
|
||||
*/
|
||||
private Boolean sslEnable;
|
||||
|
||||
/**
|
||||
* SMTP超时时长,单位毫秒,缺省值不超时
|
||||
*/
|
||||
private Long timeout;
|
||||
|
||||
/**
|
||||
* Socket连接超时值,单位毫秒,缺省值不超时
|
||||
*/
|
||||
private Long connectionTimeout;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user