cors 설정 추가
This commit is contained in:
@@ -29,34 +29,33 @@ public class SecurityConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
|
||||||
http
|
http.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||||
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
.csrf(csrf -> csrf.disable()) // CSRF 보안 기능 비활성화
|
||||||
.csrf(csrf -> csrf.disable()) // CSRF 보안 기능 비활성화
|
.sessionManagement(
|
||||||
.sessionManagement(
|
sm ->
|
||||||
sm ->
|
sm.sessionCreationPolicy(
|
||||||
sm.sessionCreationPolicy(
|
SessionCreationPolicy.STATELESS)) // 서버 세션 만들지 않음, 요청은 JWT 인증
|
||||||
SessionCreationPolicy.STATELESS)) // 서버 세션 만들지 않음, 요청은 JWT 인증
|
.formLogin(form -> form.disable()) // react에서 로그인 요청 관리
|
||||||
.formLogin(form -> form.disable()) // react에서 로그인 요청 관리
|
.httpBasic(basic -> basic.disable()) // 기본 basic 인증 비활성화 JWT 인증사용
|
||||||
.httpBasic(basic -> basic.disable()) // 기본 basic 인증 비활성화 JWT 인증사용
|
.logout(logout -> logout.disable()) // 기본 로그아웃 비활성화 JWT는 서버 상태가 없으므로 로그아웃 처리 필요 없음
|
||||||
.logout(logout -> logout.disable()) // 기본 로그아웃 비활성화 JWT는 서버 상태가 없으므로 로그아웃 처리 필요 없음
|
.authenticationProvider(
|
||||||
.authenticationProvider(
|
customAuthenticationProvider) // 로그인 패스워드 비교방식 스프링 기본 Provider 사용안함 커스텀 사용
|
||||||
customAuthenticationProvider) // 로그인 패스워드 비교방식 스프링 기본 Provider 사용안함 커스텀 사용
|
.authorizeHttpRequests(
|
||||||
.authorizeHttpRequests(
|
auth ->
|
||||||
auth ->
|
auth.requestMatchers(HttpMethod.OPTIONS, "/**")
|
||||||
auth
|
.permitAll() // preflight 허용
|
||||||
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() // preflight 허용
|
.requestMatchers(
|
||||||
.requestMatchers(
|
"/api/auth/signin",
|
||||||
"/api/auth/signin",
|
"/api/auth/refresh",
|
||||||
"/api/auth/refresh",
|
"/swagger-ui/**",
|
||||||
"/swagger-ui/**",
|
"/v3/api-docs/**")
|
||||||
"/v3/api-docs/**")
|
.permitAll()
|
||||||
.permitAll()
|
.anyRequest()
|
||||||
.anyRequest()
|
.authenticated())
|
||||||
.authenticated())
|
.addFilterBefore(
|
||||||
.addFilterBefore(
|
jwtAuthenticationFilter,
|
||||||
jwtAuthenticationFilter,
|
UsernamePasswordAuthenticationFilter
|
||||||
UsernamePasswordAuthenticationFilter
|
.class) // 요청 들어오면 먼저 JWT 토큰 검사 후 security context 에 사용자 정보 저장.
|
||||||
.class) // 요청 들어오면 먼저 JWT 토큰 검사 후 security context 에 사용자 정보 저장.
|
|
||||||
;
|
;
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
@@ -64,7 +63,7 @@ public class SecurityConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration)
|
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
return configuration.getAuthenticationManager();
|
return configuration.getAuthenticationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user