Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token-validation-*: look for annotations more robustly, support for meta annotations #191

Merged
merged 1 commit into from
Aug 5, 2020

Conversation

janolaveide
Copy link
Contributor

@janolaveide janolaveide commented Jul 17, 2020

The JwtTokenAnnotationHandler inspects the handler method of an incoming rest call in order to determine which (if any) annotations of type Protected, ProtectedWithClaims or Protected are present, and thus need to be honoured. The currrent implementation only inspects the direct/immediate annotations on the method or the class. This makes it impossible to group common annotations into a meta-annotation e.g like

@RestController
@ProtectedWithClaims(issuer = "selvbetjening", claimMap = { "acr=Level4" })
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

public @interface ProtectedRestController {

}

It also makes it impossible for these annotations to be detected if they are present on an interface or a superclass. This PR creates a subclass SpringJwtTokenAnnotationHandler that overrides the getAnnotations method. This methods then uses a Spring utility class AnnotationsUtils to detect annotations on the method/class also if they are provided via meta-annotations or superclasses/interfaces.
Note that this will only work when using Spring Boot. Ideally this extension should be on the JwtTokenAnnotationHandler itself, but implementing this using JDK-methods only is quite a mouthful, and left as an exercise to the maintainers. :-)

@janolaveide janolaveide marked this pull request as draft July 17, 2020 08:17
@janolaveide janolaveide marked this pull request as ready for review July 17, 2020 08:35
@janolaveide janolaveide changed the title support meta-annotations be more robudt when looking for annotations Jul 20, 2020
@janolaveide janolaveide changed the title be more robudt when looking for annotations be more robust when looking for annotations Jul 20, 2020
@janolaveide janolaveide changed the title be more robust when looking for annotations Look for annotations more robustly Jul 20, 2020
@tommytroen tommytroen added the enhancement New feature or request label Aug 3, 2020
Copy link
Collaborator

@tommytroen tommytroen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition :)
LGTM

@janolaveide
Copy link
Contributor Author

Får du merget denne også @tommytroen ?

@tommytroen
Copy link
Collaborator

Får du merget denne også @tommytroen ?

Will do. Tenker å få med noen flere PRs før vi releaser, men bør kunne få ut en senere i dag eller i morgen. @janolaveide

@tommytroen tommytroen merged commit bc8c32f into master Aug 5, 2020
@tommytroen tommytroen deleted the meta branch August 5, 2020 07:53
@tommytroen tommytroen changed the title Look for annotations more robustly token-validation-*: look for annotations more robustly, support for meta annotations Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants