1010import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
1111import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
1212import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
13+ import org .springframework .security .config .annotation .web .configurers .HeadersConfigurer ;
1314import org .springframework .security .oauth2 .server .resource .web .DefaultBearerTokenResolver ;
1415import org .springframework .security .web .SecurityFilterChain ;
1516import org .springframework .security .web .authentication .AuthenticationFailureHandler ;
1617import org .springframework .security .web .authentication .ExceptionMappingAuthenticationFailureHandler ;
17- import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
18- import org .springframework .security .web .util .matcher .OrRequestMatcher ;
19- import org .springframework .security .web .util .matcher .RequestMatcher ;
2018
21- import jakarta .servlet .http .HttpServletRequest ;
2219import java .util .Map ;
23- import java .util .regex .Pattern ;
2420
2521@ Configuration
2622@ EnableWebSecurity
@@ -31,19 +27,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
3127 final var bearerTokenResolver = new DefaultBearerTokenResolver ();
3228 bearerTokenResolver .setAllowUriQueryParameter (true );
3329
34- // @formatter:off
35- http .csrf (csrfConfig -> csrfConfig .requireCsrfProtectionMatcher (new RequestMatcher () {
36- private final Pattern allowedMethods = Pattern .compile ("^(GET|HEAD|TRACE|OPTIONS)$" );
37- private final RequestMatcher matcher = new OrRequestMatcher (
38- new AntPathRequestMatcher ("/oauth/authorize" ),
39- new AntPathRequestMatcher ("/login" ));
40-
41- @ Override
42- public boolean matches (HttpServletRequest request ) {
43- return matcher .matches (request ) && !allowedMethods .matcher (request .getMethod ()).matches ();
44- }
45- }));
46- http .headers (headersConfig -> headersConfig .cacheControl ().disable ());
30+ http .headers (headersConfig -> headersConfig .cacheControl (HeadersConfigurer .CacheControlConfig ::disable ));
4731 http .formLogin (AbstractHttpConfigurer ::disable );
4832 http .oauth2ResourceServer (oauth2Config -> {
4933 oauth2Config .bearerTokenResolver (bearerTokenResolver );
0 commit comments