update remote user authentication
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package ltd.hlaeja.controller
|
package ltd.hlaeja.controller
|
||||||
|
|
||||||
import ltd.hlaeja.security.RemoteUserDetail
|
import ltd.hlaeja.security.user.RemoteUserDetail
|
||||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder
|
import org.springframework.security.core.context.ReactiveSecurityContextHolder
|
||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
import org.springframework.ui.Model
|
import org.springframework.ui.Model
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ltd.hlaeja.controller.advice
|
package ltd.hlaeja.controller.advice
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import ltd.hlaeja.security.RemoteAuthentication
|
import ltd.hlaeja.security.user.RemoteAuthentication
|
||||||
import ltd.hlaeja.security.user.GuestUser
|
import ltd.hlaeja.security.user.GuestUser
|
||||||
import org.springframework.boot.web.error.ErrorAttributeOptions
|
import org.springframework.boot.web.error.ErrorAttributeOptions
|
||||||
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes
|
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ltd.hlaeja.controller.advice
|
package ltd.hlaeja.controller.advice
|
||||||
|
|
||||||
import kotlinx.coroutines.reactive.awaitFirstOrNull
|
import kotlinx.coroutines.reactive.awaitFirstOrNull
|
||||||
import ltd.hlaeja.security.RemoteAuthentication
|
import ltd.hlaeja.security.user.RemoteAuthentication
|
||||||
import ltd.hlaeja.security.user.GuestUser
|
import ltd.hlaeja.security.user.GuestUser
|
||||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder
|
import org.springframework.security.core.context.ReactiveSecurityContextHolder
|
||||||
import org.springframework.ui.Model
|
import org.springframework.ui.Model
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ltd.hlaeja.security
|
package ltd.hlaeja.security.manager
|
||||||
|
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import io.jsonwebtoken.Claims
|
import io.jsonwebtoken.Claims
|
||||||
@@ -6,7 +6,8 @@ import io.jsonwebtoken.Jws
|
|||||||
import io.jsonwebtoken.JwtException
|
import io.jsonwebtoken.JwtException
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import ltd.hlaeja.jwt.service.PublicJwtService
|
import ltd.hlaeja.jwt.service.PublicJwtService
|
||||||
import ltd.hlaeja.library.accountRegistry.Authentication.Response
|
import ltd.hlaeja.security.user.RemoteAuthentication
|
||||||
|
import ltd.hlaeja.security.user.RemoteUserDetail
|
||||||
import ltd.hlaeja.service.AccountRegistryService
|
import ltd.hlaeja.service.AccountRegistryService
|
||||||
import ltd.hlaeja.util.toAuthenticationRequest
|
import ltd.hlaeja.util.toAuthenticationRequest
|
||||||
import org.springframework.security.authentication.AuthenticationServiceException
|
import org.springframework.security.authentication.AuthenticationServiceException
|
||||||
@@ -19,7 +20,7 @@ import reactor.core.publisher.Mono
|
|||||||
private val log = KotlinLogging.logger {}
|
private val log = KotlinLogging.logger {}
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class RemoteReactiveAuthenticationManager(
|
class RemoteAuthenticationManager(
|
||||||
private val accountRegistryService: AccountRegistryService,
|
private val accountRegistryService: AccountRegistryService,
|
||||||
private val publicJwtService: PublicJwtService,
|
private val publicJwtService: PublicJwtService,
|
||||||
) : ReactiveAuthenticationManager {
|
) : ReactiveAuthenticationManager {
|
||||||
@@ -30,7 +31,7 @@ class RemoteReactiveAuthenticationManager(
|
|||||||
.map(::processToken)
|
.map(::processToken)
|
||||||
|
|
||||||
private fun processToken(
|
private fun processToken(
|
||||||
response: Response,
|
response: ltd.hlaeja.library.accountRegistry.Authentication.Response,
|
||||||
): Authentication = try {
|
): Authentication = try {
|
||||||
publicJwtService.verify(response.token) { claims -> makeRemoteAuthentication(claims) }
|
publicJwtService.verify(response.token) { claims -> makeRemoteAuthentication(claims) }
|
||||||
} catch (e: JwtException) {
|
} catch (e: JwtException) {
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package ltd.hlaeja.security.user
|
package ltd.hlaeja.security.user
|
||||||
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import ltd.hlaeja.security.RemoteAuthentication
|
|
||||||
import ltd.hlaeja.security.RemoteUserDetail
|
|
||||||
|
|
||||||
interface GuestUser {
|
interface GuestUser {
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ltd.hlaeja.security
|
package ltd.hlaeja.security.user
|
||||||
|
|
||||||
import org.springframework.security.core.Authentication
|
import org.springframework.security.core.Authentication
|
||||||
import org.springframework.security.core.GrantedAuthority
|
import org.springframework.security.core.GrantedAuthority
|
||||||
@@ -25,6 +25,7 @@ data class RemoteAuthentication(
|
|||||||
authenticated = isAuthenticated
|
authenticated = isAuthenticated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
fun hasRole(role: String): Boolean {
|
fun hasRole(role: String): Boolean {
|
||||||
authorities.forEach {
|
authorities.forEach {
|
||||||
if (it.authority.equals("role_$role", true)) {
|
if (it.authority.equals("role_$role", true)) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ltd.hlaeja.security
|
package ltd.hlaeja.security.user
|
||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
Reference in New Issue
Block a user