mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-11-04 18:59:22 +08:00 
			
		
		
		
	feat(security/password): 新增安全模块-密码编码器自动配置(core -> security/password)
This commit is contained in:
		
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								README.md
									
									
									
									
									
								
							@@ -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" />
 | 
			
		||||
@@ -165,10 +165,11 @@ 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-ip2region:3.1.6 |
 | 
			
		||||
| continew-starter-json-jackson      | JSON 模块:Jackson 自动配置                      | Jackson:2.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     | 存储模块:本地存储                                 |                                                              |
 | 
			
		||||
 
 | 
			
		||||
@@ -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>
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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>
 | 
			
		||||
 
 | 
			
		||||
@@ -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>
 | 
			
		||||
@@ -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.");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
@@ -0,0 +1 @@
 | 
			
		||||
top.charles7c.continew.starter.security.password.autoconfigure.PasswordEncoderAutoConfiguration
 | 
			
		||||
							
								
								
									
										27
									
								
								continew-starter-security/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								continew-starter-security/pom.xml
									
									
									
									
									
										Normal 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>
 | 
			
		||||
							
								
								
									
										1
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								pom.xml
									
									
									
									
									
								
							@@ -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>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user