feat(security/password): 新增安全模块-密码编码器自动配置(core -> security/password)

This commit is contained in:
2024-02-01 20:46:55 +08:00
parent 45a2c9e0c7
commit 47a4d57dee
10 changed files with 99 additions and 55 deletions

View File

@@ -4,7 +4,7 @@
<img src="https://img.shields.io/badge/License-LGPL--3.0-blue.svg" alt="License" />
</a>
<a href="https://central.sonatype.com/search?q=continew-starter" target="_blank">
<img src="https://img.shields.io/maven-central/v/top.charles7c.continew/continew-starter.svg?label=Maven%20Central" alt="Release" />
<img src="https://img.shields.io/maven-central/v/top.charles7c.continew/continew-starter.svg?label=Maven%20Central&logo=sonatype&logoColor=FFF" alt="Release" />
</a>
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
<img src="https://img.shields.io/badge/SNAPSHOT-v1.3.0-%23ff3f59.svg" alt="Release" />
@@ -15,11 +15,11 @@
<a href="https://sonarcloud.io/summary/new_code?id=Charles7c_continew-starter" target="_blank">
<img src="https://sonarcloud.io/api/project_badges/measure?project=Charles7c_continew-starter&metric=alert_status" alt="Sonar Status" />
</a>
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
<img src="https://img.shields.io/badge/Spring Boot-3.1.7-%236CB52D.svg" alt="Spring Boot" />
<a href="https://spring.io/projects/spring-boot" target="_blank">
<img src="https://img.shields.io/badge/Spring Boot-3.1.7-%236CB52D.svg?logo=Spring-Boot" alt="Spring Boot" />
</a>
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
<img src="https://img.shields.io/badge/Java-17-%236CB52D.svg" alt="Java" />
<img src="https://img.shields.io/badge/Open JDK-17-%236CB52D.svg?logo=OpenJDK&logoColor=FFF" alt="Open JDK" />
</a>
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
<img src="https://img.shields.io/github/stars/Charles7c/continew-starter?style=social" alt="GitHub stars" />
@@ -164,23 +164,24 @@ continew-starter.web:
## 模块结构
| 模块名称 | 模块说明 | 依赖版本 |
| ---------------------------------- | --------------------------------------------------- | ------------------------------------------------------------ |
| continew-starter-core | 核心模块:包含线程池等自动配置 | <a href="https://spring.io/projects/spring-boot" target="_blank">Spring Boot</a>3.1.7<br /><a href="https://www.hutool.cn/" target="_blank">Hutool</a>5.8.24<br />mica-ip2region3.1.6 |
| continew-starter-json-jackson | JSON 模块Jackson 自动配置 | Jackson2.15.3 |
| continew-starter-api-doc | API 文档模块Knife4j 自动配置 | <a href="https://doc.xiaominfo.com/" target="_blank">Knife4j</a>4.4.0 |
| continew-starter-web | Web 模块:跨域、全局异常、错误处理等自动配置 | <a href="https://undertow.io/" target="_blank">Undertow</a>2.3.10.Final<br /> |
| 模块名称 | 模块说明 | 依赖版本 |
|------------------------------------|-------------------------------------------| ------------------------------------------------------------ |
| continew-starter-core | 核心模块:包含线程池等自动配置 | <a href="https://spring.io/projects/spring-boot" target="_blank">Spring Boot</a>3.1.7<br /><a href="https://www.hutool.cn/" target="_blank">Hutool</a>5.8.24<br />mica-ip2region3.1.6 |
| continew-starter-json-jackson | JSON 模块Jackson 自动配置 | Jackson2.15.3 |
| continew-starter-api-doc | API 文档模块Knife4j 自动配置 | <a href="https://doc.xiaominfo.com/" target="_blank">Knife4j</a>4.4.0 |
| continew-starter-security | 安全模块密码编码器、数据库字段加密、JSON 脱敏等 | |
| continew-starter-web | Web 模块:跨域、全局异常、错误处理等自动配置 | <a href="https://undertow.io/" target="_blank">Undertow</a>2.3.10.Final<br /> |
| continew-starter-log-httptrace-pro | 日志模块Spring Boot Actuator HttpTrace 重置增强版 | |
| continew-starter-storage-local | 存储模块:本地存储 | |
| continew-starter-file-excel | 文件处理模块Excel 相关配置 | <a href="https://easyexcel.opensource.alibaba.com/" target="_blank">Easy Excel</a>3.3.4 |
| continew-starter-captcha-graphic | 验证码模块:图形验证码 | Easy Captcha1.6.2 |
| continew-starter-captcha-behavior | 验证码模块:行为验证码 | AJ-Captcha1.3.0 |
| continew-starter-cache-redisson | 缓存模块Redisson 自动配置 | <a href="https://github.com/redisson/redisson/wiki/Redisson%E9%A1%B9%E7%9B%AE%E4%BB%8B%E7%BB%8D" target="_blank">Redisson</a>3.25.2 |
| continew-starter-data-mybatis-plus | 数据访问模块MyBatis Plus 自动配置 | <a href="https://baomidou.com/" target="_blank">MyBatis Plus</a>3.5.5<br /><a href="https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611" target="_blank">dynamic-datasource-spring-boot-starter</a>4.2.0<br /><a href="https://github.com/p6spy/p6spy" target="_blank">P6Spy</a>3.9.1 |
| continew-starter-auth-satoken | 认证模块SaToken 自动配置 | <a href="https://sa-token.dev33.cn/" target="_blank">Sa-Token</a>1.37.0 |
| continew-starter-auth-justauth | 认证模块JustAuth 自动配置 | <a href="https://justauth.cn/" target="_blank">Just Auth</a>1.16.6 |
| continew-starter-messaging-mail | 消息模块:邮件 | Jakarta Mail1.1.0 |
| continew-starter-messaging-sms | 消息模块:短信 | <a href="https://sms4j.com/" target="_blank">SMS4J</a>3.0.4 |
| continew-starter-storage-local | 存储模块:本地存储 | |
| continew-starter-file-excel | 文件处理模块Excel 相关配置 | <a href="https://easyexcel.opensource.alibaba.com/" target="_blank">Easy Excel</a>3.3.4 |
| continew-starter-captcha-graphic | 验证码模块:图形验证码 | Easy Captcha1.6.2 |
| continew-starter-captcha-behavior | 验证码模块:行为验证码 | AJ-Captcha1.3.0 |
| continew-starter-cache-redisson | 缓存模块Redisson 自动配置 | <a href="https://github.com/redisson/redisson/wiki/Redisson%E9%A1%B9%E7%9B%AE%E4%BB%8B%E7%BB%8D" target="_blank">Redisson</a>3.25.2 |
| continew-starter-data-mybatis-plus | 数据访问模块MyBatis Plus 自动配置 | <a href="https://baomidou.com/" target="_blank">MyBatis Plus</a>3.5.5<br /><a href="https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611" target="_blank">dynamic-datasource-spring-boot-starter</a>4.2.0<br /><a href="https://github.com/p6spy/p6spy" target="_blank">P6Spy</a>3.9.1 |
| continew-starter-auth-satoken | 认证模块SaToken 自动配置 | <a href="https://sa-token.dev33.cn/" target="_blank">Sa-Token</a>1.37.0 |
| continew-starter-auth-justauth | 认证模块JustAuth 自动配置 | <a href="https://justauth.cn/" target="_blank">Just Auth</a>1.16.6 |
| continew-starter-messaging-mail | 消息模块:邮件 | Jakarta Mail1.1.0 |
| continew-starter-messaging-sms | 消息模块:短信 | <a href="https://sms4j.com/" target="_blank">SMS4J</a>3.0.4 |
| continew-starter-extension-crud | 扩展模块BaseController 自定义 CRUD API 封装 | |
## 贡献代码

View File

@@ -58,11 +58,5 @@
<groupId>cn.hutool</groupId>
<artifactId>hutool-db</artifactId>
</dependency>
<!-- Spring Security 附带的一个通用加解密库 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -1,4 +1,3 @@
top.charles7c.continew.starter.core.autoconfigure.project.ProjectAutoConfiguration
top.charles7c.continew.starter.core.autoconfigure.threadpool.ThreadPoolAutoConfiguration
top.charles7c.continew.starter.core.autoconfigure.threadpool.AsyncAutoConfiguration
top.charles7c.continew.starter.core.autoconfigure.password.PasswordEncoderAutoConfiguration

View File

@@ -375,6 +375,20 @@
<version>${revision}</version>
</dependency>
<!-- Web 模块 -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-web</artifactId>
<version>${revision}</version>
</dependency>
<!-- 安全模块 - 密码编码器 -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-security-password</artifactId>
<version>${revision}</version>
</dependency>
<!-- API 文档模块 -->
<dependency>
<groupId>top.charles7c.continew</groupId>
@@ -389,13 +403,6 @@
<version>${revision}</version>
</dependency>
<!-- Web 模块 -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-web</artifactId>
<version>${revision}</version>
</dependency>
<!-- 核心模块 -->
<dependency>
<groupId>top.charles7c.continew</groupId>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-security</artifactId>
<version>${revision}</version>
</parent>
<artifactId>continew-starter-security-password</artifactId>
<description>ContiNew Starter 安全模块 - 密码编码器</description>
<dependencies>
<!-- Spring Security 附带的一个密码加密库 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -14,9 +14,10 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.core.autoconfigure.password;
package top.charles7c.continew.starter.security.password.autoconfigure;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,6 +48,7 @@ import java.util.Map;
* </p>
*
* @author Jasmine
* @author Charles7c
* @since 1.3.0
*/
@AutoConfiguration
@@ -71,25 +73,15 @@ public class PasswordEncoderAutoConfiguration {
public PasswordEncoder passwordEncoder(List<PasswordEncoder> passwordEncoderList) {
Map<String, PasswordEncoder> encoders = new HashMap<>();
encoders.put("bcrypt", new BCryptPasswordEncoder());
encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder());
encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
encoders.put("pbkdf2", Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_5());
encoders.put("pbkdf2@SpringSecurity_v5_8", Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8());
encoders.put("scrypt", SCryptPasswordEncoder.defaultsForSpringSecurity_v4_1());
encoders.put("scrypt@SpringSecurity_v5_8", SCryptPasswordEncoder.defaultsForSpringSecurity_v5_8());
encoders.put("SHA-1", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"));
encoders
.put("SHA-256", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder());
encoders.put("argon2", Argon2PasswordEncoder.defaultsForSpringSecurity_v5_2());
encoders.put("argon2@SpringSecurity_v5_8", Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8());
encoders.put("pbkdf2", Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8());
encoders.put("scrypt", SCryptPasswordEncoder.defaultsForSpringSecurity_v5_8());
encoders.put("argon2", Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8());
// 添加自定义的密码编解码器
if (CollUtil.isNotEmpty(passwordEncoderList)) {
passwordEncoderList.forEach(passwordEncoder -> encoders.put(passwordEncoder.getClass()
.getSimpleName()
.toLowerCase(), passwordEncoder));
passwordEncoderList.forEach(passwordEncoder -> {
String simpleName = passwordEncoder.getClass().getSimpleName();
encoders.put(StrUtil.removeSuffix(simpleName, "PasswordEncoder").toLowerCase(), passwordEncoder);
});
}
String encodingId = properties.getEncodingId();
CheckUtils.throwIf(!encoders.containsKey(encodingId), "{} is not found in idToPasswordEncoder.", encodingId);
@@ -98,6 +90,6 @@ public class PasswordEncoderAutoConfiguration {
@PostConstruct
public void postConstruct() {
log.debug("[ContiNew Starter] - Auto Configuration 'PasswordEncoder' completed initialization.");
log.debug("[ContiNew Starter] - Auto Configuration 'Security-PasswordEncoder' completed initialization.");
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.core.autoconfigure.password;
package top.charles7c.continew.starter.security.password.autoconfigure;
import org.springframework.boot.context.properties.ConfigurationProperties;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;

View File

@@ -0,0 +1 @@
top.charles7c.continew.starter.security.password.autoconfigure.PasswordEncoderAutoConfiguration

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter</artifactId>
<version>${revision}</version>
</parent>
<artifactId>continew-starter-security</artifactId>
<packaging>pom</packaging>
<description>ContiNew Starter 安全模块</description>
<modules>
<module>continew-starter-security-password</module>
</modules>
<dependencies>
<!-- 核心模块 -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -70,6 +70,7 @@
<module>continew-starter-core</module>
<module>continew-starter-json</module>
<module>continew-starter-api-doc</module>
<module>continew-starter-security</module>
<module>continew-starter-web</module>
<module>continew-starter-log</module>
<module>continew-starter-storage</module>