From bb4a1728d6b15e537370c79bf927189ffcf35a5d Mon Sep 17 00:00:00 2001 From: wwan13 Date: Fri, 7 Jun 2024 23:06:06 +0900 Subject: [PATCH] refactor : Remove additional claims support annotations --- .../resolve/RequestUserClaim.java | 26 -------------- .../resolve/RequestUserClaims.java | 25 ------------- .../resolve/RequestUserPayload.java | 25 ------------- .../resolve/TargetAnnotations.java | 5 +-- .../support/TargetAnnotationsRegistry.java | 35 +------------------ .../resolve/TargetAnnotationsTest.java | 11 +----- .../TargetAnnotationsRegistryTest.java | 17 +-------- 7 files changed, 4 insertions(+), 140 deletions(-) delete mode 100644 src/main/java/io/wwan13/wintersecurity/resolve/RequestUserClaim.java delete mode 100644 src/main/java/io/wwan13/wintersecurity/resolve/RequestUserClaims.java delete mode 100644 src/main/java/io/wwan13/wintersecurity/resolve/RequestUserPayload.java diff --git a/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserClaim.java b/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserClaim.java deleted file mode 100644 index 1b6954f..0000000 --- a/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserClaim.java +++ /dev/null @@ -1,26 +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.resolve; - -import java.lang.annotation.*; - -@Target(ElementType.PARAMETER) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface RequestUserClaim { - String value() default ""; -} diff --git a/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserClaims.java b/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserClaims.java deleted file mode 100644 index fc83f1b..0000000 --- a/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserClaims.java +++ /dev/null @@ -1,25 +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.resolve; - -import java.lang.annotation.*; - -@Target(ElementType.PARAMETER) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface RequestUserClaims { -} diff --git a/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserPayload.java b/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserPayload.java deleted file mode 100644 index 742ce70..0000000 --- a/src/main/java/io/wwan13/wintersecurity/resolve/RequestUserPayload.java +++ /dev/null @@ -1,25 +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.resolve; - -import java.lang.annotation.*; - -@Target(ElementType.PARAMETER) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface RequestUserPayload { -} diff --git a/src/main/java/io/wwan13/wintersecurity/resolve/TargetAnnotations.java b/src/main/java/io/wwan13/wintersecurity/resolve/TargetAnnotations.java index 2eea4bf..cad2077 100644 --- a/src/main/java/io/wwan13/wintersecurity/resolve/TargetAnnotations.java +++ b/src/main/java/io/wwan13/wintersecurity/resolve/TargetAnnotations.java @@ -21,9 +21,6 @@ public record TargetAnnotations( Set> forSubject, - Set> forRoles, - Set> forClaims, - Set> forClaim, - Set> forPayload + Set> forRoles ) { } diff --git a/src/main/java/io/wwan13/wintersecurity/resolve/support/TargetAnnotationsRegistry.java b/src/main/java/io/wwan13/wintersecurity/resolve/support/TargetAnnotationsRegistry.java index 5ff1e73..290458b 100644 --- a/src/main/java/io/wwan13/wintersecurity/resolve/support/TargetAnnotationsRegistry.java +++ b/src/main/java/io/wwan13/wintersecurity/resolve/support/TargetAnnotationsRegistry.java @@ -28,25 +28,13 @@ public class TargetAnnotationsRegistry { = Set.of(RequestUserSubject.class, RequestUserId.class); private final static Set> DEFAULT_ROLES_TARGETS = Set.of(RequestUserRoles.class); - private final static Set> DEFAULT_CLAIMS_TARGETS - = Set.of(RequestUserClaims.class); - private final static Set> DEFAULT_CLAIM_TARGETS - = Set.of(RequestUserClaim.class); - private final static Set> DEFAULT_PAYLOAD_TARGETS - = Set.of(RequestUserPayload.class); private final Set> forSubject; private final Set> forRoles; - private final Set> forClaims; - private final Set> forClaim; - private final Set> forPayload; public TargetAnnotationsRegistry() { this.forSubject = new HashSet<>(DEFAULT_SUBJECT_TARGETS); this.forRoles = new HashSet<>(DEFAULT_ROLES_TARGETS); - this.forClaims = new HashSet<>(DEFAULT_CLAIMS_TARGETS); - this.forClaim = new HashSet<>(DEFAULT_CLAIM_TARGETS); - this.forPayload = new HashSet<>(DEFAULT_PAYLOAD_TARGETS); } public TargetAnnotationsRegistry addSubjectResolveAnnotation( @@ -63,28 +51,7 @@ public TargetAnnotationsRegistry addRolesResolveAnnotation( return this; } - public TargetAnnotationsRegistry addClaimsResolveAnnotation( - Class target - ) { - forClaims.add(target); - return this; - } - - public TargetAnnotationsRegistry addClaimResolveAnnotation( - Class target - ) { - forClaim.add(target); - return this; - } - - public TargetAnnotationsRegistry addPayloadResolveAnnotation( - Class target - ) { - forPayload.add(target); - return this; - } - protected TargetAnnotations apply() { - return new TargetAnnotations(forSubject, forRoles, forClaims, forClaim, forPayload); + return new TargetAnnotations(forSubject, forRoles); } } diff --git a/src/test/java/io/wwan13/wintersecurity/resolve/TargetAnnotationsTest.java b/src/test/java/io/wwan13/wintersecurity/resolve/TargetAnnotationsTest.java index fbe30d5..530bf48 100644 --- a/src/test/java/io/wwan13/wintersecurity/resolve/TargetAnnotationsTest.java +++ b/src/test/java/io/wwan13/wintersecurity/resolve/TargetAnnotationsTest.java @@ -31,25 +31,16 @@ void should_ContainsTargetAnnotationInfo() { // given final Class forSubject = RequestUserSubject.class; final Class forRoles = RequestUserRoles.class; - final Class forClaims = RequestUserClaims.class; - final Class forClaim = RequestUserClaim.class; - final Class forPayload = RequestUserPayload.class; // when TargetAnnotations targetAnnotations = new TargetAnnotations( Set.of(forSubject), - Set.of(forRoles), - Set.of(forClaims), - Set.of(forClaim), - Set.of(forPayload) + Set.of(forRoles) ); // then assertThat(targetAnnotations).isInstanceOf(TargetAnnotations.class); assertThat(targetAnnotations.forSubject()).contains(forSubject); assertThat(targetAnnotations.forRoles()).contains(forRoles); - assertThat(targetAnnotations.forClaims()).contains(forClaims); - assertThat(targetAnnotations.forClaim()).contains(forClaim); - assertThat(targetAnnotations.forPayload()).contains(forPayload); } } \ No newline at end of file diff --git a/src/test/java/io/wwan13/wintersecurity/resolve/support/TargetAnnotationsRegistryTest.java b/src/test/java/io/wwan13/wintersecurity/resolve/support/TargetAnnotationsRegistryTest.java index 5968611..c0af7ed 100644 --- a/src/test/java/io/wwan13/wintersecurity/resolve/support/TargetAnnotationsRegistryTest.java +++ b/src/test/java/io/wwan13/wintersecurity/resolve/support/TargetAnnotationsRegistryTest.java @@ -17,10 +17,7 @@ package io.wwan13.wintersecurity.resolve.support; import io.wwan13.wintersecurity.UnitTest; -import io.wwan13.wintersecurity.resolve.RequestUserClaim; -import io.wwan13.wintersecurity.resolve.RequestUserClaims; import io.wwan13.wintersecurity.resolve.RequestUserId; -import io.wwan13.wintersecurity.resolve.RequestUserPayload; import io.wwan13.wintersecurity.resolve.RequestUserRoles; import io.wwan13.wintersecurity.resolve.RequestUserSubject; import io.wwan13.wintersecurity.resolve.TargetAnnotations; @@ -37,17 +34,11 @@ void should_CreateTargetAnnotationsObject_when_Apply() { // given final Class forSubject = RequestUserSubject.class; final Class forRoles = RequestUserRoles.class; - final Class forClaims = RequestUserClaims.class; - final Class forClaim = RequestUserClaim.class; - final Class forPayload = RequestUserPayload.class; TargetAnnotationsRegistry registry = new TargetAnnotationsRegistry(); registry .addSubjectResolveAnnotation(forSubject) - .addRolesResolveAnnotation(forRoles) - .addClaimsResolveAnnotation(forClaims) - .addClaimResolveAnnotation(forClaim) - .addPayloadResolveAnnotation(forPayload); + .addRolesResolveAnnotation(forRoles); // when TargetAnnotations targetAnnotations = registry.apply(); @@ -56,9 +47,6 @@ void should_CreateTargetAnnotationsObject_when_Apply() { assertThat(targetAnnotations).isInstanceOf(TargetAnnotations.class); assertThat(targetAnnotations.forSubject()).contains(forSubject); assertThat(targetAnnotations.forRoles()).contains(forRoles); - assertThat(targetAnnotations.forClaims()).contains(forClaims); - assertThat(targetAnnotations.forClaim()).contains(forClaim); - assertThat(targetAnnotations.forPayload()).contains(forPayload); } @Test @@ -73,8 +61,5 @@ void should_ContainsDefaultTargetAnnotations_when_NotingEntered() { assertThat(targetAnnotations.forSubject()) .contains(RequestUserSubject.class, RequestUserId.class); assertThat(targetAnnotations.forRoles()).contains(RequestUserRoles.class); - assertThat(targetAnnotations.forClaims()).contains(RequestUserClaims.class); - assertThat(targetAnnotations.forClaim()).contains(RequestUserClaim.class); - assertThat(targetAnnotations.forPayload()).contains(RequestUserPayload.class); } } \ No newline at end of file