45
45
import org .springframework .mock .web .MockHttpServletResponse ;
46
46
import org .springframework .mock .web .MockServletContext ;
47
47
import org .springframework .security .config .BeanIds ;
48
+ import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
49
+ import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
48
50
import org .springframework .test .web .servlet .MockMvc ;
49
51
import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
50
52
import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
@@ -157,6 +159,7 @@ void securityConfigurationShouldAllowAccess() throws Exception {
157
159
mockMvc .perform (MockMvcRequestBuilders .get (DEFAULT_CONTEXT_PATH + "/restart" ).header (DEFAULT_SECRET_HEADER_NAME ,
158
160
"supersecret" )).andExpect (status ().isOk ());
159
161
assertRestartInvoked (true );
162
+ assertThat (this .context .containsBean ("devtoolsSecurityFilterChain" )).isTrue ();
160
163
}
161
164
162
165
@ Test
@@ -182,6 +185,25 @@ void securityConfigurationDoesNotAffectOtherPaths() throws Exception {
182
185
mockMvc .perform (MockMvcRequestBuilders .get ("/my-path" )).andExpect (status ().isUnauthorized ());
183
186
}
184
187
188
+ @ Test
189
+ void securityConfigurationWhenWebSecurityConfigurerAdapterIsFound2 () throws Exception {
190
+ this .context = getContext (() -> {
191
+ AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext ();
192
+ context .setServletContext (new MockServletContext ());
193
+ context .register (Config .class , PropertyPlaceholderAutoConfiguration .class ,
194
+ TestWebSecurityConfigurerAdapter .class );
195
+ TestPropertyValues .of ("spring.devtools.remote.secret:supersecret" ).applyTo (context );
196
+ context .refresh ();
197
+ return context ;
198
+ });
199
+ DispatcherFilter filter = this .context .getBean (DispatcherFilter .class );
200
+ MockMvc mockMvc = MockMvcBuilders .webAppContextSetup (this .context ).apply (springSecurity ()).addFilter (filter )
201
+ .build ();
202
+ mockMvc .perform (MockMvcRequestBuilders .get (DEFAULT_CONTEXT_PATH + "/restart" ).header (DEFAULT_SECRET_HEADER_NAME ,
203
+ "supersecret" )).andExpect (status ().isOk ());
204
+ assertRestartInvoked (true );
205
+ }
206
+
185
207
@ Test
186
208
void disableRestart () throws Exception {
187
209
this .context = getContext (() -> loadContext ("spring.devtools.remote.secret:supersecret" ,
@@ -250,6 +272,16 @@ HttpRestartServer remoteRestartHttpRestartServer() {
250
272
251
273
}
252
274
275
+ @ Configuration (proxyBeanMethods = false )
276
+ static class TestWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
277
+
278
+ @ Override
279
+ protected void configure (HttpSecurity http ) throws Exception {
280
+ http .antMatcher ("/foo/**" ).authorizeRequests ().anyRequest ().authenticated ().and ().httpBasic ();
281
+ }
282
+
283
+ }
284
+
253
285
/**
254
286
* Mock {@link HttpRestartServer} implementation.
255
287
*/
0 commit comments