Add remote authentication for users

- add RemoteReactiveAuthenticationManager
- add RemoteAuthentication
- add RemoteUserDetail
- add AccountRegistryService
- add WebClientCalls.kt with accountRegistryAuthenticate
- add Helper.kt with logCall
- add Mapping.kt toAuthenticationRequest
This commit is contained in:
2025-01-17 13:46:52 +01:00
parent 7cf39926d7
commit 9f6d7066b7
7 changed files with 186 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package ltd.hlaeja.util
import ltd.hlaeja.library.accountRegistry.Authentication
import ltd.hlaeja.property.AccountRegistryProperty
import org.springframework.http.HttpStatus.LOCKED
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.UNAUTHORIZED
import org.springframework.security.authentication.BadCredentialsException
import org.springframework.security.authentication.LockedException
import org.springframework.security.core.userdetails.UsernameNotFoundException
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Mono
fun WebClient.accountRegistryAuthenticate(
request: Authentication.Request,
property: AccountRegistryProperty,
): Mono<Authentication.Response> = post()
.uri("${property.url}/authenticate".also(::logCall))
.bodyValue(request)
.retrieve()
.onStatus(LOCKED::equals) { throw LockedException("Account is locked") }
.onStatus(UNAUTHORIZED::equals) { throw BadCredentialsException("Invalid credentials") }
.onStatus(NOT_FOUND::equals) { throw UsernameNotFoundException("User not found") }
.bodyToMono(Authentication.Response::class.java)