Skip to content

Commit

Permalink
[Feat]: cors 허용 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bayy1216 committed May 30, 2024
1 parent a73cd9f commit d6e6b2b
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;
import java.util.List;

@EnableWebSecurity
Expand Down Expand Up @@ -114,4 +118,20 @@ public AuthorizationJwtHeaderFilter jwtAuthenticationFilter(AuthenticationManage
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
public CorsConfigurationSource corsConfigSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOriginPatterns(List.of("*")); // 모든 요청 허용
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PATCH",
"OPTIONS")); // 모든 HTTP 메서드 허용
configuration.setAllowedHeaders(List.of("*")); // 모든 헤더 허용
configuration.setExposedHeaders(Arrays.asList("Authorization", "Set-cookie"));
configuration.setAllowCredentials(true); // 쿠키와 같은 자격 증명을 허용

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

return source;
}
}

0 comments on commit d6e6b2b

Please sign in to comment.