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:
7
src/main/kotlin/ltd/hlaeja/util/Helper.kt
Normal file
7
src/main/kotlin/ltd/hlaeja/util/Helper.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package ltd.hlaeja.util
|
||||
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
fun logCall(url: String) = log.debug { "calling: $url" }
|
||||
10
src/main/kotlin/ltd/hlaeja/util/Mapping.kt
Normal file
10
src/main/kotlin/ltd/hlaeja/util/Mapping.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package ltd.hlaeja.util
|
||||
|
||||
import org.springframework.security.core.Authentication as SpringAuthentication
|
||||
|
||||
import ltd.hlaeja.library.accountRegistry.Authentication
|
||||
|
||||
fun SpringAuthentication.toAuthenticationRequest(): Authentication.Request = Authentication.Request(
|
||||
principal as String,
|
||||
credentials as String,
|
||||
)
|
||||
24
src/main/kotlin/ltd/hlaeja/util/WebClientCalls.kt
Normal file
24
src/main/kotlin/ltd/hlaeja/util/WebClientCalls.kt
Normal 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)
|
||||
Reference in New Issue
Block a user