update remote user authentication

This commit is contained in:
2025-07-31 22:51:20 +02:00
parent 9321a7eadd
commit fd9c927b02
7 changed files with 11 additions and 11 deletions

View File

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

View File

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

View File

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

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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)) {

View File

@@ -1,4 +1,4 @@
package ltd.hlaeja.security
package ltd.hlaeja.security.user
import java.io.Serializable
import java.util.UUID