From e414abc73536c57a774f2c6d5dbeff78349310ae Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sat, 13 Sep 2025 22:15:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(encrypt/password-encoder):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=AF=86=E7=A0=81=E7=BC=96=E7=A0=81=E5=99=A8=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=EF=BC=88=E7=BB=8F=E8=BF=87=E8=80=83=E9=87=8F=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E6=8B=86=E5=88=86=E5=87=BA=E6=9D=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + continew-starter-bom/pom.xml | 6 ++++ .../continew-starter-encrypt-core/pom.xml | 6 ---- .../starter/encrypt/enums/Algorithm.java | 7 +---- ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../autoconfigure/FieldEncryptProperties.java | 16 ---------- .../pom.xml | 31 +++++++++++++++++++ .../PasswordEncoderAutoConfiguration.java | 6 ++-- .../PasswordEncoderProperties.java | 7 +++-- .../encryptor/PasswordEncoderEncryptor.java | 5 +-- .../enums/PasswordEncoderAlgorithm.java | 2 +- .../exception/PasswordEncodeException.java | 2 +- .../encoder}/util/PasswordEncoderUtil.java | 6 ++-- ...ot.autoconfigure.AutoConfiguration.imports | 1 + continew-starter-encrypt/pom.xml | 1 + 15 files changed, 57 insertions(+), 41 deletions(-) delete mode 100644 continew-starter-encrypt/continew-starter-encrypt-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 continew-starter-encrypt/continew-starter-encrypt-password-encoder/pom.xml rename continew-starter-encrypt/{continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt => continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder}/autoconfigure/PasswordEncoderAutoConfiguration.java (93%) rename continew-starter-encrypt/{continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt => continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder}/autoconfigure/PasswordEncoderProperties.java (78%) rename continew-starter-encrypt/{continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt => continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder}/encryptor/PasswordEncoderEncryptor.java (89%) rename continew-starter-encrypt/{continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt => continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder}/enums/PasswordEncoderAlgorithm.java (96%) rename continew-starter-encrypt/{continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt => continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder}/exception/PasswordEncodeException.java (95%) rename continew-starter-encrypt/{continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt => continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder}/util/PasswordEncoderUtil.java (94%) create mode 100644 continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/README.md b/README.md index 467afe1f..00b91977 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ continew-starter │ ├─ continew-starter-encrypt-core(核心模块) │ ├─ continew-starter-encrypt-field(字段加密) │ └─ continew-starter-encrypt-api(API 加密) +│ └─ continew-starter-encrypt-password-encoder(密码编码器) ├─ continew-starter-security(安全模块) │ ├─ continew-starter-security-mask(脱敏:JSON 数据脱敏) │ ├─ continew-starter-security-xss(XSS 过滤) diff --git a/continew-starter-bom/pom.xml b/continew-starter-bom/pom.xml index 0a6f532a..d8d5304c 100644 --- a/continew-starter-bom/pom.xml +++ b/continew-starter-bom/pom.xml @@ -116,6 +116,12 @@ continew-starter-encrypt-api ${revision} + + + top.continew.starter + continew-starter-encrypt-password-encoder + ${revision} + top.continew.starter diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/pom.xml b/continew-starter-encrypt/continew-starter-encrypt-core/pom.xml index 0836e2d0..b925d045 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-core/pom.xml +++ b/continew-starter-encrypt/continew-starter-encrypt-core/pom.xml @@ -27,11 +27,5 @@ cn.hutool hutool-crypto - - - - org.springframework.security - spring-security-crypto - \ No newline at end of file diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/enums/Algorithm.java b/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/enums/Algorithm.java index 5cfccb44..9e5628e5 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/enums/Algorithm.java +++ b/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/enums/Algorithm.java @@ -55,12 +55,7 @@ public enum Algorithm { /** * Base64 */ - BASE64(Base64Encryptor.class), - - /** - * 密码编码器,支持算法:BCrypt、SCRYPT、PBKDF2、ARGON2 - */ - PASSWORD_ENCODER(PasswordEncoderEncryptor.class); + BASE64(Base64Encryptor.class); /** * 加密/解密处理器 diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/continew-starter-encrypt/continew-starter-encrypt-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 9e47c38a..00000000 --- a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -top.continew.starter.encrypt.autoconfigure.PasswordEncoderAutoConfiguration \ No newline at end of file diff --git a/continew-starter-encrypt/continew-starter-encrypt-field/src/main/java/top/continew/starter/encrypt/field/autoconfigure/FieldEncryptProperties.java b/continew-starter-encrypt/continew-starter-encrypt-field/src/main/java/top/continew/starter/encrypt/field/autoconfigure/FieldEncryptProperties.java index fa50e070..0c471e43 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-field/src/main/java/top/continew/starter/encrypt/field/autoconfigure/FieldEncryptProperties.java +++ b/continew-starter-encrypt/continew-starter-encrypt-field/src/main/java/top/continew/starter/encrypt/field/autoconfigure/FieldEncryptProperties.java @@ -17,9 +17,7 @@ package top.continew.starter.encrypt.field.autoconfigure; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.NestedConfigurationProperty; import top.continew.starter.core.constant.PropertiesConstants; -import top.continew.starter.encrypt.autoconfigure.PasswordEncoderProperties; import top.continew.starter.encrypt.enums.Algorithm; /** @@ -57,12 +55,6 @@ public class FieldEncryptProperties { */ private String privateKey; - /** - * 密码编码器配置 - */ - @NestedConfigurationProperty - private PasswordEncoderProperties passwordEncoder; - public Boolean getEnabled() { return enabled; } @@ -102,12 +94,4 @@ public class FieldEncryptProperties { public void setPrivateKey(String privateKey) { this.privateKey = privateKey; } - - public PasswordEncoderProperties getPasswordEncoder() { - return passwordEncoder; - } - - public void setPasswordEncoder(PasswordEncoderProperties passwordEncoder) { - this.passwordEncoder = passwordEncoder; - } } \ No newline at end of file diff --git a/continew-starter-encrypt/continew-starter-encrypt-password-encoder/pom.xml b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/pom.xml new file mode 100644 index 00000000..389b3e38 --- /dev/null +++ b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + top.continew.starter + continew-starter-encrypt + ${revision} + + + continew-starter-encrypt-password-encoder + jar + + ${project.artifactId} + ContiNew Starter 加密模块 - 密码编码器 + + + + + top.continew.starter + continew-starter-encrypt-core + + + + + org.springframework.security + spring-security-crypto + + + \ No newline at end of file diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/autoconfigure/PasswordEncoderAutoConfiguration.java b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/autoconfigure/PasswordEncoderAutoConfiguration.java similarity index 93% rename from continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/autoconfigure/PasswordEncoderAutoConfiguration.java rename to continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/autoconfigure/PasswordEncoderAutoConfiguration.java index b4700d85..78a7b9a5 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/autoconfigure/PasswordEncoderAutoConfiguration.java +++ b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/autoconfigure/PasswordEncoderAutoConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.encrypt.autoconfigure; +package top.continew.starter.encrypt.password.encoder.autoconfigure; import jakarta.annotation.PostConstruct; import org.slf4j.Logger; @@ -29,8 +29,8 @@ import org.springframework.security.crypto.password.DelegatingPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import top.continew.starter.core.constant.PropertiesConstants; import top.continew.starter.core.util.validation.CheckUtils; -import top.continew.starter.encrypt.enums.PasswordEncoderAlgorithm; -import top.continew.starter.encrypt.util.PasswordEncoderUtil; +import top.continew.starter.encrypt.password.encoder.enums.PasswordEncoderAlgorithm; +import top.continew.starter.encrypt.password.encoder.util.PasswordEncoderUtil; import java.util.HashMap; import java.util.Map; diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/autoconfigure/PasswordEncoderProperties.java b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/autoconfigure/PasswordEncoderProperties.java similarity index 78% rename from continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/autoconfigure/PasswordEncoderProperties.java rename to continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/autoconfigure/PasswordEncoderProperties.java index d68b6c2f..47a079c6 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/autoconfigure/PasswordEncoderProperties.java +++ b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/autoconfigure/PasswordEncoderProperties.java @@ -14,9 +14,11 @@ * limitations under the License. */ -package top.continew.starter.encrypt.autoconfigure; +package top.continew.starter.encrypt.password.encoder.autoconfigure; -import top.continew.starter.encrypt.enums.PasswordEncoderAlgorithm; +import org.springframework.boot.context.properties.ConfigurationProperties; +import top.continew.starter.core.constant.PropertiesConstants; +import top.continew.starter.encrypt.password.encoder.enums.PasswordEncoderAlgorithm; /** * 密码编码器配置属性 @@ -25,6 +27,7 @@ import top.continew.starter.encrypt.enums.PasswordEncoderAlgorithm; * @author Charles7c * @since 1.3.0 */ +@ConfigurationProperties(PropertiesConstants.ENCRYPT_PASSWORD_ENCODER) public class PasswordEncoderProperties { /** diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/encryptor/PasswordEncoderEncryptor.java b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/encryptor/PasswordEncoderEncryptor.java similarity index 89% rename from continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/encryptor/PasswordEncoderEncryptor.java rename to continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/encryptor/PasswordEncoderEncryptor.java index 809abe6a..e98a62d0 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/encryptor/PasswordEncoderEncryptor.java +++ b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/encryptor/PasswordEncoderEncryptor.java @@ -14,13 +14,14 @@ * limitations under the License. */ -package top.continew.starter.encrypt.encryptor; +package top.continew.starter.encrypt.password.encoder.encryptor; import cn.hutool.extra.spring.SpringUtil; import org.springframework.security.crypto.password.PasswordEncoder; import top.continew.starter.core.util.SpringUtils; -import top.continew.starter.encrypt.autoconfigure.PasswordEncoderProperties; import top.continew.starter.encrypt.context.CryptoContext; +import top.continew.starter.encrypt.encryptor.AbstractEncryptor; +import top.continew.starter.encrypt.password.encoder.autoconfigure.PasswordEncoderProperties; /** * 密码编码器加密器 diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/enums/PasswordEncoderAlgorithm.java b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/enums/PasswordEncoderAlgorithm.java similarity index 96% rename from continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/enums/PasswordEncoderAlgorithm.java rename to continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/enums/PasswordEncoderAlgorithm.java index cd9bcdd1..b73238c7 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/enums/PasswordEncoderAlgorithm.java +++ b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/enums/PasswordEncoderAlgorithm.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.encrypt.enums; +package top.continew.starter.encrypt.password.encoder.enums; import java.util.regex.Pattern; diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/exception/PasswordEncodeException.java b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/exception/PasswordEncodeException.java similarity index 95% rename from continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/exception/PasswordEncodeException.java rename to continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/exception/PasswordEncodeException.java index 4c7c5f29..e4308e3c 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/exception/PasswordEncodeException.java +++ b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/exception/PasswordEncodeException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.encrypt.exception; +package top.continew.starter.encrypt.password.encoder.exception; import top.continew.starter.core.exception.BaseException; diff --git a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/util/PasswordEncoderUtil.java b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/util/PasswordEncoderUtil.java similarity index 94% rename from continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/util/PasswordEncoderUtil.java rename to continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/util/PasswordEncoderUtil.java index 04fe36d6..a8b24e70 100644 --- a/continew-starter-encrypt/continew-starter-encrypt-core/src/main/java/top/continew/starter/encrypt/util/PasswordEncoderUtil.java +++ b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/java/top/continew/starter/encrypt/password/encoder/util/PasswordEncoderUtil.java @@ -14,15 +14,15 @@ * limitations under the License. */ -package top.continew.starter.encrypt.util; +package top.continew.starter.encrypt.password.encoder.util; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.argon2.Argon2PasswordEncoder; import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder; -import top.continew.starter.encrypt.enums.PasswordEncoderAlgorithm; -import top.continew.starter.encrypt.exception.PasswordEncodeException; +import top.continew.starter.encrypt.password.encoder.exception.PasswordEncodeException; +import top.continew.starter.encrypt.password.encoder.enums.PasswordEncoderAlgorithm; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..04324eb0 --- /dev/null +++ b/continew-starter-encrypt/continew-starter-encrypt-password-encoder/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +top.continew.starter.encrypt.password.encoder.autoconfigure.PasswordEncoderAutoConfiguration \ No newline at end of file diff --git a/continew-starter-encrypt/pom.xml b/continew-starter-encrypt/pom.xml index 14c393eb..8f8d70a1 100644 --- a/continew-starter-encrypt/pom.xml +++ b/continew-starter-encrypt/pom.xml @@ -19,5 +19,6 @@ continew-starter-encrypt-core continew-starter-encrypt-field continew-starter-encrypt-api + continew-starter-encrypt-password-encoder \ No newline at end of file