Skip to content

Commit

Permalink
Test Reactive Method Security with Abstract Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jzheaux committed Sep 12, 2024
1 parent 86ef0b6 commit 0c71eaa
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -706,4 +715,29 @@ public Mono<String> getName() {

}

abstract static class AbstractClassWithNoAnnotations {

Mono<String> 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();
}

}

}

0 comments on commit 0c71eaa

Please sign in to comment.