Skip to content

Commit 20bd62e

Browse files
committed
backup
1 parent 52fcc0e commit 20bd62e

File tree

2 files changed

+23
-53
lines changed

2 files changed

+23
-53
lines changed

src/main/java/com/dmu/debug_visual/config/SecurityConfig.java

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.springframework.context.annotation.Bean;
77
import org.springframework.context.annotation.Configuration;
88
import org.springframework.http.HttpHeaders;
9-
import org.springframework.http.HttpMethod; // ✅ 추가
109
import org.springframework.http.MediaType;
1110
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1211
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -20,9 +19,6 @@
2019
import org.springframework.web.reactive.function.client.WebClient;
2120
import util.JwtTokenProvider;
2221

23-
// ⚠️ JwtAuthenticationFilter import는 프로젝트 경로에 맞게 유지하세요.
24-
// import com.dmu.debug_visual.config.JwtAuthenticationFilter; (예시)
25-
2622
import java.util.List;
2723

2824
@Configuration
@@ -39,40 +35,24 @@ public class SecurityConfig {
3935
@Bean
4036
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
4137
http
42-
// CORS 우선 적용
43-
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
44-
// REST API라면 CSRF 비활성
45-
.csrf(csrf -> csrf.disable())
46-
.authorizeHttpRequests(auth -> auth
47-
// ✅ 프리플라이트 전역 허용 (중요)
48-
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
49-
50-
// ✅ 공개 엔드포인트
51-
.requestMatchers(
52-
"/api/users/login",
53-
"/api/users/signup",
54-
"/swagger-ui/**",
55-
"/swagger-ui.html",
56-
"/v3/api-docs/**",
57-
"/actuator/health",
58-
"/healthz",
59-
"/public/**"
60-
).permitAll()
61-
62-
// 역할 기반
63-
.requestMatchers("/api/admin/**").hasRole("ADMIN")
64-
.requestMatchers("/api/posts/**").hasAnyRole("USER", "ADMIN")
65-
.requestMatchers("/api/notifications/**").hasAnyRole("USER", "ADMIN")
66-
67-
// 나머지는 인증 필요
68-
.anyRequest().authenticated()
69-
)
70-
// JWT 필터 (위치 유지)
71-
.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider, userRepository),
72-
UsernamePasswordAuthenticationFilter.class)
73-
// 폼/기본 인증 비활성
74-
.formLogin(form -> form.disable())
75-
.httpBasic(basic -> basic.disable());
38+
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
39+
.csrf(csrf -> csrf.disable())
40+
.authorizeHttpRequests(auth -> auth
41+
.requestMatchers(
42+
"/api/users/login",
43+
"/api/users/signup",
44+
"/swagger-ui/**",
45+
"/v3/api-docs/**"
46+
).permitAll()
47+
.requestMatchers("/api/admin/**").hasRole("ADMIN")
48+
.requestMatchers("/api/posts/**").hasAnyRole("USER", "ADMIN")
49+
.requestMatchers("/api/notifications/**").hasAnyRole("USER", "ADMIN")
50+
.anyRequest().authenticated()
51+
)
52+
.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider, userRepository),
53+
UsernamePasswordAuthenticationFilter.class)
54+
.formLogin(form -> form.disable())
55+
.httpBasic(basic -> basic.disable());
7656

7757
return http.build();
7858
}
@@ -82,7 +62,6 @@ public PasswordEncoder passwordEncoder() {
8262
return new BCryptPasswordEncoder();
8363
}
8464

85-
// 백엔드 → 파이썬 컴파일러 호출용 WebClient
8665
@Bean
8766
public WebClient webClient() {
8867
return WebClient.builder()
@@ -91,22 +70,15 @@ public WebClient webClient() {
9170
.build();
9271
}
9372

94-
// ✅ CORS: 프록시(Nginx)와 값 일치 — zivorp.com만 허용(+ www, http/https)
9573
@Bean
9674
public CorsConfigurationSource corsConfigurationSource() {
9775
CorsConfiguration config = new CorsConfiguration();
98-
// AllowedOriginPatterns("*") + Credentials(true)는 브라우저에서 막히기 쉬움.
99-
// 명시적으로 허용 도메인만 지정하세요.
100-
config.setAllowedOrigins(List.of(
101-
"https://zivorp.com",
102-
"http://zivorp.com",
103-
"https://www.zivorp.com",
104-
"http://www.zivorp.com"
105-
));
106-
config.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
107-
config.setAllowedHeaders(List.of("Authorization", "Content-Type", "X-Requested-With"));
76+
config.setAllowedOriginPatterns(List.of("*"));
77+
// 또는 특정 도메인만 허용할 경우:
78+
// config.setAllowedOrigins(List.of("https://zivorp.com", "http://zivorp.com"));
79+
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
80+
config.setAllowedHeaders(List.of("*"));
10881
config.setAllowCredentials(true);
109-
config.setMaxAge(3600L);
11082

11183
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
11284
source.registerCorsConfiguration("/**", config);

src/main/resources/application.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,3 @@ jwt.secret=bnTweUtRuSmcelFon7OFd2Px/ZaVWgEhMpAzyl/+LnEQLG8bKe+F5nA4UJTWwT0iM627y
3535
jwt.expiration=300000
3636

3737
compiler.python.url=http://flask-server:5050/run
38-
39-
server.forward-headers-strategy=framework

0 commit comments

Comments
 (0)