Skip to content

Distinguish same-distanced annotations in MergedAnnotations #34611

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

Open
jzheaux opened this issue Mar 17, 2025 · 0 comments
Open

Distinguish same-distanced annotations in MergedAnnotations #34611

jzheaux opened this issue Mar 17, 2025 · 0 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@jzheaux
Copy link
Contributor

jzheaux commented Mar 17, 2025

Spring Security does a search for annotations in a slightly different way than TYPE_HIERARCHY. It does the following:

  1. If it finds the annotation on the target method, then it stops searching
  2. Otherwise, it looks one level up (superclass + interfaces). If it finds the annotation on more than one, it errors; otherwise if it finds it on just one, it stops searching
  3. Otherwise, recursively return to level 2 for each class/interface

In other words, Security wants to use the @PreAuthorize annotation (for example) that is closest to the method being invoked, and if more than one is equally close, it errors.

The traversal logic is similar in many ways to AnnotationScanner, but I haven't found a way to exercise the API to achieve the above.

In talking with @sbrannen, it was thought that getAggregateIndex might allow for this kind of searching; however that does not appear to work, so this may be a bug.

Currently, Security duplicates the method hierarchy traversal logic in AnnotationsScanner in its authorization support. Whether a bug or an enhancement, being able to rely on MergedAnnotations instead would be more secure and easier to support.

@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Mar 17, 2025
@sbrannen sbrannen changed the title Distinguish Same-Distanced Annotations in MergedAnnotations Distinguish same-distanced annotations in MergedAnnotations Mar 17, 2025
@sbrannen sbrannen added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

2 participants