Authentication
- add AuthenticationController - add AuthenticationService - add AccountRegistryProperty - add WebClient.accountRegistryAuthenticate to WebClientCalls.kt
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user