Skip to content

Commit

Permalink
Merge pull request #145 from dnd-side-project/fix/#133
Browse files Browse the repository at this point in the history
Fix corsConfigurationSource
  • Loading branch information
miraexhoi authored Sep 21, 2024
2 parents 8decc4a + cb912ed commit a7d6239
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/main/java/com/dnd/spaced/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.dnd.spaced.global.security.handler.OAuth2AuthenticationFailureHandler;
import com.dnd.spaced.global.security.handler.OAuth2SuccessHandler;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down Expand Up @@ -48,7 +47,6 @@ public class SecurityConfig {
private final TokenEncoder tokenEncoder;
private final TokenDecoder tokenDecoder;
private final ObjectMapper objectMapper;
private final CorsProperties corsProperties;
private final TokenProperties tokenProperties;
private final NicknameProperties nicknameProperties;
private final ProfileImageProperties profileImageProperties;
Expand Down Expand Up @@ -102,28 +100,16 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws

@Bean
public CorsConfigurationSource corsConfigurationSource() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();

config.addAllowedOrigin(corsProperties.allowedOrigin());
config.setAllowedMethods(List.of("HEAD", "GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
config.setExposedHeaders(
List.of(
"Authorization",
"Origin",
"Accept",
"Access-Control-Allow-Headers",
"Access-Control-Request-Method",
"Access-Control-Request-Headers",
"Content-Type"
)
);
config.setAllowCredentials(true);
config.setMaxAge(corsProperties.maxAge());
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOriginPattern("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setAllowCredentials(true);

source.registerCorsConfiguration("/**", config);
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);

return source;
return urlBasedCorsConfigurationSource;
}

@Bean
Expand Down

0 comments on commit a7d6239

Please sign in to comment.