Skip to content

Commit

Permalink
[CHORE] CORS 처리 Nginx 위임에 따른 SecurityConfig 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
yummygyudon committed Dec 2, 2024
1 parent 6988e58 commit 469de96
Showing 1 changed file with 1 addition and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.sopt.makers.operation.config;

import lombok.RequiredArgsConstructor;
import lombok.val;
import org.sopt.makers.operation.filter.JwtAuthenticationFilter;
import org.sopt.makers.operation.filter.JwtExceptionFilter;
import org.springframework.context.annotation.Bean;
Expand All @@ -15,24 +14,18 @@
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.List;

@RequiredArgsConstructor
@EnableWebSecurity
@Configuration
public class SecurityConfig {
private static final String API_V1_PREFIX = "/api/v1";
private static final String AUTH_PATH_PATTERN = API_V1_PREFIX + "/auth/*";
private static final String AUTH_PATH_PATTERN = API_V1_PREFIX + "/auth/**";
private static final String TEST_PATH_PATTERN = API_V1_PREFIX + "/test/**";
private static final String ERROR_PATH_PATTERN = "/error";

private final JwtAuthenticationFilter jwtAuthenticationFilter;
private final JwtExceptionFilter jwtExceptionFilter;
private final ValueConfig valueConfig;

@Bean
public static PasswordEncoder passwordEncoder() {
Expand Down Expand Up @@ -62,8 +55,6 @@ private void setHttp(HttpSecurity http) throws Exception {
.csrf().disable()
.formLogin().disable()
.cors().disable()
// .cors().configurationSource(corsConfigurationSource())
// .and()
.authorizeHttpRequests(authorizeHttpRequests ->
authorizeHttpRequests
.requestMatchers(new AntPathRequestMatcher(AUTH_PATH_PATTERN)).permitAll()
Expand All @@ -77,32 +68,4 @@ private void setHttp(HttpSecurity http) throws Exception {
.addFilterBefore(jwtExceptionFilter, JwtAuthenticationFilter.class);
}

// @Bean
// public CorsConfigurationSource corsConfigurationSource() {
// val configuration = new CorsConfiguration();
// configuration.setAllowedOrigins(List.of(
// valueConfig.getADMIN_PROD_URL(),
// valueConfig.getADMIN_DEV_URL(),
// valueConfig.getADMIN_LOCAL_URL()
// ));
// configuration.setAllowedMethods(List.of("HEAD", "GET", "POST", "PUT", "DELETE", "OPTIONS"));
// configuration.setAllowedHeaders(List.of(
// "Authorization",
// "Cache-Control",
// "Content-Type",
// "Accept"));
// configuration.setExposedHeaders(List.of("Authorization","Set-Cookie"));
//// configuration.addAllowedOrigin(valueConfig.getADMIN_PROD_URL());
//// configuration.addAllowedOrigin(valueConfig.getADMIN_DEV_URL());
//// configuration.addAllowedOrigin(valueConfig.getADMIN_LOCAL_URL());
//// configuration.addAllowedHeader("*");
//// configuration.addAllowedMethod("*");
// configuration.setAllowCredentials(true);
//
// val source = new UrlBasedCorsConfigurationSource();
//
// source.registerCorsConfiguration("/**", configuration);
//
// return source;
// }
}

0 comments on commit 469de96

Please sign in to comment.