Как настроить Cache-Control на защищенные пути в приложении Spring Boot?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Как настроить Cache-Control на защищенные пути в приложении Spring Boot?

Сообщение Anonymous »

Я хочу установить заголовок Cache-Control: Private в приложении Spring Boot, но мне не удалось найти способ установить его для всех моих защищенных путей.
У меня есть следующий класс:

Код: Выделить всё

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;

import java.util.List;

@Configuration
@EnableWebSecurity
public class ResourceServerConfig {

private final List protectedPaths = List.of(
"/my-profile",
"/my-notes",
"/etc"
);

@Bean
@Order(2)
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.securityMatchers(customizer -> customizer.requestMatchers(protectedPaths.toArray(new String[0])))
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(requests -> requests.anyRequest().authenticated())
.oauth2ResourceServer(server -> server.jwt(
customizer -> customizer.jwtAuthenticationConverter(new UserAuthenticationTokenConverter())
));
return http.build();
}

}
Я пытался установить CacheControl cacheControl = CacheControl.noCache().cachePrivate(); в http.headers().cacheControl();, но headers() требует каких-то странных объектов. Также возможно, что там он не будет работать. Возможно, мне нужно установить заголовки внутри авторизацииHttpRequests(), но я и там ничего не нашел.
Как установить заголовки Cache-Control в protectedPaths?

Подробнее здесь: https://stackoverflow.com/questions/798 ... pplication
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»