|
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 | /**
|
@@ -432,6 +434,18 @@ public void configureWhenBeanOverridingDisallowedThenWorks() {
|
432 | 434 | .autowire();
|
433 | 435 | }
|
434 | 436 |
|
| 437 | + // gh-15651 |
| 438 | + @Test |
| 439 | + @WithMockUser(roles = "ADMIN") |
| 440 | + public void adviseWhenPrePostEnabledThenEachInterceptorRunsExactlyOnce() { |
| 441 | + this.spring.register(MethodSecurityServiceConfig.class, CustomMethodSecurityExpressionHandlerConfig.class) |
| 442 | + .autowire(); |
| 443 | + MethodSecurityExpressionHandler expressionHandler = this.spring.getContext() |
| 444 | + .getBean(MethodSecurityExpressionHandler.class); |
| 445 | + this.methodSecurityService.manyAnnotations(new ArrayList<>(Arrays.asList("harold", "jonathan", "tim", "bo"))); |
| 446 | + verify(expressionHandler, times(4)).createEvaluationContext(any(Supplier.class), any()); |
| 447 | + } |
| 448 | + |
435 | 449 | private static Consumer<ConfigurableWebApplicationContext> disallowBeanOverriding() {
|
436 | 450 | return (context) -> ((AnnotationConfigWebApplicationContext) context).setAllowBeanDefinitionOverriding(false);
|
437 | 451 | }
|
@@ -491,6 +505,19 @@ MethodSecurityService methodSecurityService() {
|
491 | 505 |
|
492 | 506 | }
|
493 | 507 |
|
| 508 | + @EnableMethodSecurity |
| 509 | + static class CustomMethodSecurityExpressionHandlerConfig { |
| 510 | + |
| 511 | + private final MethodSecurityExpressionHandler expressionHandler = spy( |
| 512 | + new DefaultMethodSecurityExpressionHandler()); |
| 513 | + |
| 514 | + @Bean |
| 515 | + MethodSecurityExpressionHandler methodSecurityExpressionHandler() { |
| 516 | + return this.expressionHandler; |
| 517 | + } |
| 518 | + |
| 519 | + } |
| 520 | + |
494 | 521 | @EnableMethodSecurity
|
495 | 522 | static class CustomPermissionEvaluatorConfig {
|
496 | 523 |
|
|
0 commit comments