Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring security - how to remove cache control in certain url pattern

I am trying to filter some url pattern to caching. What I have attempted is put some codes into WebSecurityConfigurerAdapter implementation.

 @Override
protected void configure(HttpSecurity http) throws Exception {
    initSecurityConfigService();

    // For cache
    http.headers().defaultsDisabled()
            .cacheControl()
            .and().frameOptions();

    securityConfigService.configure(http,this);
}

However this code will effect all of the web application. How can I apply this to certain URL or Content-Type like images.

I have already tried with RegexRequestMatcher, but it does not work for me.

// For cache
        http.requestMatcher(new RegexRequestMatcher("/page/", "GET"))
                .headers().defaultsDisabled()
                .cacheControl()
                .and().frameOptions();

I read this article : SpringSecurityResponseHeaders, but there is no sample for this case.

Thanks.

P.S. In short, I want to remove SpringSecurity defaults for certain url and resources.

like image 720
Juneyoung Oh Avatar asked Apr 24 '26 13:04

Juneyoung Oh


1 Answers

What about having multiple WebSecurityConfigurerAdapters? One adapter could have cache controls for certain URLs and another one will not have cache control enabled for those URLs.

like image 100
anand1st Avatar answered Apr 30 '26 02:04

anand1st