Skip to main content

Secured routes

Two helpers for restricting access to a set of routes once an AuthenticationFilter is in place. Both return Response(Status.FORBIDDEN) when the access check fails. To return a 404 instead (to avoid revealing the existence of protected URLs), combine with StatusOverride and ErrorPages.

authenticatedRoutes

Requires that a Principal is attached to the request.

val handler = authenticatedRoutes(
DashboardHandler(),
LogoutHandler()
)

securedRoutes

Requires that the request's principal is an instance of P and passes the check predicate.

val handler = securedRoutes<AppPrincipal>(
check = { it.roles.contains("ADMIN") },
route = routes(
"/admin" GET { Response(Status.OK) }
)
)