fix: Extract token before usage

This commit is contained in:
2025-08-11 08:05:24 +02:00
parent 7439bf999b
commit e00870c739
@@ -16,7 +16,7 @@ import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.security.authorization.AuthorizationDeniedException import org.springframework.security.authorization.AuthorizationDeniedException
import org.springframework.security.core.context.SecurityContextHolder import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.jwt.Jwt import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
import org.springframework.web.bind.annotation.* import org.springframework.web.bind.annotation.*
@RestController @RestController
@@ -64,8 +64,8 @@ class UserController(
]) body: User ]) body: User
): ResponseEntity<User> { ): ResponseEntity<User> {
val authentication = SecurityContextHolder.getContext().authentication val authentication = SecurityContextHolder.getContext().authentication
val jwt = authentication as Jwt val jwt = authentication as JwtAuthenticationToken
val authorizedParty = jwt.getClaimAsString("azp") val authorizedParty = jwt.token.getClaimAsString("azp")
var created = false var created = false
val userIdConverted = UserId.of(NonEmptyString(userId)) val userIdConverted = UserId.of(NonEmptyString(userId))