
Implements Attribute Based Access Control with expressive, decoupled policy-based authorization. Supports flexible, enforceable rules across systems, enhancing architectural flexibility and authorization logic.
Warden is attribute based access control (ABAC) for Kotlin on the JVM. You write authorization rules as policies over the attributes of a request: who is asking, what they want to do, what they want to do it to, and in what context. Warden evaluates them and guards your code, with no dependency on a web framework.
Policies are plain Kotlin values built with a small DSL. They talk about your domain, not your URLs:
val articlePolicies = listOf(
// Any user can read any article
allOf {
resource("type") equalTo "Article"
action("type") equalTo "READ"
},
// The author of an article can modify and delete it
allOf {
resource("type") equalTo "Article"
action("type") isIn listOf("MODIFY", "DELETE")
subject("id") equalTo resourceVal("authorId")
},
// Only authors can create articles
allOf {
resource("type") equalTo "Article"
action("type") equalTo "CREATE"
subject("roles") contains "Author"
},
)An enforcement point protects any execution path. If no policy grants access, it throws NotAuthorizedException and
the code after it never runs:
val enforcementPoint = EnforcementPointDefault(articlePolicies)
suspend fun readArticle(user: User, articleId: String): Article {
val article = articles.getById(articleId)
enforcementPoint.enforceAuthorization(
AccessRequest(
subject = user.atts(),
action = mapOf("type" to "READ"),
resource = article.atts(),
))
return article
}The complete example, with its tests, is in docs/guides/snippets and is explained step by
step in Getting started.
DecisionPoint evaluates allow and deny policies; an
EnforcementPoint turns a denial into an exception or filters a collection down to what is permitted.repositories {
mavenCentral()
}
dependencies {
implementation("codes.laurence.warden:warden-core:<version>")
implementation("codes.laurence.warden:warden-atts:<version>") // domain objects to attribute maps
implementation("codes.laurence.warden:warden-ktor3:<version>") // Ktor plugin
implementation("codes.laurence.warden:warden-http4k6:<version>") // http4k filter
implementation("codes.laurence.warden:warden-springboot4-webflux:<version>") // Spring WebFlux filter, Spring Boot 4
}| Artifact | Contents |
|---|---|
warden-core |
Access requests, the policy DSL, decision, information and enforcement points |
warden-atts |
HasAtts and AttType: turn domain objects into attribute maps by reflection |
warden-ktor3 |
A Ktor 3 server plugin that makes enforcement mandatory per route |
warden-http4k6 |
An http4k 6 filter that makes enforcement mandatory per route |
warden-springboot4-webflux |
A Spring WebFlux filter for Spring Boot 4 that makes enforcement mandatory per route, auto-configured |
warden-springboot4 |
Shared by the Spring adapters: route configuration, an enforcement point and denial handling |
Requires JDK 17 or later; warden-http4k6 requires JDK 21, as http4k 6 does.
| Guide | Covers |
|---|---|
| Key concepts | Access requests, policies, decision, information and enforcement points |
| Getting started | Policies and enforcement for a small blog |
| Policies | Expression, boolean and collection member policies |
| Decision and enforcement | Policy sources, information points, decision and enforcement points |
| Attributes |
warden-atts helpers to build attributes |
| Testing | Testing policies, services and routes |
| Ktor | The Ktor plugin |
| http4k | The http4k filter |
| Spring WebFlux | The Spring WebFlux filter and its Spring Boot auto-configuration |
The API reference covers every public type.
Requires JDK 17. Gradle downloads the JDK 21 toolchain that warden-http4k6 and the guide snippets build with.
./gradlew test
./gradlew ktfmtFormat # before opening a PRAGENTS.md holds the design rules the library is built to.docs/roadmap.md lists outstanding work.docs/guides; open it with the
Writerside plugin for IntelliJ IDEA to preview them. The code they quote lives in docs/guides/snippets and is
compiled and tested by ./gradlew test. ./gradlew dokkaGenerate builds the API reference.PUBLISHING_SETUP.md.Licensed under MIT.
Warden is attribute based access control (ABAC) for Kotlin on the JVM. You write authorization rules as policies over the attributes of a request: who is asking, what they want to do, what they want to do it to, and in what context. Warden evaluates them and guards your code, with no dependency on a web framework.
Policies are plain Kotlin values built with a small DSL. They talk about your domain, not your URLs:
val articlePolicies = listOf(
// Any user can read any article
allOf {
resource("type") equalTo "Article"
action("type") equalTo "READ"
},
// The author of an article can modify and delete it
allOf {
resource("type") equalTo "Article"
action("type") isIn listOf("MODIFY", "DELETE")
subject("id") equalTo resourceVal("authorId")
},
// Only authors can create articles
allOf {
resource("type") equalTo "Article"
action("type") equalTo "CREATE"
subject("roles") contains "Author"
},
)An enforcement point protects any execution path. If no policy grants access, it throws NotAuthorizedException and
the code after it never runs:
val enforcementPoint = EnforcementPointDefault(articlePolicies)
suspend fun readArticle(user: User, articleId: String): Article {
val article = articles.getById(articleId)
enforcementPoint.enforceAuthorization(
AccessRequest(
subject = user.atts(),
action = mapOf("type" to "READ"),
resource = article.atts(),
))
return article
}The complete example, with its tests, is in docs/guides/snippets and is explained step by
step in Getting started.
DecisionPoint evaluates allow and deny policies; an
EnforcementPoint turns a denial into an exception or filters a collection down to what is permitted.repositories {
mavenCentral()
}
dependencies {
implementation("codes.laurence.warden:warden-core:<version>")
implementation("codes.laurence.warden:warden-atts:<version>") // domain objects to attribute maps
implementation("codes.laurence.warden:warden-ktor3:<version>") // Ktor plugin
implementation("codes.laurence.warden:warden-http4k6:<version>") // http4k filter
implementation("codes.laurence.warden:warden-springboot4-webflux:<version>") // Spring WebFlux filter, Spring Boot 4
}| Artifact | Contents |
|---|---|
warden-core |
Access requests, the policy DSL, decision, information and enforcement points |
warden-atts |
HasAtts and AttType: turn domain objects into attribute maps by reflection |
warden-ktor3 |
A Ktor 3 server plugin that makes enforcement mandatory per route |
warden-http4k6 |
An http4k 6 filter that makes enforcement mandatory per route |
warden-springboot4-webflux |
A Spring WebFlux filter for Spring Boot 4 that makes enforcement mandatory per route, auto-configured |
warden-springboot4 |
Shared by the Spring adapters: route configuration, an enforcement point and denial handling |
Requires JDK 17 or later; warden-http4k6 requires JDK 21, as http4k 6 does.
| Guide | Covers |
|---|---|
| Key concepts | Access requests, policies, decision, information and enforcement points |
| Getting started | Policies and enforcement for a small blog |
| Policies | Expression, boolean and collection member policies |
| Decision and enforcement | Policy sources, information points, decision and enforcement points |
| Attributes |
warden-atts helpers to build attributes |
| Testing | Testing policies, services and routes |
| Ktor | The Ktor plugin |
| http4k | The http4k filter |
| Spring WebFlux | The Spring WebFlux filter and its Spring Boot auto-configuration |
The API reference covers every public type.
Requires JDK 17. Gradle downloads the JDK 21 toolchain that warden-http4k6 and the guide snippets build with.
./gradlew test
./gradlew ktfmtFormat # before opening a PRAGENTS.md holds the design rules the library is built to.docs/roadmap.md lists outstanding work.docs/guides; open it with the
Writerside plugin for IntelliJ IDEA to preview them. The code they quote lives in docs/guides/snippets and is
compiled and tested by ./gradlew test. ./gradlew dokkaGenerate builds the API reference.PUBLISHING_SETUP.md.Licensed under MIT.