add SecurityConfiguration

This commit is contained in:
2025-01-14 19:08:18 +01:00
parent 50ea6764d0
commit b812f835ab

View File

@@ -0,0 +1,29 @@
package ltd.hlaeja.configuration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
import org.springframework.security.config.web.server.ServerHttpSecurity
import org.springframework.security.config.web.server.ServerHttpSecurity.AuthorizeExchangeSpec
import org.springframework.security.web.server.SecurityWebFilterChain
@Configuration
@EnableWebFluxSecurity
class SecurityConfiguration {
@Bean
fun securityWebFilterChain(serverHttpSecurity: ServerHttpSecurity): SecurityWebFilterChain = serverHttpSecurity
.authorizeExchange(::authorizeExchange)
.build()
private fun authorizeExchange(authorizeExchange: AuthorizeExchangeSpec) = authorizeExchange
.publicPaths().permitAll()
.anyExchange().authenticated()
private fun AuthorizeExchangeSpec.publicPaths(): AuthorizeExchangeSpec.Access = pathMatchers(
"/css/**",
"/js/**",
"/img/**",
"/actuator/**",
)
}