|
73 | 73 | import static org.mockito.ArgumentMatchers.any;
|
74 | 74 | import static org.mockito.Mockito.atLeastOnce;
|
75 | 75 | import static org.mockito.Mockito.mock;
|
| 76 | +import static org.mockito.Mockito.spy; |
| 77 | +import static org.mockito.Mockito.times; |
76 | 78 | import static org.mockito.Mockito.verify;
|
77 | 79 |
|
78 | 80 | /**
|
@@ -447,6 +449,18 @@ public void configureWhenBeanOverridingDisallowedThenWorks() {
|
447 | 449 | .autowire();
|
448 | 450 | }
|
449 | 451 |
|
| 452 | + // gh-15651 |
| 453 | + @Test |
| 454 | + @WithMockUser(roles = "ADMIN") |
| 455 | + public void adviseWhenPrePostEnabledThenEachInterceptorRunsExactlyOnce() { |
| 456 | + this.spring.register(MethodSecurityServiceConfig.class, CustomMethodSecurityExpressionHandlerConfig.class) |
| 457 | + .autowire(); |
| 458 | + MethodSecurityExpressionHandler expressionHandler = this.spring.getContext() |
| 459 | + .getBean(MethodSecurityExpressionHandler.class); |
| 460 | + this.methodSecurityService.manyAnnotations(new ArrayList<>(Arrays.asList("harold", "jonathan", "tim", "bo"))); |
| 461 | + verify(expressionHandler, times(4)).createEvaluationContext(any(Supplier.class), any()); |
| 462 | + } |
| 463 | + |
450 | 464 | private static Consumer<ConfigurableWebApplicationContext> disallowBeanOverriding() {
|
451 | 465 | return (context) -> ((AnnotationConfigWebApplicationContext) context).setAllowBeanDefinitionOverriding(false);
|
452 | 466 | }
|
@@ -523,6 +537,19 @@ MethodSecurityService methodSecurityService() {
|
523 | 537 | }
|
524 | 538 |
|
525 | 539 | @Configuration
|
| 540 | + @EnableMethodSecurity |
| 541 | + static class CustomMethodSecurityExpressionHandlerConfig { |
| 542 | + |
| 543 | + private final MethodSecurityExpressionHandler expressionHandler = spy( |
| 544 | + new DefaultMethodSecurityExpressionHandler()); |
| 545 | + |
| 546 | + @Bean |
| 547 | + MethodSecurityExpressionHandler methodSecurityExpressionHandler() { |
| 548 | + return this.expressionHandler; |
| 549 | + } |
| 550 | + |
| 551 | + } |
| 552 | + |
526 | 553 | @EnableMethodSecurity
|
527 | 554 | static class CustomPermissionEvaluatorConfig {
|
528 | 555 |
|
|
0 commit comments