mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-10-31 10:57:15 +08:00 
			
		
		
		
	feat(security/password): 新增安全模块-密码编码器自动配置(core -> security/password)
This commit is contained in:
		
							
								
								
									
										41
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								README.md
									
									
									
									
									
								
							| @@ -4,7 +4,7 @@ | |||||||
| <img src="https://img.shields.io/badge/License-LGPL--3.0-blue.svg" alt="License" /> | <img src="https://img.shields.io/badge/License-LGPL--3.0-blue.svg" alt="License" /> | ||||||
| </a> | </a> | ||||||
| <a href="https://central.sonatype.com/search?q=continew-starter" target="_blank"> | <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> | ||||||
| <a href="https://github.com/Charles7c/continew-starter" target="_blank"> | <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" /> | <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"> | <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" /> | <img src="https://sonarcloud.io/api/project_badges/measure?project=Charles7c_continew-starter&metric=alert_status" alt="Sonar Status" /> | ||||||
| </a> | </a> | ||||||
| <a href="https://github.com/Charles7c/continew-starter" target="_blank"> | <a href="https://spring.io/projects/spring-boot" target="_blank"> | ||||||
| <img src="https://img.shields.io/badge/Spring Boot-3.1.7-%236CB52D.svg" alt="Spring Boot" /> | <img src="https://img.shields.io/badge/Spring Boot-3.1.7-%236CB52D.svg?logo=Spring-Boot" alt="Spring Boot" /> | ||||||
| </a> | </a> | ||||||
| <a href="https://github.com/Charles7c/continew-starter" target="_blank"> | <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> | ||||||
| <a href="https://github.com/Charles7c/continew-starter" target="_blank"> | <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" /> | <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-ip2region:3.1.6 | | | 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-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-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-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-log-httptrace-pro | 日志模块:Spring Boot Actuator HttpTrace 重置增强版 |                                                              | | ||||||
| | continew-starter-storage-local     | 存储模块:本地存储                                  |                                                              | | | 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-file-excel        | 文件处理模块:Excel 相关配置                         | <a href="https://easyexcel.opensource.alibaba.com/" target="_blank">Easy Excel</a>:3.3.4 | | ||||||
| | continew-starter-captcha-graphic   | 验证码模块:图形验证码                              | Easy Captcha:1.6.2                                          | | | continew-starter-captcha-graphic   | 验证码模块:图形验证码                               | Easy Captcha:1.6.2                                          | | ||||||
| | continew-starter-captcha-behavior  | 验证码模块:行为验证码                              | AJ-Captcha:1.3.0                                            | | | continew-starter-captcha-behavior  | 验证码模块:行为验证码                               | AJ-Captcha:1.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-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-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-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-auth-justauth     | 认证模块:JustAuth 自动配置                        | <a href="https://justauth.cn/" target="_blank">Just Auth</a>:1.16.6 | | ||||||
| | continew-starter-messaging-mail    | 消息模块:邮件                                      | Jakarta Mail:1.1.0                                          | | | continew-starter-messaging-mail    | 消息模块:邮件                                   | Jakarta Mail:1.1.0                                          | | ||||||
| | continew-starter-messaging-sms     | 消息模块:短信                                      | <a href="https://sms4j.com/" target="_blank">SMS4J</a>:3.0.4 | | | continew-starter-messaging-sms     | 消息模块:短信                                   | <a href="https://sms4j.com/" target="_blank">SMS4J</a>:3.0.4 | | ||||||
| | continew-starter-extension-crud    | 扩展模块:BaseController 自定义 CRUD API 封装       |                                                              | | | continew-starter-extension-crud    | 扩展模块:BaseController 自定义 CRUD API 封装       |                                                              | | ||||||
|  |  | ||||||
| ## 贡献代码 | ## 贡献代码 | ||||||
|   | |||||||
| @@ -58,11 +58,5 @@ | |||||||
|             <groupId>cn.hutool</groupId> |             <groupId>cn.hutool</groupId> | ||||||
|             <artifactId>hutool-db</artifactId> |             <artifactId>hutool-db</artifactId> | ||||||
|         </dependency> |         </dependency> | ||||||
|  |  | ||||||
|         <!-- Spring Security 附带的一个通用加解密库 --> |  | ||||||
|         <dependency> |  | ||||||
|             <groupId>org.springframework.security</groupId> |  | ||||||
|             <artifactId>spring-security-crypto</artifactId> |  | ||||||
|         </dependency> |  | ||||||
|     </dependencies> |     </dependencies> | ||||||
| </project> | </project> | ||||||
| @@ -1,4 +1,3 @@ | |||||||
| top.charles7c.continew.starter.core.autoconfigure.project.ProjectAutoConfiguration | top.charles7c.continew.starter.core.autoconfigure.project.ProjectAutoConfiguration | ||||||
| top.charles7c.continew.starter.core.autoconfigure.threadpool.ThreadPoolAutoConfiguration | top.charles7c.continew.starter.core.autoconfigure.threadpool.ThreadPoolAutoConfiguration | ||||||
| top.charles7c.continew.starter.core.autoconfigure.threadpool.AsyncAutoConfiguration | top.charles7c.continew.starter.core.autoconfigure.threadpool.AsyncAutoConfiguration | ||||||
| top.charles7c.continew.starter.core.autoconfigure.password.PasswordEncoderAutoConfiguration |  | ||||||
| @@ -375,6 +375,20 @@ | |||||||
|                 <version>${revision}</version> |                 <version>${revision}</version> | ||||||
|             </dependency> |             </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 文档模块 --> |             <!-- API 文档模块 --> | ||||||
|             <dependency> |             <dependency> | ||||||
|                 <groupId>top.charles7c.continew</groupId> |                 <groupId>top.charles7c.continew</groupId> | ||||||
| @@ -389,13 +403,6 @@ | |||||||
|                 <version>${revision}</version> |                 <version>${revision}</version> | ||||||
|             </dependency> |             </dependency> | ||||||
|  |  | ||||||
|             <!-- Web 模块 --> |  | ||||||
|             <dependency> |  | ||||||
|                 <groupId>top.charles7c.continew</groupId> |  | ||||||
|                 <artifactId>continew-starter-web</artifactId> |  | ||||||
|                 <version>${revision}</version> |  | ||||||
|             </dependency> |  | ||||||
|  |  | ||||||
|             <!-- 核心模块 --> |             <!-- 核心模块 --> | ||||||
|             <dependency> |             <dependency> | ||||||
|                 <groupId>top.charles7c.continew</groupId> |                 <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. |  * 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.collection.CollUtil; | ||||||
|  | import cn.hutool.core.util.StrUtil; | ||||||
| import jakarta.annotation.PostConstruct; | import jakarta.annotation.PostConstruct; | ||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||||
| @@ -47,6 +48,7 @@ import java.util.Map; | |||||||
|  * </p> |  * </p> | ||||||
|  * |  * | ||||||
|  * @author Jasmine |  * @author Jasmine | ||||||
|  |  * @author Charles7c | ||||||
|  * @since 1.3.0 |  * @since 1.3.0 | ||||||
|  */ |  */ | ||||||
| @AutoConfiguration | @AutoConfiguration | ||||||
| @@ -71,25 +73,15 @@ public class PasswordEncoderAutoConfiguration { | |||||||
|     public PasswordEncoder passwordEncoder(List<PasswordEncoder> passwordEncoderList) { |     public PasswordEncoder passwordEncoder(List<PasswordEncoder> passwordEncoderList) { | ||||||
|         Map<String, PasswordEncoder> encoders = new HashMap<>(); |         Map<String, PasswordEncoder> encoders = new HashMap<>(); | ||||||
|         encoders.put("bcrypt", new BCryptPasswordEncoder()); |         encoders.put("bcrypt", new BCryptPasswordEncoder()); | ||||||
|         encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder()); |         encoders.put("pbkdf2", Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8()); | ||||||
|         encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder()); |         encoders.put("scrypt", SCryptPasswordEncoder.defaultsForSpringSecurity_v5_8()); | ||||||
|         encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5")); |         encoders.put("argon2", Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8()); | ||||||
|         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()); |  | ||||||
|         // 添加自定义的密码编解码器 |         // 添加自定义的密码编解码器 | ||||||
|         if (CollUtil.isNotEmpty(passwordEncoderList)) { |         if (CollUtil.isNotEmpty(passwordEncoderList)) { | ||||||
|             passwordEncoderList.forEach(passwordEncoder -> encoders.put(passwordEncoder.getClass() |             passwordEncoderList.forEach(passwordEncoder -> { | ||||||
|                 .getSimpleName() |                 String simpleName = passwordEncoder.getClass().getSimpleName(); | ||||||
|                 .toLowerCase(), passwordEncoder)); |                 encoders.put(StrUtil.removeSuffix(simpleName, "PasswordEncoder").toLowerCase(), passwordEncoder); | ||||||
|  |             }); | ||||||
|         } |         } | ||||||
|         String encodingId = properties.getEncodingId(); |         String encodingId = properties.getEncodingId(); | ||||||
|         CheckUtils.throwIf(!encoders.containsKey(encodingId), "{} is not found in idToPasswordEncoder.", encodingId); |         CheckUtils.throwIf(!encoders.containsKey(encodingId), "{} is not found in idToPasswordEncoder.", encodingId); | ||||||
| @@ -98,6 +90,6 @@ public class PasswordEncoderAutoConfiguration { | |||||||
| 
 | 
 | ||||||
|     @PostConstruct |     @PostConstruct | ||||||
|     public void 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. |  * 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 org.springframework.boot.context.properties.ConfigurationProperties; | ||||||
| import top.charles7c.continew.starter.core.constant.PropertiesConstants; | 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-core</module> | ||||||
|         <module>continew-starter-json</module> |         <module>continew-starter-json</module> | ||||||
|         <module>continew-starter-api-doc</module> |         <module>continew-starter-api-doc</module> | ||||||
|  |         <module>continew-starter-security</module> | ||||||
|         <module>continew-starter-web</module> |         <module>continew-starter-web</module> | ||||||
|         <module>continew-starter-log</module> |         <module>continew-starter-log</module> | ||||||
|         <module>continew-starter-storage</module> |         <module>continew-starter-storage</module> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user