3333import org .aopalliance .intercept .MethodInvocation ;
3434import org .junit .jupiter .api .Test ;
3535import org .junit .jupiter .api .extension .ExtendWith ;
36+ import org .junit .jupiter .params .ParameterizedTest ;
37+ import org .junit .jupiter .params .provider .ValueSource ;
3638
3739import org .springframework .aop .Advisor ;
3840import org .springframework .aop .support .DefaultPointcutAdvisor ;
7880import org .springframework .security .config .test .SpringTestContextExtension ;
7981import org .springframework .security .config .test .SpringTestParentApplicationContextExecutionListener ;
8082import org .springframework .security .core .Authentication ;
83+ import org .springframework .security .core .annotation .AnnotationTemplateExpressionDefaults ;
8184import org .springframework .security .core .context .SecurityContextHolderStrategy ;
8285import org .springframework .security .test .context .support .WithAnonymousUser ;
8386import org .springframework .security .test .context .support .WithMockUser ;
@@ -607,69 +610,77 @@ public void allAnnotationsWhenAdviceAfterAllOffsetThenReturnsFilteredList() {
607610 assertThat (filtered ).containsExactly ("DoNotDrop" );
608611 }
609612
610- @ Test
613+ @ ParameterizedTest
614+ @ ValueSource (classes = { LegacyMetaAnnotationPlaceholderConfig .class , MetaAnnotationPlaceholderConfig .class })
611615 @ WithMockUser
612- public void methodeWhenParameterizedPreAuthorizeMetaAnnotationThenPasses () {
613- this .spring .register (MetaAnnotationPlaceholderConfig . class ).autowire ();
616+ public void methodeWhenParameterizedPreAuthorizeMetaAnnotationThenPasses (Class <?> config ) {
617+ this .spring .register (config ).autowire ();
614618 MetaAnnotationService service = this .spring .getContext ().getBean (MetaAnnotationService .class );
615619 assertThat (service .hasRole ("USER" )).isTrue ();
616620 }
617621
618- @ Test
622+ @ ParameterizedTest
623+ @ ValueSource (classes = { LegacyMetaAnnotationPlaceholderConfig .class , MetaAnnotationPlaceholderConfig .class })
619624 @ WithMockUser
620- public void methodRoleWhenPreAuthorizeMetaAnnotationHardcodedParameterThenPasses () {
621- this .spring .register (MetaAnnotationPlaceholderConfig . class ).autowire ();
625+ public void methodRoleWhenPreAuthorizeMetaAnnotationHardcodedParameterThenPasses (Class <?> config ) {
626+ this .spring .register (config ).autowire ();
622627 MetaAnnotationService service = this .spring .getContext ().getBean (MetaAnnotationService .class );
623628 assertThat (service .hasUserRole ()).isTrue ();
624629 }
625630
626- @ Test
627- public void methodWhenParameterizedAnnotationThenFails () {
628- this .spring .register (MetaAnnotationPlaceholderConfig .class ).autowire ();
631+ @ ParameterizedTest
632+ @ ValueSource (classes = { LegacyMetaAnnotationPlaceholderConfig .class , MetaAnnotationPlaceholderConfig .class })
633+ public void methodWhenParameterizedAnnotationThenFails (Class <?> config ) {
634+ this .spring .register (config ).autowire ();
629635 MetaAnnotationService service = this .spring .getContext ().getBean (MetaAnnotationService .class );
630636 assertThatExceptionOfType (IllegalArgumentException .class )
631637 .isThrownBy (service ::placeholdersOnlyResolvedByMetaAnnotations );
632638 }
633639
634- @ Test
640+ @ ParameterizedTest
641+ @ ValueSource (classes = { LegacyMetaAnnotationPlaceholderConfig .class , MetaAnnotationPlaceholderConfig .class })
635642 @ WithMockUser (authorities = "SCOPE_message:read" )
636- public void methodWhenMultiplePlaceholdersHasAuthorityThenPasses () {
637- this .spring .register (MetaAnnotationPlaceholderConfig . class ).autowire ();
643+ public void methodWhenMultiplePlaceholdersHasAuthorityThenPasses (Class <?> config ) {
644+ this .spring .register (config ).autowire ();
638645 MetaAnnotationService service = this .spring .getContext ().getBean (MetaAnnotationService .class );
639646 assertThat (service .readMessage ()).isEqualTo ("message" );
640647 }
641648
642- @ Test
649+ @ ParameterizedTest
650+ @ ValueSource (classes = { LegacyMetaAnnotationPlaceholderConfig .class , MetaAnnotationPlaceholderConfig .class })
643651 @ WithMockUser (roles = "ADMIN" )
644- public void methodWhenMultiplePlaceholdersHasRoleThenPasses () {
645- this .spring .register (MetaAnnotationPlaceholderConfig . class ).autowire ();
652+ public void methodWhenMultiplePlaceholdersHasRoleThenPasses (Class <?> config ) {
653+ this .spring .register (config ).autowire ();
646654 MetaAnnotationService service = this .spring .getContext ().getBean (MetaAnnotationService .class );
647655 assertThat (service .readMessage ()).isEqualTo ("message" );
648656 }
649657
650- @ Test
658+ @ ParameterizedTest
659+ @ ValueSource (classes = { LegacyMetaAnnotationPlaceholderConfig .class , MetaAnnotationPlaceholderConfig .class })
651660 @ WithMockUser
652- public void methodWhenPostAuthorizeMetaAnnotationThenAuthorizes () {
653- this .spring .register (MetaAnnotationPlaceholderConfig . class ).autowire ();
661+ public void methodWhenPostAuthorizeMetaAnnotationThenAuthorizes (Class <?> config ) {
662+ this .spring .register (config ).autowire ();
654663 MetaAnnotationService service = this .spring .getContext ().getBean (MetaAnnotationService .class );
655664 service .startsWithDave ("daveMatthews" );
656665 assertThatExceptionOfType (AccessDeniedException .class )
657666 .isThrownBy (() -> service .startsWithDave ("jenniferHarper" ));
658667 }
659668
660- @ Test
669+ @ ParameterizedTest
670+ @ ValueSource (classes = { LegacyMetaAnnotationPlaceholderConfig .class , MetaAnnotationPlaceholderConfig .class })
661671 @ WithMockUser
662- public void methodWhenPreFilterMetaAnnotationThenFilters () {
663- this .spring .register (MetaAnnotationPlaceholderConfig . class ).autowire ();
672+ public void methodWhenPreFilterMetaAnnotationThenFilters (Class <?> config ) {
673+ this .spring .register (config ).autowire ();
664674 MetaAnnotationService service = this .spring .getContext ().getBean (MetaAnnotationService .class );
665675 assertThat (service .parametersContainDave (new ArrayList <>(List .of ("dave" , "carla" , "vanessa" , "paul" ))))
666676 .containsExactly ("dave" );
667677 }
668678
669- @ Test
679+ @ ParameterizedTest
680+ @ ValueSource (classes = { LegacyMetaAnnotationPlaceholderConfig .class , MetaAnnotationPlaceholderConfig .class })
670681 @ WithMockUser
671- public void methodWhenPostFilterMetaAnnotationThenFilters () {
672- this .spring .register (MetaAnnotationPlaceholderConfig . class ).autowire ();
682+ public void methodWhenPostFilterMetaAnnotationThenFilters (Class <?> config ) {
683+ this .spring .register (config ).autowire ();
673684 MetaAnnotationService service = this .spring .getContext ().getBean (MetaAnnotationService .class );
674685 assertThat (service .resultsContainDave (new ArrayList <>(List .of ("dave" , "carla" , "vanessa" , "paul" ))))
675686 .containsExactly ("dave" );
@@ -827,7 +838,7 @@ void preAuthorizeWhenDeniedAndHandlerWithCustomAnnotationInClassThenHandlerCanUs
827838 @ WithMockUser
828839 void postAuthorizeWhenNullDeniedMetaAnnotationThanWorks () {
829840 this .spring
830- .register (MethodSecurityServiceEnabledConfig .class , MetaAnnotationPlaceholderConfig .class ,
841+ .register (MethodSecurityServiceEnabledConfig .class , LegacyMetaAnnotationPlaceholderConfig .class ,
831842 MethodSecurityService .NullPostProcessor .class )
832843 .autowire ();
833844 MethodSecurityService service = this .spring .getContext ().getBean (MethodSecurityService .class );
@@ -1268,7 +1279,7 @@ Authz authz() {
12681279
12691280 @ Configuration
12701281 @ EnableMethodSecurity
1271- static class MetaAnnotationPlaceholderConfig {
1282+ static class LegacyMetaAnnotationPlaceholderConfig {
12721283
12731284 @ Bean
12741285 PrePostTemplateDefaults methodSecurityDefaults () {
@@ -1282,6 +1293,22 @@ MetaAnnotationService metaAnnotationService() {
12821293
12831294 }
12841295
1296+ @ Configuration
1297+ @ EnableMethodSecurity
1298+ static class MetaAnnotationPlaceholderConfig {
1299+
1300+ @ Bean
1301+ AnnotationTemplateExpressionDefaults methodSecurityDefaults () {
1302+ return new AnnotationTemplateExpressionDefaults ();
1303+ }
1304+
1305+ @ Bean
1306+ MetaAnnotationService metaAnnotationService () {
1307+ return new MetaAnnotationService ();
1308+ }
1309+
1310+ }
1311+
12851312 static class MetaAnnotationService {
12861313
12871314 @ RequireRole (role = "#role" )
0 commit comments