From 54f59a0c69d7e657e4fa55f2ad84d80a809a3453 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Thu, 6 Jun 2024 23:34:21 +0900 Subject: [PATCH] refactor : Separate the combined configures into JwtProvider and SecureRequest --- .../config/AuthConfiguration.java | 16 +++++ .../config/AuthorizedRequestRegistrar.java | 8 +-- ...ebSecurity.java => EnableJwtProvider.java} | 16 ++--- .../config/EnableSecureRequest.java | 38 +++++++++++ .../config/JwtPropertiesRegistrar.java | 8 +-- ...ration.java => JwtProviderConfigurer.java} | 11 +-- .../config/SecretKeyConfigurer.java | 24 +++++++ .../config/SecretKeyRegistrar.java | 38 +++++++++++ ...urer.java => SecureRequestConfigurer.java} | 7 +- .../config/TargetAnnotationsRegistrar.java | 8 +-- .../context/AuthConfigurationContextTest.java | 64 ----------------- .../context/AuthorizedRequestContextTest.java | 57 ---------------- .../context/JwtConfigurationContextTest.java | 68 ------------------- .../context/JwtPropertiesContextTest.java | 44 ------------ ...sswordEncoderConfigurationContextTest.java | 43 ------------ .../context/TargetAnnotationsContextTest.java | 41 ----------- .../context/config/TestContextConfig.java | 58 ---------------- 17 files changed, 141 insertions(+), 408 deletions(-) rename src/main/java/io/wwan13/wintersecurity/config/{EnableWebSecurity.java => EnableJwtProvider.java} (76%) create mode 100644 src/main/java/io/wwan13/wintersecurity/config/EnableSecureRequest.java rename src/main/java/io/wwan13/wintersecurity/config/{PasswordEncoderConfiguration.java => JwtProviderConfigurer.java} (65%) create mode 100644 src/main/java/io/wwan13/wintersecurity/config/SecretKeyConfigurer.java create mode 100644 src/main/java/io/wwan13/wintersecurity/config/SecretKeyRegistrar.java rename src/main/java/io/wwan13/wintersecurity/config/{WebSecurityConfigurer.java => SecureRequestConfigurer.java} (79%) delete mode 100644 src/test/java/io/wwan13/wintersecurity/context/AuthConfigurationContextTest.java delete mode 100644 src/test/java/io/wwan13/wintersecurity/context/AuthorizedRequestContextTest.java delete mode 100644 src/test/java/io/wwan13/wintersecurity/context/JwtConfigurationContextTest.java delete mode 100644 src/test/java/io/wwan13/wintersecurity/context/JwtPropertiesContextTest.java delete mode 100644 src/test/java/io/wwan13/wintersecurity/context/PasswordEncoderConfigurationContextTest.java delete mode 100644 src/test/java/io/wwan13/wintersecurity/context/TargetAnnotationsContextTest.java delete mode 100644 src/test/java/io/wwan13/wintersecurity/context/config/TestContextConfig.java diff --git a/src/main/java/io/wwan13/wintersecurity/config/AuthConfiguration.java b/src/main/java/io/wwan13/wintersecurity/config/AuthConfiguration.java index f1cf221..c8f5157 100644 --- a/src/main/java/io/wwan13/wintersecurity/config/AuthConfiguration.java +++ b/src/main/java/io/wwan13/wintersecurity/config/AuthConfiguration.java @@ -24,10 +24,21 @@ import io.wwan13.wintersecurity.auth.provider.BearerTokenExtractor; import io.wwan13.wintersecurity.auth.provider.HttpRequestAccessManager; import io.wwan13.wintersecurity.jwt.TokenDecoder; +import io.wwan13.wintersecurity.jwt.provider.JwtTokenDecoder; +import io.wwan13.wintersecurity.secretkey.SecretKey; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; public class AuthConfiguration { + @Bean + @ConditionalOnMissingBean(TokenDecoder.class) + public TokenDecoder tokenDecoder(SecretKey secretKey) { + return new JwtTokenDecoder(secretKey); + } + @Bean public TokenExtractor tokenExtractor() { return new BearerTokenExtractor(); @@ -50,4 +61,9 @@ public AbstractInterceptorAuthProcessor authProcessor( requestAccessManager ); } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } } diff --git a/src/main/java/io/wwan13/wintersecurity/config/AuthorizedRequestRegistrar.java b/src/main/java/io/wwan13/wintersecurity/config/AuthorizedRequestRegistrar.java index 2b15eb9..46454b9 100644 --- a/src/main/java/io/wwan13/wintersecurity/config/AuthorizedRequestRegistrar.java +++ b/src/main/java/io/wwan13/wintersecurity/config/AuthorizedRequestRegistrar.java @@ -24,16 +24,16 @@ public class AuthorizedRequestRegistrar { - private final WebSecurityConfigurer webSecurityConfigurer; + private final SecureRequestConfigurer secureRequestConfigurer; - public AuthorizedRequestRegistrar(WebSecurityConfigurer webSecurityConfigurer) { - this.webSecurityConfigurer = webSecurityConfigurer; + public AuthorizedRequestRegistrar(SecureRequestConfigurer secureRequestConfigurer) { + this.secureRequestConfigurer = secureRequestConfigurer; } @Bean public AuthorizedRequest authorizedRequest() { AuthorizedRequestRegistry registry = AuthorizedRequestRegistry.of(); - webSecurityConfigurer.registerAuthPatterns(registry); + secureRequestConfigurer.registerAuthPatterns(registry); return AuthorizedRequestApplier.apply(registry); } } diff --git a/src/main/java/io/wwan13/wintersecurity/config/EnableWebSecurity.java b/src/main/java/io/wwan13/wintersecurity/config/EnableJwtProvider.java similarity index 76% rename from src/main/java/io/wwan13/wintersecurity/config/EnableWebSecurity.java rename to src/main/java/io/wwan13/wintersecurity/config/EnableJwtProvider.java index f5ae16e..6182f02 100644 --- a/src/main/java/io/wwan13/wintersecurity/config/EnableWebSecurity.java +++ b/src/main/java/io/wwan13/wintersecurity/config/EnableJwtProvider.java @@ -18,19 +18,19 @@ import org.springframework.context.annotation.Import; -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Import({ - AuthorizedRequestRegistrar.class, - AuthConfiguration.class, - AuthProcessorRegistrar.class, JwtPropertiesRegistrar.class, JwtConfiguration.class, - PasswordEncoderConfiguration.class, - TargetAnnotationsRegistrar.class + SecretKeyRegistrar.class }) -public @interface EnableWebSecurity { -} +public @interface EnableJwtProvider { +} \ No newline at end of file diff --git a/src/main/java/io/wwan13/wintersecurity/config/EnableSecureRequest.java b/src/main/java/io/wwan13/wintersecurity/config/EnableSecureRequest.java new file mode 100644 index 0000000..f6de8da --- /dev/null +++ b/src/main/java/io/wwan13/wintersecurity/config/EnableSecureRequest.java @@ -0,0 +1,38 @@ +/* + * Copyright 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 + * + * http://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 io.wwan13.wintersecurity.config; + +import org.springframework.context.annotation.Import; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +@Import({ + AuthorizedRequestRegistrar.class, + AuthConfiguration.class, + AuthProcessorRegistrar.class, + TargetAnnotationsRegistrar.class, + SecretKeyRegistrar.class +}) +public @interface EnableSecureRequest { +} diff --git a/src/main/java/io/wwan13/wintersecurity/config/JwtPropertiesRegistrar.java b/src/main/java/io/wwan13/wintersecurity/config/JwtPropertiesRegistrar.java index 9e3ab3b..112d762 100644 --- a/src/main/java/io/wwan13/wintersecurity/config/JwtPropertiesRegistrar.java +++ b/src/main/java/io/wwan13/wintersecurity/config/JwtPropertiesRegistrar.java @@ -23,16 +23,16 @@ public class JwtPropertiesRegistrar { - private final WebSecurityConfigurer webSecurityConfigurer; + private final JwtProviderConfigurer jwtProviderConfigurer; - public JwtPropertiesRegistrar(WebSecurityConfigurer webSecurityConfigurer) { - this.webSecurityConfigurer = webSecurityConfigurer; + public JwtPropertiesRegistrar(JwtProviderConfigurer jwtProviderConfigurer) { + this.jwtProviderConfigurer = jwtProviderConfigurer; } @Bean public JwtProperties jwtProperties() { JwtPropertiesRegistry registry = new JwtPropertiesRegistry(); - webSecurityConfigurer.configureJwt(registry); + jwtProviderConfigurer.configureJwt(registry); return JwtPropertiesApplier.apply(registry); } } diff --git a/src/main/java/io/wwan13/wintersecurity/config/PasswordEncoderConfiguration.java b/src/main/java/io/wwan13/wintersecurity/config/JwtProviderConfigurer.java similarity index 65% rename from src/main/java/io/wwan13/wintersecurity/config/PasswordEncoderConfiguration.java rename to src/main/java/io/wwan13/wintersecurity/config/JwtProviderConfigurer.java index 80c8baa..bb0d163 100644 --- a/src/main/java/io/wwan13/wintersecurity/config/PasswordEncoderConfiguration.java +++ b/src/main/java/io/wwan13/wintersecurity/config/JwtProviderConfigurer.java @@ -16,14 +16,9 @@ package io.wwan13.wintersecurity.config; -import org.springframework.context.annotation.Bean; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; +import io.wwan13.wintersecurity.jwt.support.JwtPropertiesRegistry; -public class PasswordEncoderConfiguration { +public interface JwtProviderConfigurer extends SecretKeyConfigurer { - @Bean - public PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } + void configureJwt(JwtPropertiesRegistry registry); } diff --git a/src/main/java/io/wwan13/wintersecurity/config/SecretKeyConfigurer.java b/src/main/java/io/wwan13/wintersecurity/config/SecretKeyConfigurer.java new file mode 100644 index 0000000..39aab43 --- /dev/null +++ b/src/main/java/io/wwan13/wintersecurity/config/SecretKeyConfigurer.java @@ -0,0 +1,24 @@ +/* + * Copyright 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 + * + * http://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 io.wwan13.wintersecurity.config; + +import io.wwan13.wintersecurity.secretkey.support.SecretKeyRegistry; + +public interface SecretKeyConfigurer { + + void configureSecretKey(SecretKeyRegistry registry); +} diff --git a/src/main/java/io/wwan13/wintersecurity/config/SecretKeyRegistrar.java b/src/main/java/io/wwan13/wintersecurity/config/SecretKeyRegistrar.java new file mode 100644 index 0000000..b3b77da --- /dev/null +++ b/src/main/java/io/wwan13/wintersecurity/config/SecretKeyRegistrar.java @@ -0,0 +1,38 @@ +/* + * Copyright 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 + * + * http://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 io.wwan13.wintersecurity.config; + +import io.wwan13.wintersecurity.secretkey.SecretKey; +import io.wwan13.wintersecurity.secretkey.support.SecretKetApplier; +import io.wwan13.wintersecurity.secretkey.support.SecretKeyRegistry; +import org.springframework.context.annotation.Bean; + +public class SecretKeyRegistrar { + + private final SecretKeyConfigurer configurer; + + public SecretKeyRegistrar(SecretKeyConfigurer configurer) { + this.configurer = configurer; + } + + @Bean + public SecretKey secretKey() { + SecretKeyRegistry registry = new SecretKeyRegistry(); + configurer.configureSecretKey(registry); + return SecretKetApplier.apply(registry); + } +} diff --git a/src/main/java/io/wwan13/wintersecurity/config/WebSecurityConfigurer.java b/src/main/java/io/wwan13/wintersecurity/config/SecureRequestConfigurer.java similarity index 79% rename from src/main/java/io/wwan13/wintersecurity/config/WebSecurityConfigurer.java rename to src/main/java/io/wwan13/wintersecurity/config/SecureRequestConfigurer.java index 7fc87cc..f79f522 100644 --- a/src/main/java/io/wwan13/wintersecurity/config/WebSecurityConfigurer.java +++ b/src/main/java/io/wwan13/wintersecurity/config/SecureRequestConfigurer.java @@ -17,14 +17,11 @@ package io.wwan13.wintersecurity.config; import io.wwan13.wintersecurity.auth.authorizedrequest.support.AuthorizedRequestRegistry; -import io.wwan13.wintersecurity.jwt.support.JwtPropertiesRegistry; import io.wwan13.wintersecurity.resolve.support.TargetAnnotationsRegistry; -public interface WebSecurityConfigurer { +public interface SecureRequestConfigurer extends SecretKeyConfigurer { void registerAuthPatterns(AuthorizedRequestRegistry registry); - void configureJwt(JwtPropertiesRegistry registry); - - void registerResolveTargets(TargetAnnotationsRegistry registry); + void registerTargetAnnotations(TargetAnnotationsRegistry registry); } diff --git a/src/main/java/io/wwan13/wintersecurity/config/TargetAnnotationsRegistrar.java b/src/main/java/io/wwan13/wintersecurity/config/TargetAnnotationsRegistrar.java index ebfbdf1..2bbd8e6 100644 --- a/src/main/java/io/wwan13/wintersecurity/config/TargetAnnotationsRegistrar.java +++ b/src/main/java/io/wwan13/wintersecurity/config/TargetAnnotationsRegistrar.java @@ -23,16 +23,16 @@ public class TargetAnnotationsRegistrar { - private final WebSecurityConfigurer webSecurityConfigurer; + private final SecureRequestConfigurer secureRequestConfigurer; - public TargetAnnotationsRegistrar(WebSecurityConfigurer webSecurityConfigurer) { - this.webSecurityConfigurer = webSecurityConfigurer; + public TargetAnnotationsRegistrar(SecureRequestConfigurer secureRequestConfigurer) { + this.secureRequestConfigurer = secureRequestConfigurer; } @Bean public TargetAnnotations targetAnnotations() { TargetAnnotationsRegistry registry = new TargetAnnotationsRegistry(); - webSecurityConfigurer.registerResolveTargets(registry); + secureRequestConfigurer.registerTargetAnnotations(registry); return TargetAnnotationsApplier.apply(registry); } } diff --git a/src/test/java/io/wwan13/wintersecurity/context/AuthConfigurationContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/AuthConfigurationContextTest.java deleted file mode 100644 index 41702c9..0000000 --- a/src/test/java/io/wwan13/wintersecurity/context/AuthConfigurationContextTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 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 - * - * http://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 io.wwan13.wintersecurity.context; - -import io.wwan13.wintersecurity.ContextTest; -import io.wwan13.wintersecurity.auth.AuthProcessor; -import io.wwan13.wintersecurity.auth.RequestAccessManager; -import io.wwan13.wintersecurity.auth.TokenExtractor; -import io.wwan13.wintersecurity.auth.processor.AbstractInterceptorAuthProcessor; -import io.wwan13.wintersecurity.auth.processor.InterceptorAuthProcessor; -import io.wwan13.wintersecurity.auth.provider.BearerTokenExtractor; -import io.wwan13.wintersecurity.auth.provider.HttpRequestAccessManager; -import io.wwan13.wintersecurity.context.config.TestContextConfig; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; -import org.springframework.web.servlet.HandlerInterceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -@Deprecated -@Import({TestContextConfig.class}) -public class AuthConfigurationContextTest extends ContextTest { - - @Autowired - TokenExtractor tokenExtractor; - - @Autowired - RequestAccessManager requestAccessManager; - - @Autowired - AbstractInterceptorAuthProcessor authProcessor; - - @Test - void should_RegisteredInSpringIocWithEnteredValue_when_ContextLoaded() { - // given, then, then - assertThat(tokenExtractor) - .isInstanceOf(TokenExtractor.class) - .isExactlyInstanceOf(BearerTokenExtractor.class); - - assertThat(requestAccessManager) - .isInstanceOf(RequestAccessManager.class) - .isExactlyInstanceOf(HttpRequestAccessManager.class); - - assertThat(authProcessor) - .isInstanceOf(AuthProcessor.class) - .isInstanceOf(HandlerInterceptor.class) - .isExactlyInstanceOf(InterceptorAuthProcessor.class); - } -} diff --git a/src/test/java/io/wwan13/wintersecurity/context/AuthorizedRequestContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/AuthorizedRequestContextTest.java deleted file mode 100644 index ae4961a..0000000 --- a/src/test/java/io/wwan13/wintersecurity/context/AuthorizedRequestContextTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 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 - * - * http://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 io.wwan13.wintersecurity.context; - -import io.wwan13.wintersecurity.ContextTest; -import io.wwan13.wintersecurity.auth.authorizedrequest.AuthorizedRequest; -import io.wwan13.wintersecurity.context.config.TestContextConfig; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; -import org.springframework.http.HttpMethod; - -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; - -@Deprecated -@Import({TestContextConfig.class}) -public class AuthorizedRequestContextTest extends ContextTest { - - @Autowired - AuthorizedRequest authorizedRequest; - - @ParameterizedTest - @CsvSource({ - "GET, /api/test/hello, ROLE_ADMIN, true", - "GET, /api/bad/hello, ROLE_ADMIN, false", - }) - void should_RegisteredInSpringIocWithEnteredValue_when_ContextLoaded( - final String requestMethod, - final String requestUri, - final String requestRole, - final boolean expected - ) { - // given, when - boolean result = authorizedRequest - .isAccessibleRequest(HttpMethod.resolve(requestMethod), requestUri, Set.of(requestRole)); - - // then - assertThat(result).isEqualTo(expected); - } -} diff --git a/src/test/java/io/wwan13/wintersecurity/context/JwtConfigurationContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/JwtConfigurationContextTest.java deleted file mode 100644 index 4abdd94..0000000 --- a/src/test/java/io/wwan13/wintersecurity/context/JwtConfigurationContextTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 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 - * - * http://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 io.wwan13.wintersecurity.context; - -import io.wwan13.wintersecurity.ContextTest; -import io.wwan13.wintersecurity.context.config.TestContextConfig; -import io.wwan13.wintersecurity.jwt.PayloadAnalysis; -import io.wwan13.wintersecurity.jwt.PayloadParser; -import io.wwan13.wintersecurity.jwt.TokenDecoder; -import io.wwan13.wintersecurity.jwt.TokenGenerator; -import io.wwan13.wintersecurity.jwt.payload.support.JwtPayloadParser; -import io.wwan13.wintersecurity.jwt.provider.JwtTokenDecoder; -import io.wwan13.wintersecurity.jwt.provider.JwtTokenGenerator; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; - -import static org.assertj.core.api.Assertions.assertThat; - -@Deprecated -@Import({TestContextConfig.class}) -public class JwtConfigurationContextTest extends ContextTest { - - @Autowired - TokenGenerator tokenGenerator; - - @Autowired - TokenDecoder tokenDecoder; - - @Autowired - PayloadAnalysis payloadAnalysis; - - @Autowired - PayloadParser payloadParser; - - @Test - void should_RegisteredInSpringIocWithEnteredValue_when_ContextLoaded() { - // given, then, then - assertThat(tokenGenerator) - .isInstanceOf(TokenGenerator.class) - .isExactlyInstanceOf(JwtTokenGenerator.class); - - assertThat(tokenDecoder) - .isInstanceOf(TokenDecoder.class) - .isExactlyInstanceOf(JwtTokenDecoder.class); - - assertThat(payloadAnalysis) - .isInstanceOf(PayloadAnalysis.class); - - assertThat(payloadParser) - .isInstanceOf(PayloadParser.class) - .isExactlyInstanceOf(JwtPayloadParser.class); - } -} diff --git a/src/test/java/io/wwan13/wintersecurity/context/JwtPropertiesContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/JwtPropertiesContextTest.java deleted file mode 100644 index 86de033..0000000 --- a/src/test/java/io/wwan13/wintersecurity/context/JwtPropertiesContextTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 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 - * - * http://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 io.wwan13.wintersecurity.context; - -import io.wwan13.wintersecurity.ContextTest; -import io.wwan13.wintersecurity.context.config.TestContextConfig; -import io.wwan13.wintersecurity.jwt.JwtProperties; -import io.wwan13.wintersecurity.jwt.payload.DefaultPayload; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; - -import static org.assertj.core.api.Assertions.assertThat; - -@Deprecated -@Import({TestContextConfig.class}) -public class JwtPropertiesContextTest extends ContextTest { - - @Autowired - JwtProperties jwtProperties; - - @Test - void should_RegisteredInSpringIocWithEnteredValue_when_ContextLoaded() { - // given, then, then - assertThat(jwtProperties.accessTokenValidity()).isEqualTo(1000L); - assertThat(jwtProperties.refreshTokenValidity()).isEqualTo(1000L); - assertThat(jwtProperties.payloadClazz()).isEqualTo(DefaultPayload.class); - assertThat(jwtProperties.subjectClazz()).isEqualTo(long.class); - } -} diff --git a/src/test/java/io/wwan13/wintersecurity/context/PasswordEncoderConfigurationContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/PasswordEncoderConfigurationContextTest.java deleted file mode 100644 index 9ceb913..0000000 --- a/src/test/java/io/wwan13/wintersecurity/context/PasswordEncoderConfigurationContextTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 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 - * - * http://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 io.wwan13.wintersecurity.context; - -import io.wwan13.wintersecurity.ContextTest; -import io.wwan13.wintersecurity.context.config.TestContextConfig; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; - -import static org.assertj.core.api.Assertions.assertThat; - -@Deprecated -@Import(TestContextConfig.class) -public class PasswordEncoderConfigurationContextTest extends ContextTest { - - @Autowired - PasswordEncoder passwordEncoder; - - @Test - void should_RegisteredInSpringIocWithEnteredValue_when_ContextLoaded() { - // given, then, then - assertThat(passwordEncoder) - .isInstanceOf(PasswordEncoder.class) - .isExactlyInstanceOf(BCryptPasswordEncoder.class); - } -} diff --git a/src/test/java/io/wwan13/wintersecurity/context/TargetAnnotationsContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/TargetAnnotationsContextTest.java deleted file mode 100644 index 4578482..0000000 --- a/src/test/java/io/wwan13/wintersecurity/context/TargetAnnotationsContextTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 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 - * - * http://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 io.wwan13.wintersecurity.context; - -import io.wwan13.wintersecurity.ContextTest; -import io.wwan13.wintersecurity.context.config.TestContextConfig; -import io.wwan13.wintersecurity.resolve.TargetAnnotations; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; - -import static org.assertj.core.api.Assertions.assertThat; - -@Deprecated -@Import(TestContextConfig.class) -public class TargetAnnotationsContextTest extends ContextTest { - - @Autowired - TargetAnnotations targetAnnotations; - - @Test - void should_RegisteredInSpringIocWithEnteredValue_when_ContextLoaded() { - // given, then, then - assertThat(targetAnnotations) - .isInstanceOf(TargetAnnotations.class); - } -} diff --git a/src/test/java/io/wwan13/wintersecurity/context/config/TestContextConfig.java b/src/test/java/io/wwan13/wintersecurity/context/config/TestContextConfig.java deleted file mode 100644 index d2f40f1..0000000 --- a/src/test/java/io/wwan13/wintersecurity/context/config/TestContextConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 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 - * - * http://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 io.wwan13.wintersecurity.context.config; - -import io.wwan13.wintersecurity.auth.authorizedrequest.support.AuthorizedRequestRegistry; -import io.wwan13.wintersecurity.config.EnableWebSecurity; -import io.wwan13.wintersecurity.config.WebSecurityConfigurer; -import io.wwan13.wintersecurity.jwt.payload.DefaultPayload; -import io.wwan13.wintersecurity.jwt.support.JwtPropertiesRegistry; -import io.wwan13.wintersecurity.resolve.RequestUserId; -import io.wwan13.wintersecurity.resolve.RequestUserRoles; -import io.wwan13.wintersecurity.resolve.support.TargetAnnotationsRegistry; -import org.springframework.boot.test.context.TestConfiguration; - -@TestConfiguration -@EnableWebSecurity -public class TestContextConfig implements WebSecurityConfigurer { - - @Override - public void registerAuthPatterns(AuthorizedRequestRegistry registry) { - registry - .uriPatterns("/api/test/**") - .allHttpMethods() - .permitAll() - - .elseRequestAuthenticated(); - } - - @Override - public void configureJwt(JwtPropertiesRegistry registry) { - registry - .accessTokenValidity(1000L) - .refreshTokenValidity(1000L) - .payloadClazz(DefaultPayload.class) - .subjectClazz(long.class); - } - - @Override - public void registerResolveTargets(TargetAnnotationsRegistry registry) { - registry - .addSubjectResolveAnnotation(RequestUserId.class) - .addRolesResolveAnnotation(RequestUserRoles.class); - } -}