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:
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