From 0c71eaa924b45c83b31fb9adf113be1c4df18e18 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Thu, 12 Sep 2024 15:38:09 -0600 Subject: [PATCH] Test Reactive Method Security with Abstract Classes Issue gh-15352 --- ...ctiveMethodSecurityConfigurationTests.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/config/src/test/java/org/springframework/security/config/annotation/method/configuration/PrePostReactiveMethodSecurityConfigurationTests.java b/config/src/test/java/org/springframework/security/config/annotation/method/configuration/PrePostReactiveMethodSecurityConfigurationTests.java index e1eea9d52c8..7c865efe4b3 100644 --- a/config/src/test/java/org/springframework/security/config/annotation/method/configuration/PrePostReactiveMethodSecurityConfigurationTests.java +++ b/config/src/test/java/org/springframework/security/config/annotation/method/configuration/PrePostReactiveMethodSecurityConfigurationTests.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import jakarta.annotation.security.DenyAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -37,6 +38,7 @@ import org.springframework.context.annotation.Role; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.PermissionEvaluator; +import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; import org.springframework.security.access.hierarchicalroles.RoleHierarchy; @@ -409,6 +411,13 @@ public void findAllWhenNestedPreAuthorizeThenAuthorizes() { }); } + // gh-15352 + @Test + void annotationsInChildClassesDoNotAffectSuperclasses() { + this.spring.register(AbstractClassConfig.class).autowire(); + this.spring.getContext().getBean(ClassInheritingAbstractClassWithNoAnnotations.class).method(); + } + @Configuration @EnableReactiveMethodSecurity static class MethodSecurityServiceEnabledConfig { @@ -706,4 +715,29 @@ public Mono getName() { } + abstract static class AbstractClassWithNoAnnotations { + + Mono method() { + return Mono.just("ok"); + } + + } + + @PreAuthorize("denyAll()") + @Secured("DENIED") + @DenyAll + static class ClassInheritingAbstractClassWithNoAnnotations extends AbstractClassWithNoAnnotations { + + } + + @EnableReactiveMethodSecurity + static class AbstractClassConfig { + + @Bean + ClassInheritingAbstractClassWithNoAnnotations inheriting() { + return new ClassInheritingAbstractClassWithNoAnnotations(); + } + + } + }