2026-12-02 23:01:03 +03:00
|
|
|
package com.mmkilic.education.config;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.security.config.Customizer;
|
|
|
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
|
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
|
|
|
|
import org.springframework.security.web.SecurityFilterChain;
|
|
|
|
|
import org.springframework.web.cors.CorsConfiguration;
|
|
|
|
|
import org.springframework.web.cors.CorsConfigurationSource;
|
|
|
|
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
public class Config {
|
|
|
|
|
@Bean
|
|
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
|
|
http
|
|
|
|
|
.cors(Customizer.withDefaults())
|
|
|
|
|
.csrf(AbstractHttpConfigurer::disable)
|
|
|
|
|
.headers(headers -> headers.frameOptions(fo -> fo.sameOrigin()))
|
|
|
|
|
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll());
|
|
|
|
|
|
|
|
|
|
return http.build();
|
|
|
|
|
}
|
|
|
|
|
@Bean
|
|
|
|
|
CorsConfigurationSource corsConfigurationSource() {
|
|
|
|
|
CorsConfiguration configuration = new CorsConfiguration();
|
2026-12-03 00:16:47 +03:00
|
|
|
configuration.setAllowedOrigins(List.of("http://localhost:3000", "http://localhost", "https://www.mmkilic.com"));
|
2026-12-02 23:01:03 +03:00
|
|
|
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
|
|
|
|
|
configuration.setAllowedHeaders(List.of("*"));
|
|
|
|
|
//configuration.setAllowedHeaders(Arrays.asList(HttpHeaders.CONTENT_TYPE, HttpHeaders.AUTHORIZATION));
|
|
|
|
|
configuration.setAllowCredentials(true);
|
|
|
|
|
|
|
|
|
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
|
|
source.registerCorsConfiguration("/**", configuration);
|
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
}
|