mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-27 14:22:47 +00:00
Annotation parameter scan finds first-level conflicts
Closes PR-16312
This commit is contained in:
parent
103ccb3b9d
commit
96b9820e19
@ -149,14 +149,10 @@ final class UniqueSecurityAnnotationScanner<A extends Annotation> extends Abstra
|
|||||||
}
|
}
|
||||||
Executable executable = current.getDeclaringExecutable();
|
Executable executable = current.getDeclaringExecutable();
|
||||||
if (executable instanceof Method method) {
|
if (executable instanceof Method method) {
|
||||||
Class<?> clazz = method.getDeclaringClass();
|
directAnnotations = findClosestParameterAnnotations(method, method.getDeclaringClass(), current,
|
||||||
Set<Class<?>> visited = new HashSet<>();
|
new HashSet<>());
|
||||||
while (clazz != null && clazz != Object.class) {
|
if (!directAnnotations.isEmpty()) {
|
||||||
directAnnotations = findClosestParameterAnnotations(method, clazz, current, visited);
|
return directAnnotations;
|
||||||
if (!directAnnotations.isEmpty()) {
|
|
||||||
return directAnnotations;
|
|
||||||
}
|
|
||||||
clazz = clazz.getSuperclass();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@ -164,10 +160,15 @@ final class UniqueSecurityAnnotationScanner<A extends Annotation> extends Abstra
|
|||||||
|
|
||||||
private List<MergedAnnotation<A>> findClosestParameterAnnotations(Method method, Class<?> clazz, Parameter current,
|
private List<MergedAnnotation<A>> findClosestParameterAnnotations(Method method, Class<?> clazz, Parameter current,
|
||||||
Set<Class<?>> visited) {
|
Set<Class<?>> visited) {
|
||||||
if (!visited.add(clazz)) {
|
if (clazz == null || clazz == Object.class || !visited.add(clazz)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<MergedAnnotation<A>> annotations = new ArrayList<>(findDirectParameterAnnotations(method, clazz, current));
|
List<MergedAnnotation<A>> directAnnotations = findDirectParameterAnnotations(method, clazz, current);
|
||||||
|
if (!directAnnotations.isEmpty()) {
|
||||||
|
return directAnnotations;
|
||||||
|
}
|
||||||
|
List<MergedAnnotation<A>> annotations = new ArrayList<>(
|
||||||
|
findClosestParameterAnnotations(method, clazz.getSuperclass(), current, visited));
|
||||||
for (Class<?> ifc : clazz.getInterfaces()) {
|
for (Class<?> ifc : clazz.getInterfaces()) {
|
||||||
annotations.addAll(findClosestParameterAnnotations(method, ifc, current, visited));
|
annotations.addAll(findClosestParameterAnnotations(method, ifc, current, visited));
|
||||||
}
|
}
|
||||||
|
@ -319,6 +319,13 @@ public class UniqueSecurityAnnotationScannerTests {
|
|||||||
assertThat(pre).isNotNull();
|
assertThat(pre).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void scanParameterAnnotationWhenPresentInParentAndInterfaceThenException() throws Exception {
|
||||||
|
Parameter parameter = DefaultUserService.class.getDeclaredMethod("batch", String[].class).getParameters()[0];
|
||||||
|
assertThatExceptionOfType(AnnotationConfigurationException.class)
|
||||||
|
.isThrownBy(() -> this.parameterScanner.scan(parameter));
|
||||||
|
}
|
||||||
|
|
||||||
interface UserService {
|
interface UserService {
|
||||||
|
|
||||||
void add(@CustomParameterAnnotation("one") String user);
|
void add(@CustomParameterAnnotation("one") String user);
|
||||||
@ -345,6 +352,8 @@ public class UniqueSecurityAnnotationScannerTests {
|
|||||||
|
|
||||||
interface RemoteUserService extends ThirdPartyUserService {
|
interface RemoteUserService extends ThirdPartyUserService {
|
||||||
|
|
||||||
|
void batch(@CustomParameterAnnotation("six") String... user);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class UserServiceImpl implements UserService, OtherUserService, RemoteUserService {
|
static class UserServiceImpl implements UserService, OtherUserService, RemoteUserService {
|
||||||
@ -369,6 +378,20 @@ public class UniqueSecurityAnnotationScannerTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void batch(@CustomParameterAnnotation("seven") String... user) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class DefaultUserService extends UserServiceImpl implements RemoteUserService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void batch(String... user) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Target({ ElementType.PARAMETER })
|
@Target({ ElementType.PARAMETER })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user