Skip to content

Commit

Permalink
refactor : Remove additional claims support annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed Jun 7, 2024
1 parent 995797d commit bb4a172
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 140 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

public record TargetAnnotations(
Set<Class<? extends Annotation>> forSubject,
Set<Class<? extends Annotation>> forRoles,
Set<Class<? extends Annotation>> forClaims,
Set<Class<? extends Annotation>> forClaim,
Set<Class<? extends Annotation>> forPayload
Set<Class<? extends Annotation>> forRoles
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,13 @@ public class TargetAnnotationsRegistry {
= Set.of(RequestUserSubject.class, RequestUserId.class);
private final static Set<Class<? extends Annotation>> DEFAULT_ROLES_TARGETS
= Set.of(RequestUserRoles.class);
private final static Set<Class<? extends Annotation>> DEFAULT_CLAIMS_TARGETS
= Set.of(RequestUserClaims.class);
private final static Set<Class<? extends Annotation>> DEFAULT_CLAIM_TARGETS
= Set.of(RequestUserClaim.class);
private final static Set<Class<? extends Annotation>> DEFAULT_PAYLOAD_TARGETS
= Set.of(RequestUserPayload.class);

private final Set<Class<? extends Annotation>> forSubject;
private final Set<Class<? extends Annotation>> forRoles;
private final Set<Class<? extends Annotation>> forClaims;
private final Set<Class<? extends Annotation>> forClaim;
private final Set<Class<? extends Annotation>> 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(
Expand All @@ -63,28 +51,7 @@ public TargetAnnotationsRegistry addRolesResolveAnnotation(
return this;
}

public TargetAnnotationsRegistry addClaimsResolveAnnotation(
Class<? extends Annotation> target
) {
forClaims.add(target);
return this;
}

public TargetAnnotationsRegistry addClaimResolveAnnotation(
Class<? extends Annotation> target
) {
forClaim.add(target);
return this;
}

public TargetAnnotationsRegistry addPayloadResolveAnnotation(
Class<? extends Annotation> target
) {
forPayload.add(target);
return this;
}

protected TargetAnnotations apply() {
return new TargetAnnotations(forSubject, forRoles, forClaims, forClaim, forPayload);
return new TargetAnnotations(forSubject, forRoles);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,16 @@ void should_ContainsTargetAnnotationInfo() {
// given
final Class<? extends Annotation> forSubject = RequestUserSubject.class;
final Class<? extends Annotation> forRoles = RequestUserRoles.class;
final Class<? extends Annotation> forClaims = RequestUserClaims.class;
final Class<? extends Annotation> forClaim = RequestUserClaim.class;
final Class<? extends Annotation> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,17 +34,11 @@ void should_CreateTargetAnnotationsObject_when_Apply() {
// given
final Class<? extends Annotation> forSubject = RequestUserSubject.class;
final Class<? extends Annotation> forRoles = RequestUserRoles.class;
final Class<? extends Annotation> forClaims = RequestUserClaims.class;
final Class<? extends Annotation> forClaim = RequestUserClaim.class;
final Class<? extends Annotation> 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();
Expand All @@ -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
Expand All @@ -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);
}
}

0 comments on commit bb4a172

Please sign in to comment.