Skip to content

Commit

Permalink
fix: cors 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HI-JIN2 committed Oct 10, 2023
1 parent ad86ef9 commit 120da23
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/umc/yourweather/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.List;

@Configuration
@EnableWebSecurity
Expand Down Expand Up @@ -72,9 +77,23 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.addFilterAfter(customLoginFilter(), CustomOAuthLoginFilter.class);
http.addFilterBefore(jwtAuthenticationFilter(), CustomLoginFilter.class);

http.cors(httpSecurityCorsConfigurer -> corsConfigurationSource());

return http.build();
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("*"));
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
configuration.setAllowedHeaders(List.of("*"));
configuration.setExposedHeaders(List.of("*"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
Expand Down

0 comments on commit 120da23

Please sign in to comment.