-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Provide Runtime Hints for Beans used in Pre/PostAuthorize Expressions #14790
Conversation
private static <A extends Annotation> A findDistinctAnnotation(AnnotatedElement annotatedElement, | ||
Class<A> annotationType, Function<MergedAnnotation<A>, A> map) { | ||
MergedAnnotations mergedAnnotations = MergedAnnotations.from(annotatedElement, | ||
MergedAnnotations.SearchStrategy.TYPE_HIERARCHY, RepeatableContainers.none()); | ||
List<A> annotations = mergedAnnotations.stream(annotationType) | ||
.map(MergedAnnotation::withNonMergedAttributes) | ||
.map(map) | ||
.distinct() | ||
.toList(); | ||
|
||
return switch (annotations.size()) { | ||
case 0 -> null; | ||
case 1 -> annotations.get(0); | ||
default -> throw new AnnotationConfigurationException(""" | ||
Please ensure there is one unique annotation of type @%s attributed to %s. \ | ||
Found %d competing annotations: %s""".formatted(annotationType.getName(), annotatedElement, | ||
annotations.size(), annotations)); | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jzheaux This was copied from AuthorizationAnnotationUtils
. My concern is that this logic can change and then we have to remember to update it on multiple places. Any idea on how we can reuse the same logic?
As per @jzheaux comments: it's not always clear from the bean factory which type it is that we should be proxying, like in the case of Spring Data, which publishes a factory bean (so the interface that has the annotations isn't yet known). With that said, we might have to adopt another strategy to find the components to register hints, maybe by doing a component scan. |
I'll close this for now for the following reasons:
|
Closes gh-14652