This commit is contained in:
Vladimir Voronin
2025-01-07 12:35:17 +03:00
commit afd8e9f6d7
72 changed files with 4606 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
package space.luminic.budgerapp.controllers
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.security.core.AuthenticationException
import org.springframework.security.web.server.ServerAuthenticationEntryPoint
import org.springframework.stereotype.Component
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono
import java.util.*
@Component
class CustomAuthenticationEntryPoint : ServerAuthenticationEntryPoint {
override fun commence(
exchange: ServerWebExchange,
ex: AuthenticationException
): Mono<Void> {
val response = exchange.response
response.statusCode = HttpStatus.UNAUTHORIZED
response.headers.contentType = MediaType.APPLICATION_JSON
val body = mapOf(
"timestamp" to Date(),
"status" to HttpStatus.UNAUTHORIZED.value(),
"error" to "Unauthorized",
"message" to ex.message,
"path" to exchange.request.path.value()
)
val buffer = response.bufferFactory().wrap(ObjectMapper().writeValueAsBytes(body))
return response.writeWith(Mono.just(buffer))
}
}