Skip to content

Commit

Permalink
refactor:[#84]- refact Security
Browse files Browse the repository at this point in the history
cors 변경
  • Loading branch information
yooonwodyd committed Nov 15, 2024
1 parent cadade1 commit af756ea
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand Down Expand Up @@ -71,6 +72,13 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.sessionManagement((session) -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
http.cors((cors) -> cors.configurationSource(corsConfigurationSource()));

http.authorizeHttpRequests((authorize) ->
authorize
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() // OPTIONS 요청 허용
.anyRequest().authenticated()
);

http.authorizeHttpRequests((authorize) ->
authorize
.requestMatchers(
Expand Down Expand Up @@ -98,7 +106,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("http://1.618.s3-website.ap-northeast-2.amazonaws.com","http//localhost:3000"));
configuration.setAllowedOrigins(Arrays.asList("http://1.618.s3-website.ap-northeast-2.amazonaws.com","http://localhost:3000"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type", "X-Requested-With", "accept", "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers"));
configuration.setAllowCredentials(true);
Expand Down

0 comments on commit af756ea

Please sign in to comment.