Authentication

- add AuthenticationController
- add AuthenticationService
- add AccountRegistryProperty
- add WebClient.accountRegistryAuthenticate to WebClientCalls.kt
This commit is contained in:
2025-01-01 20:25:03 +01:00
parent 0d2457b574
commit 22222fb0e3
6 changed files with 105 additions and 0 deletions

View File

@@ -1,8 +1,13 @@
package ltd.hlaeja.util
import ltd.hlaeja.library.accountRegistry.Authentication
import ltd.hlaeja.library.deviceRegistry.Device
import ltd.hlaeja.property.AccountRegistryProperty
import ltd.hlaeja.property.DeviceRegistryProperty
import org.springframework.http.HttpStatus.LOCKED
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.REQUEST_TIMEOUT
import org.springframework.http.HttpStatus.UNAUTHORIZED
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.awaitBodyOrNull
import org.springframework.web.server.ResponseStatusException
@@ -15,3 +20,15 @@ suspend fun WebClient.deviceRegistryCreateDevice(
.bodyValue(request)
.retrieve()
.awaitBodyOrNull<Device.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)
suspend fun WebClient.accountRegistryAuthenticate(
request: Authentication.Request,
property: AccountRegistryProperty,
): Authentication.Response = post()
.uri("${property.url}/authenticate".also(::logCall))
.bodyValue(request)
.retrieve()
.onStatus(LOCKED::equals) { throw ResponseStatusException(UNAUTHORIZED) }
.onStatus(UNAUTHORIZED::equals) { throw ResponseStatusException(UNAUTHORIZED) }
.onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NOT_FOUND) }
.awaitBodyOrNull<Authentication.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)