Skip to content

Commit f8272a8

Browse files
committed
Fallback to Object When Determining Overridden Methods
Closes gh-17898
1 parent f844a97 commit f8272a8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

core/src/main/java/org/springframework/security/core/annotation/UniqueSecurityAnnotationScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private static boolean hasSameGenericTypeParameters(Method rootMethod, Method ca
308308
}
309309
for (int i = 0; i < rootParameterTypes.length; i++) {
310310
Class<?> resolvedParameterType = ResolvableType.forMethodParameter(candidateMethod, i, sourceDeclaringClass)
311-
.resolve();
311+
.toClass();
312312
if (rootParameterTypes[i] != resolvedParameterType) {
313313
return false;
314314
}

core/src/test/java/org/springframework/security/core/annotation/UniqueSecurityAnnotationScannerTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.core.annotation.AnnotationConfigurationException;
3030
import org.springframework.security.access.prepost.PreAuthorize;
31+
import org.springframework.util.ClassUtils;
3132

3233
import static org.assertj.core.api.Assertions.assertThat;
3334
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -326,6 +327,14 @@ void scanParameterAnnotationWhenPresentInParentAndInterfaceThenException() throw
326327
.isThrownBy(() -> this.parameterScanner.scan(parameter));
327328
}
328329

330+
// gh-17898
331+
@Test
332+
void scanWhenAnnotationOnParameterizedUndeclaredMethodAndThenLocates() throws Exception {
333+
Method method = ClassUtils.getMethod(GenericInterfaceImpl.class, "processOneAndTwo", Long.class, Object.class);
334+
PreAuthorize pre = this.scanner.scan(method, method.getDeclaringClass());
335+
assertThat(pre).isNotNull();
336+
}
337+
329338
interface UserService {
330339

331340
void add(@CustomParameterAnnotation("one") String user);
@@ -764,4 +773,27 @@ <S extends Number> S getExtByClass(Class<S> clazz, Long l) {
764773

765774
}
766775

776+
interface GenericInterface<A, B> {
777+
778+
@PreAuthorize("hasAuthority('thirtythree')")
779+
void processOneAndTwo(A value1, B value2);
780+
781+
}
782+
783+
abstract static class GenericAbstractSuperclass<C> implements GenericInterface<Long, C> {
784+
785+
@Override
786+
public void processOneAndTwo(Long value1, C value2) {
787+
}
788+
789+
}
790+
791+
static class GenericInterfaceImpl extends GenericAbstractSuperclass<String> {
792+
793+
// The compiler does not require us to declare a concrete
794+
// processOneAndTwo(Long, String) method, and we intentionally
795+
// do not declare one here.
796+
797+
}
798+
767799
}

0 commit comments

Comments
 (0)