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