Skip to content

Commit

Permalink
feat: CORS 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxklee committed Oct 6, 2024
1 parent e1101e3 commit 4aec592
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/main/java/com/leets/X/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;

import static org.springframework.security.config.Customizer.withDefaults;

Expand Down Expand Up @@ -72,18 +77,18 @@ public AuthenticationManager authenticationManager(AuthenticationConfiguration a
/*
CORS 관련 설정
*/
// @Bean
// public CorsConfigurationSource corsConfigurationSource() {
// CorsConfiguration configuration = new CorsConfiguration();
//
// configuration.setAllowedOrigins(Arrays.asList());
// configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PATCH", "DELETE"));
// configuration.setAllowedHeaders(Arrays.asList("*"));
// configuration.setExposedHeaders(Arrays.asList("Authorization, Authorization_refresh"));
// configuration.setAllowCredentials(true);
//
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// source.registerCorsConfiguration("/**", configuration);
// return source;
// }
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

configuration.setAllowedOrigins(Arrays.asList("*"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PATCH", "DELETE"));
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.setExposedHeaders(Arrays.asList("Authorization, Authorization_refresh"));
configuration.setAllowCredentials(true);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}

0 comments on commit 4aec592

Please sign in to comment.