Skip to content

Commit

Permalink
chore(core): Log the duration to load Keycloak roles
Browse files Browse the repository at this point in the history
Log the duration it takes to load the Keycloak roles for a user.

Signed-off-by: Martin Nonnenmacher <[email protected]>
  • Loading branch information
mnonnenmacher committed Mar 20, 2024
1 parent f6f930f commit ad41093
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/src/main/kotlin/plugins/Authentication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import io.ktor.server.config.ApplicationConfig
import java.net.URI
import java.util.concurrent.TimeUnit

import kotlin.time.measureTimedValue

import org.eclipse.apoapsis.ortserver.clients.keycloak.KeycloakClient
import org.eclipse.apoapsis.ortserver.clients.keycloak.UserId
import org.eclipse.apoapsis.ortserver.core.authorization.OrtPrincipal
Expand Down Expand Up @@ -65,9 +67,15 @@ fun Application.configureAuthentication() {

validate { credential ->
credential.payload.takeIf(this@configureAuthentication::validateJwtPayload)?.let { payload ->
val roles = runCatching {
keycloakClient.getUserClientRoles(UserId(payload.subject))
.mapTo(mutableSetOf()) { it.name.value }
val (result, duration) = measureTimedValue {
runCatching {
keycloakClient.getUserClientRoles(UserId(payload.subject))
.mapTo(mutableSetOf()) { it.name.value }
}
}

val roles = result.onSuccess {
logger.debug("Loaded ${it.size} Keycloak roles for '${payload.subject}' in $duration.")
}.onFailure {
logger.error("Failed to load Keycloak roles for '${payload.subject}'.", it)
}.getOrThrow()
Expand Down

0 comments on commit ad41093

Please sign in to comment.