mirror of
https://github.com/MewoLab/AquaDX.git
synced 2025-10-26 04:22:38 +00:00
37 lines
1.3 KiB
Kotlin
37 lines
1.3 KiB
Kotlin
package icu.samnyan.aqua.spring
|
|
|
|
import org.springframework.context.annotation.Bean
|
|
import org.springframework.context.annotation.Configuration
|
|
import org.springframework.security.config.Customizer
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
|
|
import org.springframework.security.web.SecurityFilterChain
|
|
import org.springframework.web.cors.CorsConfiguration
|
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
|
|
|
|
|
|
@Configuration
|
|
@EnableWebSecurity
|
|
class SecurityConfig {
|
|
@Bean
|
|
fun corsConfigurationSource() = UrlBasedCorsConfigurationSource().apply {
|
|
registerCorsConfiguration("/api/**", CorsConfiguration().apply {
|
|
allowedOrigins = listOf("*")
|
|
allowedMethods = listOf("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
|
allowedHeaders = listOf("*")
|
|
})
|
|
}
|
|
|
|
@Bean
|
|
fun configure(http: HttpSecurity): SecurityFilterChain = http
|
|
.headers { it.disable() }
|
|
.cors(Customizer.withDefaults())
|
|
.csrf { it.disable() }
|
|
.authorizeHttpRequests { it.anyRequest().permitAll() }
|
|
.build()
|
|
|
|
@Bean
|
|
fun passwordEncoder() = BCryptPasswordEncoder()
|
|
}
|