Skip to main content

Principal

See Security — Core concepts for an overview.

Principal

Marker interface for the authenticated entity, requiring a stable reference.

interface Principal {
val ref: PrincipalRef
}

data class PrincipalRef(val type: String, val id: String) {
override fun toString(): String = "$type:$id" // e.g. "user:abc123"
}

Request.principal

Returns the Principal attached to the request via AuthenticationFilter (or withPrincipal()), or null when no principal is attached.

val Request.principal: Principal?

Request.hasPrincipal

True when a principal is attached to the request.

val Request.hasPrincipal: Boolean

Request.withPrincipal

Returns a copy of the request with the given principal attached. Primarily intended for testing handlers that depend on an authenticated principal — in production code the principal is set by AuthenticationFilter.

fun Request.withPrincipal(principal: Principal): Request