Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corsConfig를 구성하였습니다. #26

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.AuthenticationSuccessHandler
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import team.themoment.gsmNetworking.domain.auth.domain.Authority
import team.themoment.gsmNetworking.global.filter.ExceptionHandlerFilter
import team.themoment.gsmNetworking.global.filter.TokenRequestFilter
Expand All @@ -34,6 +37,8 @@ class SecurityConfig(
.formLogin().disable()
.httpBasic().disable()
.csrf().disable()
.cors().configurationSource(corsConfigurationSource())
.and()
.apply(FilterConfig(tokenRequestFilter, exceptionHandlerFilter))
logout(http)
oauth2Login(http)
Expand Down Expand Up @@ -75,4 +80,17 @@ class SecurityConfig(
.deleteCookies(JwtProperties.ACCESS, JwtProperties.REFRESH)
}

@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val configuration = CorsConfiguration()
val source = UrlBasedCorsConfigurationSource()
configuration.allowedOrigins = listOf("*")
configuration.setAllowedMethods(
mutableListOf("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS")
)
configuration.allowedHeaders = mutableListOf("*")
configuration.allowCredentials = true
source.registerCorsConfiguration("/**", configuration)
return source
}
Comment on lines +83 to +95
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 global.config.WebMvcCorsConfig.ktcors 를 막고자 하였는데, 안됐던거 같습니다.
해당 새로 작업하신거 사용하실거면 기존거는 삭제해주시면 감사하겠습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#28 에서 삭제하였습니다!

}