File tree Expand file tree Collapse file tree 5 files changed +18
-6
lines changed
main/java/org/springframework/security/config/annotation/web
test/java/org/springframework/security/config/annotation/web Expand file tree Collapse file tree 5 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 34
34
import org .apache .commons .logging .LogFactory ;
35
35
36
36
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
37
+ import org .springframework .beans .factory .ObjectProvider ;
37
38
import org .springframework .context .ApplicationContext ;
39
+ import org .springframework .core .ResolvableType ;
38
40
import org .springframework .http .HttpMethod ;
39
41
import org .springframework .lang .Nullable ;
40
42
import org .springframework .security .config .annotation .ObjectPostProcessor ;
@@ -113,7 +115,9 @@ public C anyRequest() {
113
115
*/
114
116
protected final List <MvcRequestMatcher > createMvcMatchers (HttpMethod method , String ... mvcPatterns ) {
115
117
Assert .state (!this .anyRequestConfigured , "Can't configure mvcMatchers after anyRequest" );
116
- ObjectPostProcessor <Object > opp = this .context .getBean (ObjectPostProcessor .class );
118
+ ResolvableType type = ResolvableType .forClassWithGenerics (ObjectPostProcessor .class , Object .class );
119
+ ObjectProvider <ObjectPostProcessor <Object >> postProcessors = this .context .getBeanProvider (type );
120
+ ObjectPostProcessor <Object > opp = postProcessors .getObject ();
117
121
if (!this .context .containsBean (HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME )) {
118
122
throw new NoSuchBeanDefinitionException ("A Bean named " + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME
119
123
+ " of type " + HandlerMappingIntrospector .class .getName ()
Original file line number Diff line number Diff line change @@ -3686,7 +3686,9 @@ private List<RequestMatcher> createAntMatchers(String... patterns) {
3686
3686
}
3687
3687
3688
3688
private List <RequestMatcher > createMvcMatchers (String ... mvcPatterns ) {
3689
- ObjectPostProcessor <Object > opp = getContext ().getBean (ObjectPostProcessor .class );
3689
+ ResolvableType type = ResolvableType .forClassWithGenerics (ObjectPostProcessor .class , Object .class );
3690
+ ObjectProvider <ObjectPostProcessor <Object >> postProcessors = getContext ().getBeanProvider (type );
3691
+ ObjectPostProcessor <Object > opp = postProcessors .getObject ();
3690
3692
if (!getContext ().containsBean (HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME )) {
3691
3693
throw new NoSuchBeanDefinitionException ("A Bean named " + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME
3692
3694
+ " of type " + HandlerMappingIntrospector .class .getName ()
Original file line number Diff line number Diff line change 25
25
import org .junit .jupiter .api .Test ;
26
26
27
27
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
28
+ import org .springframework .beans .factory .ObjectProvider ;
28
29
import org .springframework .context .ApplicationContext ;
29
30
import org .springframework .context .annotation .Configuration ;
31
+ import org .springframework .core .ResolvableType ;
30
32
import org .springframework .http .HttpMethod ;
31
33
import org .springframework .mock .web .MockHttpServletRequest ;
32
34
import org .springframework .security .config .MockServletContext ;
@@ -79,7 +81,11 @@ public <O> O postProcess(O object) {
79
81
public void setUp () {
80
82
this .matcherRegistry = new TestRequestMatcherRegistry ();
81
83
this .context = mock (WebApplicationContext .class );
82
- given (this .context .getBean (ObjectPostProcessor .class )).willReturn (NO_OP_OBJECT_POST_PROCESSOR );
84
+ ObjectProvider <ObjectPostProcessor <Object >> postProcessors = mock (ObjectProvider .class );
85
+ ResolvableType type = ResolvableType .forClassWithGenerics (ObjectPostProcessor .class , Object .class );
86
+ ObjectProvider <ObjectPostProcessor <Object >> given = this .context .getBeanProvider (type );
87
+ given (given ).willReturn (postProcessors );
88
+ given (postProcessors .getObject ()).willReturn (NO_OP_OBJECT_POST_PROCESSOR );
83
89
given (this .context .getServletContext ()).willReturn (MockServletContext .mvc ());
84
90
this .matcherRegistry .setApplicationContext (this .context );
85
91
mockMvcIntrospector (true );
Original file line number Diff line number Diff line change @@ -110,8 +110,8 @@ public void configureWhenDefaultLogoutSuccessHandlerForHasNullMatcherInLambdaThe
110
110
@ Test
111
111
public void configureWhenRegisteringObjectPostProcessorThenInvokedOnLogoutFilter () {
112
112
this .spring .register (ObjectPostProcessorConfig .class ).autowire ();
113
- ObjectPostProcessor <LogoutFilter > objectPostProcessor = this .spring .getContext ()
114
- .getBean (ObjectPostProcessor .class );
113
+ ObjectPostProcessor <Object > objectPostProcessor = this .spring .getContext ()
114
+ .getBean (ObjectPostProcessorConfig .class ). objectPostProcessor ;
115
115
verify (objectPostProcessor ).postProcess (any (LogoutFilter .class ));
116
116
}
117
117
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ public void postWhenNoUserDetailsServiceThenException() {
102
102
@ Test
103
103
public void configureWhenRegisteringObjectPostProcessorThenInvokedOnRememberMeAuthenticationFilter () {
104
104
this .spring .register (ObjectPostProcessorConfig .class ).autowire ();
105
- verify (this .spring .getContext ().getBean (ObjectPostProcessor .class ))
105
+ verify (this .spring .getContext ().getBean (ObjectPostProcessorConfig .class ). objectPostProcessor )
106
106
.postProcess (any (RememberMeAuthenticationFilter .class ));
107
107
}
108
108
You can’t perform that action at this time.
0 commit comments