Skip to content

Commit 08173cd

Browse files
committed
refactor: 리뷰, 구인 api 경로 추가
1 parent 0c3c6d4 commit 08173cd

1 file changed

Lines changed: 82 additions & 80 deletions

File tree

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.back.web7_9_codecrete_be.global.security;
22

3-
import java.util.List;
4-
3+
import com.back.web7_9_codecrete_be.domain.auth.service.TokenService;
4+
import lombok.RequiredArgsConstructor;
55
import org.springframework.context.annotation.Bean;
66
import org.springframework.context.annotation.Configuration;
77
import org.springframework.security.authentication.AuthenticationManager;
@@ -14,91 +14,93 @@
1414
import org.springframework.web.cors.CorsConfiguration;
1515
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
1616

17-
import com.back.web7_9_codecrete_be.domain.auth.service.TokenService;
18-
19-
import lombok.RequiredArgsConstructor;
17+
import java.util.List;
2018

2119
@Configuration
2220
@RequiredArgsConstructor
2321
public class SecurityConfig {
2422

25-
private final JwtTokenProvider jwtTokenProvider;
26-
private final JwtProperties jwtProperties;
27-
private final CustomUserDetailService customUserDetailService;
28-
private final TokenService tokenService;
29-
30-
@Bean
31-
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
32-
33-
http
34-
.csrf(csrf -> csrf.disable())
35-
.cors(Customizer.withDefaults())
36-
37-
// 기본 로그인 폼 비활성화
38-
.formLogin(form -> form.disable())
39-
40-
// HTTP Basic 인증 비활성화
41-
.httpBasic(basic -> basic.disable())
42-
43-
// H2 Console 설정
44-
.headers(headers -> headers.frameOptions(frame -> frame.disable()))
45-
46-
// 세션 관리 설정 - Stateless
47-
.sessionManagement((session) -> session
48-
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
49-
50-
// Authorization 설정
51-
.authorizeHttpRequests(auth -> auth
52-
.requestMatchers(
53-
"/ws-chat/**",
54-
"/actuator/**",
55-
"/api/v1/auth/**", // 로그인/회원가입은 허용
56-
"/v3/api-docs/**", // Swagger
57-
"/swagger-ui/**", // Swagger UI
58-
"/h2-console/**", // H2 Console
59-
"/api/v1/location/**", //location 정보 조회 도메인(임시)
60-
"/api/v1/concerts/**", // concert 정보 조회 도메인
61-
"/api/v1/artists/**", // artist 정보 저장 도메인(임시)
62-
"/api/v1/users/**",
63-
"/api/v1/chats/**"
64-
).permitAll()
65-
66-
// ADMIN 전용
67-
.requestMatchers("/api/v1/admin/**").hasRole("ADMIN")
68-
69-
.anyRequest().authenticated()
70-
)
71-
72-
.addFilterBefore(
73-
new JwtAuthenticationFilter(jwtTokenProvider, jwtProperties, tokenService),
74-
UsernamePasswordAuthenticationFilter.class
75-
);
76-
77-
return http.build();
78-
}
79-
80-
@Bean
81-
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception {
82-
return configuration.getAuthenticationManager();
83-
}
84-
85-
// CORS 설정(로컬 프론트 통신 허용)
86-
@Bean
87-
public UrlBasedCorsConfigurationSource corsConfigurationSource() {
88-
CorsConfiguration configuration = new CorsConfiguration();
89-
90-
configuration.setAllowedOrigins(List.of("http://localhost:3000", "https://www.naeconcertbutakhae.shop"));
91-
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
92-
93-
configuration.setAllowedHeaders(List.of("*"));
23+
private final JwtTokenProvider jwtTokenProvider;
24+
private final JwtProperties jwtProperties;
25+
private final CustomUserDetailService customUserDetailService;
26+
private final TokenService tokenService;
27+
28+
@Bean
29+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
30+
31+
http
32+
.csrf(csrf -> csrf.disable())
33+
.cors(Customizer.withDefaults())
34+
35+
// 기본 로그인 폼 비활성화
36+
.formLogin(form -> form.disable())
37+
38+
// HTTP Basic 인증 비활성화
39+
.httpBasic(basic -> basic.disable())
40+
41+
// H2 Console 설정
42+
.headers(headers -> headers.frameOptions(frame -> frame.disable()))
43+
44+
// 세션 관리 설정 - Stateless
45+
.sessionManagement((session) -> session
46+
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
47+
48+
// Authorization 설정
49+
50+
.authorizeHttpRequests(auth -> auth
51+
.requestMatchers(org.springframework.http.HttpMethod.OPTIONS, "/**").permitAll()
52+
.requestMatchers(
53+
"/ws-chat/**",
54+
"/actuator/**",
55+
"/api/v1/auth/**", // 로그인/회원가입은 허용
56+
"/v3/api-docs/**", // Swagger
57+
"/swagger-ui/**", // Swagger UI
58+
"/h2-console/**", // H2 Console
59+
"/api/v1/location/**", //location 정보 조회 도메인(임시)
60+
"/api/v1/concerts/**", // concert 정보 조회 도메인
61+
"/api/v1/artists/**", // artist 정보 저장 도메인(임시)
62+
"/api/v1/users/**",
63+
"/api/v1/chats/**",
64+
"/api/v1/reviews/**",
65+
"api/v1/join/**"
66+
).permitAll()
67+
68+
// ADMIN 전용
69+
.requestMatchers("/api/v1/admin/**").hasRole("ADMIN")
70+
71+
.anyRequest().authenticated()
72+
)
73+
74+
.addFilterBefore(
75+
new JwtAuthenticationFilter(jwtTokenProvider, jwtProperties, tokenService),
76+
UsernamePasswordAuthenticationFilter.class
77+
);
78+
79+
return http.build();
80+
}
81+
82+
@Bean
83+
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception {
84+
return configuration.getAuthenticationManager();
85+
}
86+
87+
// CORS 설정(로컬 프론트 통신 허용)
88+
@Bean
89+
public UrlBasedCorsConfigurationSource corsConfigurationSource() {
90+
CorsConfiguration configuration = new CorsConfiguration();
91+
92+
configuration.setAllowedOrigins(List.of("http://localhost:3000", "http://localhost:8080", "https://www.naeconcertbutakhae.shop"));
93+
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
94+
95+
configuration.setAllowedHeaders(List.of("*"));
9496
configuration.setExposedHeaders(List.of("Set-Cookie"));
9597

96-
//쿠키 자동으로 넘어가게 설정
97-
configuration.setAllowCredentials(true);
98+
//쿠키 자동으로 넘어가게 설정
99+
configuration.setAllowCredentials(true);
98100

99-
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
100-
source.registerCorsConfiguration("/**", configuration);
101+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
102+
source.registerCorsConfiguration("/**", configuration);
101103

102-
return source;
103-
}
104+
return source;
105+
}
104106
}

0 commit comments

Comments
 (0)