diff --git a/base-framework-cache-starter/src/main/java/com/fuhouyu/framework/cache/CacheAutoConfiguration.java b/base-framework-cache-starter/src/main/java/com/fuhouyu/framework/cache/CacheAutoConfiguration.java index 9cd1b49..9bb1651 100644 --- a/base-framework-cache-starter/src/main/java/com/fuhouyu/framework/cache/CacheAutoConfiguration.java +++ b/base-framework-cache-starter/src/main/java/com/fuhouyu/framework/cache/CacheAutoConfiguration.java @@ -17,8 +17,8 @@ package com.fuhouyu.framework.cache; import org.springframework.boot.autoconfigure.cache.CacheProperties; -import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; /** @@ -29,9 +29,9 @@ * @author fuhouyu * @since 2024/8/13 21:00 */ +@Configuration @Import({RedisCacheAutoConfiguration.class, CaffeineCacheAutoconfiguration.class}) @EnableConfigurationProperties(CacheProperties.class) -@ConfigurationPropertiesScan(basePackageClasses = CacheAutoConfiguration.class) public class CacheAutoConfiguration { diff --git a/base-framework-cache-starter/src/main/java/com/fuhouyu/framework/cache/RedisCacheAutoConfiguration.java b/base-framework-cache-starter/src/main/java/com/fuhouyu/framework/cache/RedisCacheAutoConfiguration.java index f21d4e8..4d26928 100644 --- a/base-framework-cache-starter/src/main/java/com/fuhouyu/framework/cache/RedisCacheAutoConfiguration.java +++ b/base-framework-cache-starter/src/main/java/com/fuhouyu/framework/cache/RedisCacheAutoConfiguration.java @@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; @@ -47,6 +48,7 @@ name = "cache-service-type", havingValue = "redis") @AutoConfigureAfter(RedisAutoConfiguration.class) +@Configuration public class RedisCacheAutoConfiguration { diff --git a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfiguration.java b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfiguration.java index 90b5253..e4f068a 100644 --- a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfiguration.java +++ b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfiguration.java @@ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -58,6 +59,7 @@ @ConditionalOnMissingBean(KmsService.class) @EnableConfigurationProperties(KmsDefaultProperties.class) @RequiredArgsConstructor +@Configuration public class DefaultKmsAutoConfiguration { private final KmsDefaultProperties properties; diff --git a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/KmsAutoConfiguration.java b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/KmsAutoConfiguration.java index 188e9b0..2972e62 100644 --- a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/KmsAutoConfiguration.java +++ b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/KmsAutoConfiguration.java @@ -16,7 +16,7 @@ package com.fuhouyu.framework.kms; -import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; /** @@ -27,8 +27,8 @@ * @author fuhouyu * @since 2024/8/17 17:27 */ -@ComponentScan(basePackageClasses = KmsAutoConfiguration.class) @Import({DefaultKmsAutoConfiguration.class}) +@Configuration public class KmsAutoConfiguration { diff --git a/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/LogRecordAutoConfiguration.java b/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/LogRecordAutoConfiguration.java index 93bd1ec..b73eca5 100644 --- a/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/LogRecordAutoConfiguration.java +++ b/base-framework-log-starter/src/main/java/com/fuhouyu/framework/log/LogRecordAutoConfiguration.java @@ -19,13 +19,14 @@ import com.fuhouyu.framework.log.core.LogRecordAspectj; import com.fuhouyu.framework.log.core.LogRecordStoreService; import com.fuhouyu.framework.log.properties.LogRecordProperties; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.context.expression.BeanFactoryResolver; import org.springframework.util.Assert; @@ -33,6 +34,7 @@ import java.util.ArrayList; import java.util.List; + /** *
* 日志记录的自动装配类 @@ -41,11 +43,12 @@ * @author fuhouyu * @since 2024/8/14 12:16 */ -@ConfigurationPropertiesScan(basePackages = "com.fuhouyu.framework.log.properties") +@EnableConfigurationProperties(LogRecordProperties.class) +@Configuration(proxyBeanMethods = false) @ConditionalOnProperty(prefix = LogRecordProperties.LOG_RECORD_PREFIX, name = "enabled", havingValue = "true") -@ComponentScan(basePackageClasses = LogRecordAutoConfiguration.class) +@RequiredArgsConstructor public class LogRecordAutoConfiguration implements InitializingBean { private final LogRecordProperties logRecordProperties; @@ -54,11 +57,6 @@ public class LogRecordAutoConfiguration implements InitializingBean { private final BeanFactory beanFactory; - public LogRecordAutoConfiguration(LogRecordProperties logRecordProperties, ApplicationContext applicationContext, BeanFactory beanFactory) { - this.logRecordProperties = logRecordProperties; - this.applicationContext = applicationContext; - this.beanFactory = beanFactory; - } @Override public void afterPropertiesSet() throws Exception { diff --git a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/AliYunOssAutoConfiguration.java b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/AliYunOssAutoConfiguration.java index 8617299..3f08e35 100644 --- a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/AliYunOssAutoConfiguration.java +++ b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/AliYunOssAutoConfiguration.java @@ -31,7 +31,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import java.util.Objects; @@ -46,6 +48,8 @@ @ConditionalOnClass(OSS.class) @RequiredArgsConstructor @Slf4j +@EnableConfigurationProperties(AliYunOssProperties.class) +@Configuration public class AliYunOssAutoConfiguration implements InitializingBean { private final ResourceProperties resourceProperties; diff --git a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/LocalFileResourceAutoConfiguration.java b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/LocalFileResourceAutoConfiguration.java index b55d3a7..0467967 100644 --- a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/LocalFileResourceAutoConfiguration.java +++ b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/LocalFileResourceAutoConfiguration.java @@ -20,7 +20,7 @@ import com.fuhouyu.framework.resource.service.impl.LocalFileServiceImpl; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; -import org.springframework.core.io.Resource; +import org.springframework.context.annotation.Configuration; /** *
@@ -30,6 +30,7 @@ * @author fuhouyu * @since 2024/8/18 17:28 */ +@Configuration(proxyBeanMethods = false) public class LocalFileResourceAutoConfiguration { @@ -39,7 +40,7 @@ public class LocalFileResourceAutoConfiguration { * @return bean对象 */ @Bean - @ConditionalOnMissingBean(Resource.class) + @ConditionalOnMissingBean(ResourceService.class) public ResourceService localFileResourceService() { return new LocalFileServiceImpl(); } diff --git a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/ResourceAutoConfiguration.java b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/ResourceAutoConfiguration.java index 62b40f0..ca866f6 100644 --- a/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/ResourceAutoConfiguration.java +++ b/base-framework-resource-starter/src/main/java/com/fuhouyu/framework/resource/ResourceAutoConfiguration.java @@ -16,8 +16,9 @@ package com.fuhouyu.framework.resource; -import org.springframework.boot.context.properties.ConfigurationPropertiesScan; -import org.springframework.context.annotation.ComponentScan; +import com.fuhouyu.framework.resource.properties.ResourceProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; /** @@ -28,9 +29,9 @@ * @author fuhouyu * @since 2024/8/16 18:36 */ -@ComponentScan(basePackageClasses = ResourceAutoConfiguration.class) @Import({AliYunOssAutoConfiguration.class, LocalFileResourceAutoConfiguration.class}) -@ConfigurationPropertiesScan(basePackages = "com.fuhouyu.framework.resource.properties") +@EnableConfigurationProperties(ResourceProperties.class) +@Configuration public class ResourceAutoConfiguration { } diff --git a/base-framework-resource-starter/src/test/java/com/fuhouyu/framework/resource/ResourceServiceTest.java b/base-framework-resource-starter/src/test/java/com/fuhouyu/framework/resource/ResourceServiceTest.java index 6935b79..c5a9adf 100644 --- a/base-framework-resource-starter/src/test/java/com/fuhouyu/framework/resource/ResourceServiceTest.java +++ b/base-framework-resource-starter/src/test/java/com/fuhouyu/framework/resource/ResourceServiceTest.java @@ -21,11 +21,11 @@ import com.fuhouyu.framework.resource.exception.ResourceException; import com.fuhouyu.framework.resource.model.*; import com.fuhouyu.framework.resource.service.ResourceService; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; -import org.springframework.util.Assert; import java.io.*; import java.nio.charset.StandardCharsets; @@ -59,7 +59,7 @@ class ResourceServiceTest { void testResourceUpload() throws ResourceException { PutResourceResult putResourceResult = resourceService.uploadFile(new PutResourceRequest(BUCKET_NAME, objectKey, FILE_INPUT_STREAM)); - Assert.notNull(putResourceResult, "文件上传失败"); + Assertions.assertNotNull(putResourceResult, "文件上传失败"); } @@ -68,14 +68,14 @@ void testResourceDownload() throws ResourceException { String filePath = LOCAL_FILE_PARENT + "resource_download.xml"; DownloadResourceResult downloadResourceResult = resourceService.downloadFile(new DownloadResourceRequest("./", "pom.xml", filePath, 1000)); - Assert.notNull(downloadResourceResult, "文件下载失败"); + Assertions.assertNotNull(downloadResourceResult, "文件下载失败"); FileUtil.deleteFileIfExists(Path.of(filePath)); } @Test void testResourceDelete() throws ResourceException { resourceService.deleteFile(BUCKET_NAME, objectKey); - Assert.isTrue((!resourceService.doesObjectExist(BUCKET_NAME, objectKey)), "文件未被删除"); + Assertions.assertTrue((!resourceService.doesObjectExist(BUCKET_NAME, objectKey)), "文件未被删除"); } @Test @@ -84,7 +84,7 @@ void testGetFile() throws ResourceException { objectKey); GetResourceResult getResourceResult = resourceService.getFile(getResourceRequest); InputStream objectContent = getResourceResult.getObjectContent(); - Assert.notNull(objectContent, "资源文件下载失败"); + Assertions.assertNotNull(objectContent, "资源文件下载失败"); // 测试下载文件的写入 String localFilePath = LOCAL_FILE_PARENT + "get_file.txt"; try (objectContent; @@ -101,12 +101,12 @@ void testGetFile() throws ResourceException { void testUploadFile() throws ResourceException { PutResourceRequest putResourceRequest = new PutResourceRequest(BUCKET_NAME, objectKey, FILE_INPUT_STREAM); PutResourceResult putResourceResult = this.resourceService.uploadFile(putResourceRequest); - Assert.notNull(putResourceResult, "返回结果为空"); + Assertions.assertNotNull(putResourceResult, "返回结果为空"); GetResourceRequest getResourceRequest = new GetResourceRequest(BUCKET_NAME, objectKey); GetResourceResult getResourceResult = resourceService.getFile(getResourceRequest); ResourceMetadata resourceMetadata = getResourceResult.getResourceMetadata(); - Assert.notNull(resourceMetadata, "文件元数据为空"); + Assertions.assertNotNull(resourceMetadata, "文件元数据为空"); } @@ -117,14 +117,14 @@ void testInitUploadId() throws ResourceException, IOException { InitiateUploadMultipartRequest initiateUploadMultipartRequest = new InitiateUploadMultipartRequest(BUCKET_NAME, objectKey); InitiateUploadMultipartResult initiateUploadMultipartResult = resourceService.initiateMultipartUpload(initiateUploadMultipartRequest); - Assert.notNull(initiateUploadMultipartResult, "初始化上传id 返回的结果为空"); + Assertions.assertNotNull(initiateUploadMultipartResult, "初始化上传id 返回的结果为空"); uploadPartFile(localFilePath, initiateUploadMultipartResult.getUploadId()); ListMultipartRequest listMultipartRequest = new ListMultipartRequest(BUCKET_NAME); listMultipartRequest.setUploadId(initiateUploadMultipartResult.getUploadId()); ListMultipartResult listMultipartResult = resourceService.listParts(listMultipartRequest); - Assert.notNull(listMultipartResult, "列出分片 返回的文件不正确"); + Assertions.assertNotNull(listMultipartResult, "列出分片 返回的文件不正确"); UploadCompleteMultipartRequest uploadCompleteMultipartRequest = new UploadCompleteMultipartRequest(BUCKET_NAME); diff --git a/base-framework-security-starter/src/main/java/com/fuhouyu/framework/security/OpenPlatformAutoConfiguration.java b/base-framework-security-starter/src/main/java/com/fuhouyu/framework/security/OpenPlatformAutoConfiguration.java index ad3c486..a80b313 100644 --- a/base-framework-security-starter/src/main/java/com/fuhouyu/framework/security/OpenPlatformAutoConfiguration.java +++ b/base-framework-security-starter/src/main/java/com/fuhouyu/framework/security/OpenPlatformAutoConfiguration.java @@ -17,7 +17,8 @@ package com.fuhouyu.framework.security; import com.fuhouyu.framework.security.properties.OpenPlatformAuthProperties; -import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; /** *
@@ -27,7 +28,8 @@ * @author fuhouyu * @since 2024/8/15 16:23 */ -@ConfigurationPropertiesScan(basePackageClasses = OpenPlatformAuthProperties.class) +@Configuration +@EnableConfigurationProperties(OpenPlatformAuthProperties.class) public class OpenPlatformAutoConfiguration { diff --git a/base-framework-security-starter/src/main/java/com/fuhouyu/framework/security/SecurityAutoConfiguration.java b/base-framework-security-starter/src/main/java/com/fuhouyu/framework/security/SecurityAutoConfiguration.java index af0c8e6..45ab311 100644 --- a/base-framework-security-starter/src/main/java/com/fuhouyu/framework/security/SecurityAutoConfiguration.java +++ b/base-framework-security-starter/src/main/java/com/fuhouyu/framework/security/SecurityAutoConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; import org.springframework.security.authentication.AuthenticationManager; @@ -44,7 +44,7 @@ * @author fuhouyu * @since 2024/8/15 16:22 */ -@ComponentScan(basePackageClasses = SecurityAutoConfiguration.class) +@Configuration @Import({OpenPlatformAutoConfiguration.class}) @AutoConfigureAfter(CacheAutoConfiguration.class) public class SecurityAutoConfiguration { diff --git a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/BaseComponent.java b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/BaseComponent.java new file mode 100644 index 0000000..68f5556 --- /dev/null +++ b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/BaseComponent.java @@ -0,0 +1,73 @@ +/* + * Copyright 2024-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.fuhouyu.framework.security; + +import com.fuhouyu.framework.security.core.authentication.refreshtoken.RefreshAuthenticationProvider; +import com.fuhouyu.framework.security.token.TokenStore; +import org.springframework.boot.test.context.TestComponent; +import org.springframework.context.annotation.Bean; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.web.client.RestTemplate; + +import java.util.Collection; +import java.util.List; + +/** + *
+ * + *
+ * + * @author fuhouyu + * @since 2024/10/28 21:21 + */ +@TestComponent +class BaseComponent { + + @Bean + public AuthenticationProvider refreshTokenAuthenticationProvider(TokenStore tokenStore) { + return new RefreshAuthenticationProvider(tokenStore); + } + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + @Bean + public UserDetailsService userDetailsService() { + UserDetails userDetails = new UserDetails() { + @Override + public Collection extends GrantedAuthority> getAuthorities() { + return List.of(); + } + + @Override + public String getPassword() { + return "{noop}admin"; + } + + @Override + public String getUsername() { + return "admin"; + } + }; + return new InMemoryUserDetailsManager(userDetails); + } +} diff --git a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/RefreshTokenTest.java b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/RefreshTokenTest.java index 581a22d..467f12b 100644 --- a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/RefreshTokenTest.java +++ b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/RefreshTokenTest.java @@ -18,18 +18,14 @@ import com.fuhouyu.framework.cache.CacheAutoConfiguration; import com.fuhouyu.framework.cache.CaffeineCacheAutoconfiguration; import com.fuhouyu.framework.security.core.GrantTypeAuthenticationTokenEnum; -import com.fuhouyu.framework.security.core.authentication.refreshtoken.RefreshAuthenticationProvider; import com.fuhouyu.framework.security.entity.TokenEntity; import com.fuhouyu.framework.security.token.TokenStore; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestComponent; -import org.springframework.context.annotation.Bean; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.test.context.TestPropertySource; @@ -49,7 +45,7 @@ CacheAutoConfiguration.class, CaffeineCacheAutoconfiguration.class, SecurityAutoConfiguration.class, - + BaseComponent.class }) @TestPropertySource(locations = {"classpath:application.yaml"}) class RefreshTokenTest { @@ -76,13 +72,4 @@ void testRefreshToken() { Assertions.assertNotNull(refreshTokenEntity); } - @TestComponent - public static class RefreshTokenTestComponent { - - - @Bean - public AuthenticationProvider refreshTokenAuthenticationProvider(TokenStore tokenStore) { - return new RefreshAuthenticationProvider(tokenStore); - } - } } diff --git a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/Sm3PasswordEncoderTest.java b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/Sm3PasswordEncoderTest.java index a6e0fc0..90b7175 100644 --- a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/Sm3PasswordEncoderTest.java +++ b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/Sm3PasswordEncoderTest.java @@ -18,12 +18,12 @@ import com.fuhouyu.framework.cache.CacheAutoConfiguration; import com.fuhouyu.framework.cache.CaffeineCacheAutoconfiguration; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.test.context.TestPropertySource; -import org.springframework.util.Assert; /** *@@ -37,6 +37,7 @@ CacheAutoConfiguration.class, CaffeineCacheAutoconfiguration.class, SecurityAutoConfiguration.class, + BaseComponent.class }) @TestPropertySource(locations = {"classpath:application.yaml"}) class Sm3PasswordEncoderTest { @@ -47,10 +48,9 @@ class Sm3PasswordEncoderTest { @Test void testSm3PasswordEncoder() { String encodePassword = passwordEncoder.encode("test123"); - Assert.isTrue(passwordEncoder.matches("test123", encodePassword), + Assertions.assertTrue(passwordEncoder.matches("test123", encodePassword), "sm3 正确密码验证失败"); - Assert.isTrue(!passwordEncoder.matches("test124", encodePassword), - "sm3 错误密码验证失败"); + Assertions.assertFalse(passwordEncoder.matches("test124", encodePassword), "sm3 错误密码验证失败"); } } diff --git a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/TokenStoreTest.java b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/TokenStoreTest.java index 467a2c2..d2e9472 100644 --- a/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/TokenStoreTest.java +++ b/base-framework-security-starter/src/test/java/com/fuhouyu/framework/security/TokenStoreTest.java @@ -26,22 +26,13 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestComponent; -import org.springframework.context.annotation.Bean; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.core.OAuth2RefreshToken; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.test.context.TestPropertySource; -import org.springframework.web.client.RestTemplate; -import java.util.Collection; import java.util.Collections; -import java.util.List; /** *
@@ -55,7 +46,7 @@ CacheAutoConfiguration.class, CaffeineCacheAutoconfiguration.class, SecurityAutoConfiguration.class, - + BaseComponent.class }) @TestPropertySource(locations = {"classpath:application.yaml"}) class TokenStoreTest { @@ -97,36 +88,5 @@ void testTokenStore() { Assertions.assertNull(tokenStore.readRefreshToken(tokenEntity.getRefreshToken().getTokenValue()), "refresh token 未被清除"); } - @TestComponent - public static class AuthenticationProvider { - - - @Bean - public RestTemplate restTemplate() { - return new RestTemplate(); - } - - @Bean - public UserDetailsService userDetailsService() { - UserDetails userDetails = new UserDetails() { - @Override - public Collection extends GrantedAuthority> getAuthorities() { - return List.of(); - } - - @Override - public String getPassword() { - return "{noop}admin"; - } - - @Override - public String getUsername() { - return "admin"; - } - }; - return new InMemoryUserDetailsManager(userDetails); - } - - } }