Skip to content

Commit e5694ac

Browse files
committed
Fallback to Object When Determining Overridden Methods
Closes gh-17898
1 parent 9de0aad commit e5694ac

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
@@ -252,7 +252,7 @@ private static boolean hasSameGenericTypeParameters(Method rootMethod, Method ca
252252
}
253253
for (int i = 0; i < rootParameterTypes.length; i++) {
254254
Class<?> resolvedParameterType = ResolvableType.forMethodParameter(candidateMethod, i, sourceDeclaringClass)
255-
.resolve();
255+
.toClass();
256256
if (rootParameterTypes[i] != resolvedParameterType) {
257257
return false;
258258
}

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
@@ -22,6 +22,7 @@
2222

2323
import org.springframework.core.annotation.AnnotationConfigurationException;
2424
import org.springframework.security.access.prepost.PreAuthorize;
25+
import org.springframework.util.ClassUtils;
2526

2627
import static org.assertj.core.api.Assertions.assertThat;
2728
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -275,6 +276,14 @@ void scanWhenAnnotationOnParameterizedMethodThenLocates() throws Exception {
275276
assertThat(pre).isNotNull();
276277
}
277278

279+
// gh-17898
280+
@Test
281+
void scanWhenAnnotationOnParameterizedUndeclaredMethodAndThenLocates() throws Exception {
282+
Method method = ClassUtils.getMethod(GenericInterfaceImpl.class, "processOneAndTwo", Long.class, Object.class);
283+
PreAuthorize pre = this.scanner.scan(method, method.getDeclaringClass());
284+
assertThat(pre).isNotNull();
285+
}
286+
278287
@PreAuthorize("one")
279288
private interface AnnotationOnInterface {
280289

@@ -637,4 +646,27 @@ <S extends Number> S getExtByClass(Class<S> clazz, Long l) {
637646

638647
}
639648

649+
interface GenericInterface<A, B> {
650+
651+
@PreAuthorize("hasAuthority('thirtythree')")
652+
void processOneAndTwo(A value1, B value2);
653+
654+
}
655+
656+
abstract static class GenericAbstractSuperclass<C> implements GenericInterface<Long, C> {
657+
658+
@Override
659+
public void processOneAndTwo(Long value1, C value2) {
660+
}
661+
662+
}
663+
664+
static class GenericInterfaceImpl extends GenericAbstractSuperclass<String> {
665+
666+
// The compiler does not require us to declare a concrete
667+
// processOneAndTwo(Long, String) method, and we intentionally
668+
// do not declare one here.
669+
670+
}
671+
640672
}

0 commit comments

Comments
 (0)