Skip to content

Commit

Permalink
Merge branch '6.1.x' into 6.2.x
Browse files Browse the repository at this point in the history
Closes gh-14267
  • Loading branch information
jzheaux committed Dec 9, 2023
2 parents 981bc1e + 9f90661 commit 6e636e6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,28 @@ static <A extends Annotation> A findUniqueAnnotation(Class<?> type, Class<A> ann

private static <A extends Annotation> boolean hasDuplicate(MergedAnnotations mergedAnnotations,
Class<A> annotationType) {
boolean alreadyFound = false;
MergedAnnotation<Annotation> alreadyFound = null;
for (MergedAnnotation<Annotation> mergedAnnotation : mergedAnnotations) {
if (isSynthetic(mergedAnnotation.getSource())) {
continue;
}

if (mergedAnnotation.getType() == annotationType) {
if (alreadyFound) {
return true;
}
alreadyFound = true;
if (mergedAnnotation.getType() != annotationType) {
continue;
}

if (alreadyFound == null) {
alreadyFound = mergedAnnotation;
continue;
}

// https://github.com/spring-projects/spring-framework/issues/31803
if (!mergedAnnotation.getSource().equals(alreadyFound.getSource())) {
return true;
}

if (mergedAnnotation.getRoot().getType() != alreadyFound.getRoot().getType()) {
return true;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ void annotationsOnSyntheticMethodsShouldNotTriggerAnnotationConfigurationExcepti
.isThrownBy(() -> AuthorizationAnnotationUtils.findUniqueAnnotation(method, PreAuthorize.class));
}

@Test // gh-13625
void annotationsFromSuperSuperInterfaceShouldNotTriggerAnnotationConfigurationException() throws Exception {
Method method = HelloImpl.class.getMethod("sayHello");
assertThatNoException()
.isThrownBy(() -> AuthorizationAnnotationUtils.findUniqueAnnotation(method, PreAuthorize.class));
}

private interface BaseRepository<T> {

Iterable<T> findAll();
Expand All @@ -55,4 +62,24 @@ private interface StringRepository extends BaseRepository<String> {

}

private interface Hello {

@PreAuthorize("hasRole('someRole')")
String sayHello();

}

private interface SayHello extends Hello {

}

private static class HelloImpl implements SayHello {

@Override
public String sayHello() {
return "hello";
}

}

}

0 comments on commit 6e636e6

Please sign in to comment.