Skip to content

Commit 3e1f8bb

Browse files
committed
Test Reactive Method Security with Abstract Classes
Issue gh-15352
1 parent fee5dd3 commit 3e1f8bb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

config/src/test/java/org/springframework/security/config/annotation/method/configuration/PrePostReactiveMethodSecurityConfigurationTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.concurrent.ConcurrentHashMap;
2525

26+
import jakarta.annotation.security.DenyAll;
2627
import org.junit.jupiter.api.Test;
2728
import org.junit.jupiter.api.extension.ExtendWith;
2829
import org.junit.jupiter.params.ParameterizedTest;
@@ -37,6 +38,7 @@
3738
import org.springframework.context.annotation.Role;
3839
import org.springframework.security.access.AccessDeniedException;
3940
import org.springframework.security.access.PermissionEvaluator;
41+
import org.springframework.security.access.annotation.Secured;
4042
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
4143
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
4244
import org.springframework.security.access.hierarchicalroles.RoleHierarchy;
@@ -409,6 +411,13 @@ public void findAllWhenNestedPreAuthorizeThenAuthorizes() {
409411
});
410412
}
411413

414+
// gh-15352
415+
@Test
416+
void annotationsInChildClassesDoNotAffectSuperclasses() {
417+
this.spring.register(AbstractClassConfig.class).autowire();
418+
this.spring.getContext().getBean(ClassInheritingAbstractClassWithNoAnnotations.class).method();
419+
}
420+
412421
@Configuration
413422
@EnableReactiveMethodSecurity
414423
static class MethodSecurityServiceEnabledConfig {
@@ -706,4 +715,29 @@ public Mono<String> getName() {
706715

707716
}
708717

718+
abstract static class AbstractClassWithNoAnnotations {
719+
720+
Mono<String> method() {
721+
return Mono.just("ok");
722+
}
723+
724+
}
725+
726+
@PreAuthorize("denyAll()")
727+
@Secured("DENIED")
728+
@DenyAll
729+
static class ClassInheritingAbstractClassWithNoAnnotations extends AbstractClassWithNoAnnotations {
730+
731+
}
732+
733+
@EnableReactiveMethodSecurity
734+
static class AbstractClassConfig {
735+
736+
@Bean
737+
ClassInheritingAbstractClassWithNoAnnotations inheriting() {
738+
return new ClassInheritingAbstractClassWithNoAnnotations();
739+
}
740+
741+
}
742+
709743
}

0 commit comments

Comments
 (0)