Agent-Logs-Url: https://github.com/devitq/movienight-backend/sessions/62eaa8e4-560b-4737-be4b-478f1a4c484a Co-authored-by: devitq <118541411+devitq@users.noreply.github.com>
43 lines
1.5 KiB
Kotlin
43 lines
1.5 KiB
Kotlin
package com.project.movienight.adapters.security
|
|
|
|
import org.springframework.context.annotation.Bean
|
|
import org.springframework.context.annotation.Configuration
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
|
import org.springframework.security.web.SecurityFilterChain
|
|
|
|
@Configuration
|
|
@EnableWebSecurity
|
|
class SecurityConfiguration(
|
|
private val customOAuth2UserService: CustomOAuth2UserService,
|
|
) {
|
|
@Bean
|
|
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
|
|
http
|
|
.oauth2Login { oauth2 ->
|
|
oauth2
|
|
.userInfoEndpoint { userInfo ->
|
|
userInfo.userService(customOAuth2UserService)
|
|
}.defaultSuccessUrl("/api/users/me", true)
|
|
}.authorizeHttpRequests { auth ->
|
|
auth
|
|
.requestMatchers("/", "/login/**", "/oauth2/**", "/h2-console/**", "/actuator/health")
|
|
.permitAll()
|
|
.requestMatchers("/api/users/me")
|
|
.authenticated()
|
|
.requestMatchers("/api/**")
|
|
.authenticated()
|
|
.anyRequest()
|
|
.authenticated()
|
|
}.headers { headers ->
|
|
headers.frameOptions { frameOptions ->
|
|
frameOptions.sameOrigin()
|
|
}
|
|
}.csrf { csrf ->
|
|
csrf.disable()
|
|
}
|
|
|
|
return http.build()
|
|
}
|
|
}
|