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:
46
src/main/kotlin/ltd/hlaeja/service/AccountRegistryService.kt
Normal file
46
src/main/kotlin/ltd/hlaeja/service/AccountRegistryService.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package ltd.hlaeja.service
|
||||
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import ltd.hlaeja.library.accountRegistry.Authentication
|
||||
import ltd.hlaeja.property.AccountRegistryProperty
|
||||
import ltd.hlaeja.util.accountRegistryAuthenticate
|
||||
import org.springframework.security.authentication.AuthenticationServiceException
|
||||
import org.springframework.security.core.AuthenticationException
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import org.springframework.web.reactive.function.client.WebClientRequestException
|
||||
import org.springframework.web.reactive.function.client.WebClientResponseException
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
@Service
|
||||
class AccountRegistryService(
|
||||
private val webClient: WebClient,
|
||||
private val property: AccountRegistryProperty,
|
||||
) {
|
||||
|
||||
fun authenticate(
|
||||
request: Authentication.Request,
|
||||
): Mono<Authentication.Response> = webClient.accountRegistryAuthenticate(request, property)
|
||||
.onErrorResume { error ->
|
||||
when (error) {
|
||||
is AuthenticationException -> Mono.error(error)
|
||||
|
||||
is WebClientResponseException -> "WebClient response exception: ${error.message}".let {
|
||||
log.error(error) { it }
|
||||
Mono.error(AuthenticationServiceException(it, error))
|
||||
}
|
||||
|
||||
is WebClientRequestException -> "An error occurred while making a request: ${error.message}".let {
|
||||
log.error(error) { it }
|
||||
Mono.error(AuthenticationServiceException(it, error))
|
||||
}
|
||||
|
||||
else -> "An unexpected error occurred: ${error.message}".let {
|
||||
log.error(error) { it }
|
||||
Mono.error(AuthenticationServiceException(it, error))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user