


SecurityConfiguration.java
Код: Выделить всё
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(AbstractHttpConfigurer::disable)
.cors(cors -> cors
.configurationSource(request -> {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(Collections.singletonList("http://localhost:5173"));
config.setAllowedMethods(Collections.singletonList("*"));
config.setAllowCredentials(true);
config.setAllowedHeaders(Collections.singletonList("*"));
config.setMaxAge(3600L);
return config;
}));
http
.authorizeHttpRequests(authorize -> {
authorize.requestMatchers(ALLOWED_URLS).permitAll();
authorize.requestMatchers("/api/v1/auth/login").permitAll();
authorize.requestMatchers("/api/v1/auth/refresh").permitAll();
authorize.requestMatchers(HttpMethod.GET, "/api/v1/users/**")
.hasAuthority(Permissions.USER_READ.getName());
authorize.requestMatchers(HttpMethod.POST, "/api/v1/users/**")
.hasAuthority(Permissions.USER_CREATE.getName());
authorize.requestMatchers(HttpMethod.PUT, "/api/v1/users/**")
.hasAuthority(Permissions.USER_UPDATE.getName());
authorize.requestMatchers(HttpMethod.DELETE, "/api/v1/users/**")
.hasAuthority(Permissions.USER_DELETE.getName());
authorize.anyRequest().authenticated();
});
http
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
http
.exceptionHandling(exception -> exception.authenticationEntryPoint(jwtAuthEntryPoint));
http
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
return http.build();
}


Но когда я тестирую интерфейс после успешного входа в систему, последующие запросы НЕ АВТОРИЗОВАНЫ. В чем может быть проблема?
Подробнее здесь: https://stackoverflow.com/questions/791 ... authorized