|
23 | 23 | import java.util.Map; |
24 | 24 | import java.util.concurrent.ConcurrentHashMap; |
25 | 25 |
|
| 26 | +import jakarta.annotation.security.DenyAll; |
26 | 27 | import org.junit.jupiter.api.Test; |
27 | 28 | import org.junit.jupiter.api.extension.ExtendWith; |
28 | 29 | import org.junit.jupiter.params.ParameterizedTest; |
|
37 | 38 | import org.springframework.context.annotation.Role; |
38 | 39 | import org.springframework.security.access.AccessDeniedException; |
39 | 40 | import org.springframework.security.access.PermissionEvaluator; |
| 41 | +import org.springframework.security.access.annotation.Secured; |
40 | 42 | import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; |
41 | 43 | import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; |
42 | 44 | import org.springframework.security.access.hierarchicalroles.RoleHierarchy; |
@@ -409,6 +411,13 @@ public void findAllWhenNestedPreAuthorizeThenAuthorizes() { |
409 | 411 | }); |
410 | 412 | } |
411 | 413 |
|
| 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 | + |
412 | 421 | @Configuration |
413 | 422 | @EnableReactiveMethodSecurity |
414 | 423 | static class MethodSecurityServiceEnabledConfig { |
@@ -706,4 +715,29 @@ public Mono<String> getName() { |
706 | 715 |
|
707 | 716 | } |
708 | 717 |
|
| 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 | + |
709 | 743 | } |
0 commit comments