Commit ce3aefadd70b70516fd664bfcd580d67914276a8
1 parent
3fbb0b4c
移除 jasypt-spring-boot-starter 依赖,使用 hutool AES 替代
Showing
8 changed files
with
32 additions
and
50 deletions
yudao-dependencies/pom.xml
| @@ -43,7 +43,6 @@ | @@ -43,7 +43,6 @@ | ||
| 43 | <!-- Bpm 工作流相关 --> | 43 | <!-- Bpm 工作流相关 --> |
| 44 | <flowable.version>6.7.2</flowable.version> | 44 | <flowable.version>6.7.2</flowable.version> |
| 45 | <!-- 工具类相关 --> | 45 | <!-- 工具类相关 --> |
| 46 | - <jasypt-spring-boot-starter.version>3.0.4</jasypt-spring-boot-starter.version> | ||
| 47 | <lombok.version>1.18.24</lombok.version> | 46 | <lombok.version>1.18.24</lombok.version> |
| 48 | <mapstruct.version>1.5.3.Final</mapstruct.version> | 47 | <mapstruct.version>1.5.3.Final</mapstruct.version> |
| 49 | <hutool.version>5.8.9</hutool.version> | 48 | <hutool.version>5.8.9</hutool.version> |
| @@ -408,12 +407,6 @@ | @@ -408,12 +407,6 @@ | ||
| 408 | </dependency> | 407 | </dependency> |
| 409 | 408 | ||
| 410 | <dependency> | 409 | <dependency> |
| 411 | - <groupId>com.github.ulisesbocchio</groupId> | ||
| 412 | - <artifactId>jasypt-spring-boot-starter</artifactId> <!-- 加解密 --> | ||
| 413 | - <version>${jasypt-spring-boot-starter.version}</version> | ||
| 414 | - </dependency> | ||
| 415 | - | ||
| 416 | - <dependency> | ||
| 417 | <groupId>cn.iocoder.boot</groupId> | 410 | <groupId>cn.iocoder.boot</groupId> |
| 418 | <artifactId>yudao-spring-boot-starter-excel</artifactId> | 411 | <artifactId>yudao-spring-boot-starter-excel</artifactId> |
| 419 | <version>${revision}</version> | 412 | <version>${revision}</version> |
yudao-framework/yudao-spring-boot-starter-mybatis/pom.xml
| @@ -59,13 +59,6 @@ | @@ -59,13 +59,6 @@ | ||
| 59 | <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <!-- 多数据源 --> | 59 | <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <!-- 多数据源 --> |
| 60 | </dependency> | 60 | </dependency> |
| 61 | 61 | ||
| 62 | - <!-- 工具类相关 --> | ||
| 63 | - <dependency> | ||
| 64 | - <groupId>com.github.ulisesbocchio</groupId> | ||
| 65 | - <artifactId>jasypt-spring-boot-starter</artifactId> <!-- 加解密 --> | ||
| 66 | - <optional>true</optional> | ||
| 67 | - </dependency> | ||
| 68 | - | ||
| 69 | </dependencies> | 62 | </dependencies> |
| 70 | 63 | ||
| 71 | </project> | 64 | </project> |
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/EncryptTypeHandler.java
| 1 | package cn.iocoder.yudao.framework.mybatis.core.type; | 1 | package cn.iocoder.yudao.framework.mybatis.core.type; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.lang.Assert; | 3 | import cn.hutool.core.lang.Assert; |
| 4 | +import cn.hutool.crypto.SecureUtil; | ||
| 5 | +import cn.hutool.crypto.symmetric.AES; | ||
| 4 | import cn.hutool.extra.spring.SpringUtil; | 6 | import cn.hutool.extra.spring.SpringUtil; |
| 5 | import org.apache.ibatis.type.BaseTypeHandler; | 7 | import org.apache.ibatis.type.BaseTypeHandler; |
| 6 | import org.apache.ibatis.type.JdbcType; | 8 | import org.apache.ibatis.type.JdbcType; |
| 7 | -import org.jasypt.encryption.StringEncryptor; | ||
| 8 | 9 | ||
| 9 | import java.sql.CallableStatement; | 10 | import java.sql.CallableStatement; |
| 10 | import java.sql.PreparedStatement; | 11 | import java.sql.PreparedStatement; |
| @@ -12,18 +13,20 @@ import java.sql.ResultSet; | @@ -12,18 +13,20 @@ import java.sql.ResultSet; | ||
| 12 | import java.sql.SQLException; | 13 | import java.sql.SQLException; |
| 13 | 14 | ||
| 14 | /** | 15 | /** |
| 15 | - * 字段字段的 TypeHandler 实现类,基于 {@link StringEncryptor} 实现 | 16 | + * 字段字段的 TypeHandler 实现类,基于 {@link cn.hutool.crypto.symmetric.AES} 实现 |
| 16 | * 可通过 jasypt.encryptor.password 配置项,设置密钥 | 17 | * 可通过 jasypt.encryptor.password 配置项,设置密钥 |
| 17 | * | 18 | * |
| 18 | * @author 芋道源码 | 19 | * @author 芋道源码 |
| 19 | */ | 20 | */ |
| 20 | public class EncryptTypeHandler extends BaseTypeHandler<String> { | 21 | public class EncryptTypeHandler extends BaseTypeHandler<String> { |
| 21 | 22 | ||
| 22 | - private static StringEncryptor encryptor; | 23 | + private static final String ENCRYPTOR_PROPERTY_NAME = "mybatis-plus.encryptor.password"; |
| 24 | + | ||
| 25 | + private static AES aes; | ||
| 23 | 26 | ||
| 24 | @Override | 27 | @Override |
| 25 | public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { | 28 | public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { |
| 26 | - ps.setString(i, getEncryptor().encrypt(parameter)); | 29 | + ps.setString(i, encrypt(parameter)); |
| 27 | } | 30 | } |
| 28 | 31 | ||
| 29 | @Override | 32 | @Override |
| @@ -48,23 +51,25 @@ public class EncryptTypeHandler extends BaseTypeHandler<String> { | @@ -48,23 +51,25 @@ public class EncryptTypeHandler extends BaseTypeHandler<String> { | ||
| 48 | if (value == null) { | 51 | if (value == null) { |
| 49 | return null; | 52 | return null; |
| 50 | } | 53 | } |
| 51 | - return getEncryptor().decrypt(value); | 54 | + return getEncryptor().decryptStr(value); |
| 52 | } | 55 | } |
| 53 | 56 | ||
| 54 | public static String encrypt(String rawValue) { | 57 | public static String encrypt(String rawValue) { |
| 55 | if (rawValue == null) { | 58 | if (rawValue == null) { |
| 56 | return null; | 59 | return null; |
| 57 | } | 60 | } |
| 58 | - return getEncryptor().encrypt(rawValue); | 61 | + return getEncryptor().encryptBase64(rawValue); |
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | - private static StringEncryptor getEncryptor() { | ||
| 62 | - if (encryptor != null) { | ||
| 63 | - return encryptor; | 64 | + private static AES getEncryptor() { |
| 65 | + if (aes != null) { | ||
| 66 | + return aes; | ||
| 64 | } | 67 | } |
| 65 | - encryptor = SpringUtil.getBean(StringEncryptor.class); | ||
| 66 | - Assert.notNull(encryptor, "StringEncryptor 不能为空"); | ||
| 67 | - return encryptor; | 68 | + // 构建 AES |
| 69 | + String password = SpringUtil.getProperty(ENCRYPTOR_PROPERTY_NAME); | ||
| 70 | + Assert.notEmpty(password, "配置项({}) 不能为空", ENCRYPTOR_PROPERTY_NAME); | ||
| 71 | + aes = SecureUtil.aes(password.getBytes()); | ||
| 72 | + return aes; | ||
| 68 | } | 73 | } |
| 69 | 74 | ||
| 70 | } | 75 | } |
yudao-module-infra/yudao-module-infra-biz/pom.xml
| @@ -83,10 +83,6 @@ | @@ -83,10 +83,6 @@ | ||
| 83 | </dependency> | 83 | </dependency> |
| 84 | 84 | ||
| 85 | <!-- 工具类相关 --> | 85 | <!-- 工具类相关 --> |
| 86 | - <dependency> | ||
| 87 | - <groupId>com.github.ulisesbocchio</groupId> | ||
| 88 | - <artifactId>jasypt-spring-boot-starter</artifactId> <!-- 加解密 --> | ||
| 89 | - </dependency> | ||
| 90 | 86 | ||
| 91 | <dependency> | 87 | <dependency> |
| 92 | <groupId>cn.iocoder.boot</groupId> | 88 | <groupId>cn.iocoder.boot</groupId> |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java
| 1 | package cn.iocoder.yudao.module.infra.service.db; | 1 | package cn.iocoder.yudao.module.infra.service.db; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.ReflectUtil; | 3 | import cn.hutool.core.util.ReflectUtil; |
| 4 | +import cn.hutool.crypto.symmetric.AES; | ||
| 4 | import cn.iocoder.yudao.framework.mybatis.core.type.EncryptTypeHandler; | 5 | import cn.iocoder.yudao.framework.mybatis.core.type.EncryptTypeHandler; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils; | 6 | import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils; |
| 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 7 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| @@ -9,7 +10,6 @@ import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigUpda | @@ -9,7 +10,6 @@ import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigUpda | ||
| 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO; | 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO; |
| 10 | import cn.iocoder.yudao.module.infra.dal.mysql.db.DataSourceConfigMapper; | 11 | import cn.iocoder.yudao.module.infra.dal.mysql.db.DataSourceConfigMapper; |
| 11 | import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties; | 12 | import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties; |
| 12 | -import org.jasypt.encryption.StringEncryptor; | ||
| 13 | import org.junit.jupiter.api.BeforeEach; | 13 | import org.junit.jupiter.api.BeforeEach; |
| 14 | import org.junit.jupiter.api.Test; | 14 | import org.junit.jupiter.api.Test; |
| 15 | import org.mockito.MockedStatic; | 15 | import org.mockito.MockedStatic; |
| @@ -24,7 +24,8 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic | @@ -24,7 +24,8 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic | ||
| 24 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | 24 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; |
| 25 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | 25 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 26 | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_EXISTS; | 26 | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_EXISTS; |
| 27 | -import static org.junit.jupiter.api.Assertions.*; | 27 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 28 | +import static org.junit.jupiter.api.Assertions.assertNull; | ||
| 28 | import static org.mockito.ArgumentMatchers.anyString; | 29 | import static org.mockito.ArgumentMatchers.anyString; |
| 29 | import static org.mockito.ArgumentMatchers.eq; | 30 | import static org.mockito.ArgumentMatchers.eq; |
| 30 | import static org.mockito.Mockito.mockStatic; | 31 | import static org.mockito.Mockito.mockStatic; |
| @@ -45,7 +46,7 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { | @@ -45,7 +46,7 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { | ||
| 45 | private DataSourceConfigMapper dataSourceConfigMapper; | 46 | private DataSourceConfigMapper dataSourceConfigMapper; |
| 46 | 47 | ||
| 47 | @MockBean | 48 | @MockBean |
| 48 | - private StringEncryptor stringEncryptor; | 49 | + private AES aes; |
| 49 | 50 | ||
| 50 | @MockBean | 51 | @MockBean |
| 51 | private DynamicDataSourceProperties dynamicDataSourceProperties; | 52 | private DynamicDataSourceProperties dynamicDataSourceProperties; |
| @@ -53,9 +54,9 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { | @@ -53,9 +54,9 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { | ||
| 53 | @BeforeEach | 54 | @BeforeEach |
| 54 | public void setUp() { | 55 | public void setUp() { |
| 55 | // mock 一个空实现的 StringEncryptor,避免 EncryptTypeHandler 报错 | 56 | // mock 一个空实现的 StringEncryptor,避免 EncryptTypeHandler 报错 |
| 56 | - ReflectUtil.setFieldValue(EncryptTypeHandler.class, "encryptor", stringEncryptor); | ||
| 57 | - when(stringEncryptor.encrypt(anyString())).then((Answer<String>) invocation -> invocation.getArgument(0)); | ||
| 58 | - when(stringEncryptor.decrypt(anyString())).then((Answer<String>) invocation -> invocation.getArgument(0)); | 57 | + ReflectUtil.setFieldValue(EncryptTypeHandler.class, "aes", aes); |
| 58 | + when(aes.encryptBase64(anyString())).then((Answer<String>) invocation -> invocation.getArgument(0)); | ||
| 59 | + when(aes.decryptStr(anyString())).then((Answer<String>) invocation -> invocation.getArgument(0)); | ||
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | @Test | 62 | @Test |
yudao-server/src/main/resources/application-dev.yaml
| @@ -63,10 +63,6 @@ spring: | @@ -63,10 +63,6 @@ spring: | ||
| 63 | database: 1 # 数据库索引 | 63 | database: 1 # 数据库索引 |
| 64 | # password: 123456 # 密码,建议生产环境开启 | 64 | # password: 123456 # 密码,建议生产环境开启 |
| 65 | 65 | ||
| 66 | -jasypt: | ||
| 67 | - encryptor: | ||
| 68 | - password: yuanma # 加解密的秘钥 | ||
| 69 | - | ||
| 70 | --- #################### 定时任务相关配置 #################### | 66 | --- #################### 定时任务相关配置 #################### |
| 71 | 67 | ||
| 72 | # Quartz 配置项,对应 QuartzProperties 配置类 | 68 | # Quartz 配置项,对应 QuartzProperties 配置类 |
yudao-server/src/main/resources/application-local.yaml
| @@ -45,37 +45,33 @@ spring: | @@ -45,37 +45,33 @@ spring: | ||
| 45 | datasource: | 45 | datasource: |
| 46 | master: | 46 | master: |
| 47 | name: ruoyi-vue-pro | 47 | name: ruoyi-vue-pro |
| 48 | - url: jdbc:mysql://139.9.196.247:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 | 48 | + url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 |
| 49 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 | 49 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 |
| 50 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 | 50 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 |
| 51 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 | 51 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 |
| 52 | # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 | 52 | # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 |
| 53 | username: root | 53 | username: root |
| 54 | - password: ${RUOYI_VUE_PRO} | 54 | + password: 123456 |
| 55 | # username: sa | 55 | # username: sa |
| 56 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W | 56 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W |
| 57 | slave: # 模拟从库,可根据自己需要修改 | 57 | slave: # 模拟从库,可根据自己需要修改 |
| 58 | name: ruoyi-vue-pro | 58 | name: ruoyi-vue-pro |
| 59 | - url: jdbc:mysql://139.9.196.247:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 | 59 | + url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 |
| 60 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 | 60 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 |
| 61 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 | 61 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 |
| 62 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 | 62 | # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 |
| 63 | # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 | 63 | # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 |
| 64 | username: root | 64 | username: root |
| 65 | - password: ${RUOYI_VUE_PRO} | 65 | + password: 123456 |
| 66 | # username: sa | 66 | # username: sa |
| 67 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W | 67 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W |
| 68 | 68 | ||
| 69 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 | 69 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 |
| 70 | redis: | 70 | redis: |
| 71 | - host: 139.9.196.247 # 地址 | 71 | + host: 127.0.0.1 # 地址 |
| 72 | port: 6379 # 端口 | 72 | port: 6379 # 端口 |
| 73 | database: 0 # 数据库索引 | 73 | database: 0 # 数据库索引 |
| 74 | - password: 123456 # 密码,建议生产环境开启 | ||
| 75 | - | ||
| 76 | -jasypt: | ||
| 77 | - encryptor: | ||
| 78 | - password: yuanma # 加解密的秘钥 | 74 | +# password: 123456 # 密码,建议生产环境开启 |
| 79 | 75 | ||
| 80 | --- #################### 定时任务相关配置 #################### | 76 | --- #################### 定时任务相关配置 #################### |
| 81 | 77 |
yudao-server/src/main/resources/application.yaml
| @@ -56,6 +56,8 @@ mybatis-plus: | @@ -56,6 +56,8 @@ mybatis-plus: | ||
| 56 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) | 56 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) |
| 57 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) | 57 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) |
| 58 | type-aliases-package: ${yudao.info.base-package}.module.*.dal.dataobject | 58 | type-aliases-package: ${yudao.info.base-package}.module.*.dal.dataobject |
| 59 | + encryptor: | ||
| 60 | + password: XDV71a+xqStEA3WH # 加解密的秘钥,可使用 https://www.imaegoo.com/2020/aes-key-generator/ 网站生成 | ||
| 59 | 61 | ||
| 60 | --- #################### 验证码相关配置 #################### | 62 | --- #################### 验证码相关配置 #################### |
| 61 | 63 |