1919import org .springframework .context .annotation .Bean ;
2020import org .springframework .context .annotation .Configuration ;
2121import org .springframework .context .annotation .Profile ;
22- import org .springframework .http .HttpMethod ;
2322import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
2423import org .springframework .security .web .SecurityFilterChain ;
24+ import org .springframework .security .web .authentication .www .BasicAuthenticationFilter ;
2525import org .springframework .security .web .csrf .CookieCsrfTokenRepository ;
26+ import org .springframework .security .web .csrf .CsrfTokenRequestAttributeHandler ;
2627import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
2728
2829import de .codecentric .boot .admin .server .config .AdminServerProperties ;
2930
31+ import static org .springframework .http .HttpMethod .DELETE ;
32+ import static org .springframework .http .HttpMethod .POST ;
33+
3034@ Profile ("insecure" )
3135@ Configuration (proxyBeanMethods = false )
3236public class SecurityPermitAllConfig {
@@ -39,13 +43,19 @@ public SecurityPermitAllConfig(AdminServerProperties adminServer) {
3943
4044 @ Bean
4145 protected SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
42- http .authorizeHttpRequests ((authorizeRequest ) -> authorizeRequest .anyRequest ().permitAll ()).csrf ((csrf ) -> csrf
43- .csrfTokenRepository (CookieCsrfTokenRepository .withHttpOnlyFalse ()).ignoringRequestMatchers (
44- new AntPathRequestMatcher (this .adminServer .path ("/instances" ), HttpMethod .POST .toString ()),
45- new AntPathRequestMatcher (this .adminServer .path ("/instances/*" ), HttpMethod .DELETE .toString ()),
46- new AntPathRequestMatcher (this .adminServer .path ("/actuator/**" ))));
46+
47+ http .authorizeHttpRequests ((authorizeRequest ) -> authorizeRequest .anyRequest ().permitAll ());
48+
49+ http .addFilterAfter (new CustomCsrfFilter (), BasicAuthenticationFilter .class )
50+ .csrf ((csrf ) -> csrf .csrfTokenRepository (CookieCsrfTokenRepository .withHttpOnlyFalse ())
51+ .csrfTokenRequestHandler (new CsrfTokenRequestAttributeHandler ()).ignoringRequestMatchers (
52+ new AntPathRequestMatcher (this .adminServer .path ("/instances" ), POST .toString ()),
53+ new AntPathRequestMatcher (this .adminServer .path ("/instances/*" ), DELETE .toString ()),
54+ new AntPathRequestMatcher (this .adminServer .path ("/actuator/**" ))
55+ ));
4756
4857 return http .build ();
58+
4959 }
5060
5161}
0 commit comments