4545import org .springframework .mock .web .MockHttpServletResponse ;
4646import org .springframework .mock .web .MockServletContext ;
4747import 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 ;
4850import org .springframework .test .web .servlet .MockMvc ;
4951import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
5052import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
@@ -157,6 +159,7 @@ void securityConfigurationShouldAllowAccess() throws Exception {
157159 mockMvc .perform (MockMvcRequestBuilders .get (DEFAULT_CONTEXT_PATH + "/restart" ).header (DEFAULT_SECRET_HEADER_NAME ,
158160 "supersecret" )).andExpect (status ().isOk ());
159161 assertRestartInvoked (true );
162+ assertThat (this .context .containsBean ("devtoolsSecurityFilterChain" )).isTrue ();
160163 }
161164
162165 @ Test
@@ -182,6 +185,25 @@ void securityConfigurationDoesNotAffectOtherPaths() throws Exception {
182185 mockMvc .perform (MockMvcRequestBuilders .get ("/my-path" )).andExpect (status ().isUnauthorized ());
183186 }
184187
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+
185207 @ Test
186208 void disableRestart () throws Exception {
187209 this .context = getContext (() -> loadContext ("spring.devtools.remote.secret:supersecret" ,
@@ -250,6 +272,16 @@ HttpRestartServer remoteRestartHttpRestartServer() {
250272
251273 }
252274
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+
253285 /**
254286 * Mock {@link HttpRestartServer} implementation.
255287 */
0 commit comments