diff --git a/src/test/java/io/wwan13/wintersecurity/context/allconfigures/AllConfiguresContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/allconfigures/AllConfiguresContextTest.java new file mode 100644 index 0000000..8c40719 --- /dev/null +++ b/src/test/java/io/wwan13/wintersecurity/context/allconfigures/AllConfiguresContextTest.java @@ -0,0 +1,29 @@ +/* + * 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.allconfigures; + +import io.wwan13.wintersecurity.ContextTest; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +@Import(AllConfiguresTestConfigure.class) +public class AllConfiguresContextTest extends ContextTest { + + @Test + void contextLoad() { + } +} diff --git a/src/test/java/io/wwan13/wintersecurity/context/allconfigures/AllConfiguresTestConfigure.java b/src/test/java/io/wwan13/wintersecurity/context/allconfigures/AllConfiguresTestConfigure.java new file mode 100644 index 0000000..d336dad --- /dev/null +++ b/src/test/java/io/wwan13/wintersecurity/context/allconfigures/AllConfiguresTestConfigure.java @@ -0,0 +1,66 @@ +/* + * 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.allconfigures; + +import io.wwan13.wintersecurity.auth.authorizedrequest.support.AuthorizedRequestRegistry; +import io.wwan13.wintersecurity.config.EnableJwtProvider; +import io.wwan13.wintersecurity.config.EnableSecureRequest; +import io.wwan13.wintersecurity.config.JwtProviderConfigurer; +import io.wwan13.wintersecurity.config.SecureRequestConfigurer; +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 io.wwan13.wintersecurity.secretkey.support.SecretKeyRegistry; +import org.springframework.boot.test.context.TestConfiguration; + +@TestConfiguration +@EnableJwtProvider +@EnableSecureRequest +public class AllConfiguresTestConfigure + implements JwtProviderConfigurer, SecureRequestConfigurer { + + @Override + public void configureJwt(JwtPropertiesRegistry registry) { + registry + .accessTokenValidity(100000000000L) + .refreshTokenValidity(100000000000L); + } + + @Override + public void configureSecretKey(SecretKeyRegistry registry) { + registry + .secretKey("asdfghjklqwertyuiopzxcvbnmasddfgwerasf"); + } + + @Override + public void registerAuthPatterns(AuthorizedRequestRegistry registry) { + registry + .uriPatterns("/api/test/**") + .allHttpMethods() + .permitAll() + + .elseRequestAuthenticated(); + } + + @Override + public void registerTargetAnnotations(TargetAnnotationsRegistry registry) { + registry + .addSubjectResolveAnnotation(RequestUserId.class) + .addRolesResolveAnnotation(RequestUserRoles.class); + } +} diff --git a/src/test/java/io/wwan13/wintersecurity/context/jwtprovider/JwtProviderContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/jwtprovider/JwtProviderContextTest.java new file mode 100644 index 0000000..a50d5be --- /dev/null +++ b/src/test/java/io/wwan13/wintersecurity/context/jwtprovider/JwtProviderContextTest.java @@ -0,0 +1,29 @@ +/* + * 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.jwtprovider; + +import io.wwan13.wintersecurity.ContextTest; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +@Import(JwtProviderTestConfig.class) +public class JwtProviderContextTest extends ContextTest { + + @Test + void contextLoad() { + } +} diff --git a/src/test/java/io/wwan13/wintersecurity/context/jwtprovider/JwtProviderTestConfig.java b/src/test/java/io/wwan13/wintersecurity/context/jwtprovider/JwtProviderTestConfig.java new file mode 100644 index 0000000..a0e8358 --- /dev/null +++ b/src/test/java/io/wwan13/wintersecurity/context/jwtprovider/JwtProviderTestConfig.java @@ -0,0 +1,41 @@ +/* + * 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.jwtprovider; + +import io.wwan13.wintersecurity.config.EnableJwtProvider; +import io.wwan13.wintersecurity.config.JwtProviderConfigurer; +import io.wwan13.wintersecurity.jwt.support.JwtPropertiesRegistry; +import io.wwan13.wintersecurity.secretkey.support.SecretKeyRegistry; +import org.springframework.boot.test.context.TestConfiguration; + +@TestConfiguration +@EnableJwtProvider +public class JwtProviderTestConfig implements JwtProviderConfigurer { + + @Override + public void configureJwt(JwtPropertiesRegistry registry) { + registry + .accessTokenValidity(100000000000L) + .refreshTokenValidity(100000000000L); + } + + @Override + public void configureSecretKey(SecretKeyRegistry registry) { + registry + .secretKey("asdfghjklqwertyuiopzxcvbnmasddfgwerasf"); + } +} diff --git a/src/test/java/io/wwan13/wintersecurity/context/securerequest/SecureRequestContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/securerequest/SecureRequestContextTest.java new file mode 100644 index 0000000..bc9d67c --- /dev/null +++ b/src/test/java/io/wwan13/wintersecurity/context/securerequest/SecureRequestContextTest.java @@ -0,0 +1,29 @@ +/* + * 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.securerequest; + +import io.wwan13.wintersecurity.ContextTest; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +@Import(SecureRequestTestConfig.class) +public class SecureRequestContextTest extends ContextTest { + + @Test + void contextLoad() { + } +} diff --git a/src/test/java/io/wwan13/wintersecurity/context/securerequest/SecureRequestTestConfig.java b/src/test/java/io/wwan13/wintersecurity/context/securerequest/SecureRequestTestConfig.java new file mode 100644 index 0000000..dba38d0 --- /dev/null +++ b/src/test/java/io/wwan13/wintersecurity/context/securerequest/SecureRequestTestConfig.java @@ -0,0 +1,54 @@ +/* + * 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.securerequest; + +import io.wwan13.wintersecurity.auth.authorizedrequest.support.AuthorizedRequestRegistry; +import io.wwan13.wintersecurity.config.EnableSecureRequest; +import io.wwan13.wintersecurity.config.SecureRequestConfigurer; +import io.wwan13.wintersecurity.resolve.RequestUserId; +import io.wwan13.wintersecurity.resolve.RequestUserRoles; +import io.wwan13.wintersecurity.resolve.support.TargetAnnotationsRegistry; +import io.wwan13.wintersecurity.secretkey.support.SecretKeyRegistry; +import org.springframework.boot.test.context.TestConfiguration; + +@TestConfiguration +@EnableSecureRequest +public class SecureRequestTestConfig implements SecureRequestConfigurer { + + @Override + public void configureSecretKey(SecretKeyRegistry registry) { + registry + .secretKey("asdfghjklqwertyuiopzxcvbnmasddfgwerasf"); + } + + @Override + public void registerAuthPatterns(AuthorizedRequestRegistry registry) { + registry + .uriPatterns("/api/test/**") + .allHttpMethods() + .permitAll() + + .elseRequestAuthenticated(); + } + + @Override + public void registerTargetAnnotations(TargetAnnotationsRegistry registry) { + registry + .addSubjectResolveAnnotation(RequestUserId.class) + .addRolesResolveAnnotation(RequestUserRoles.class); + } +}