accessPolicy

inline fun <reified S : Any> accessPolicy(aggregate: AggregateType? = null, noinline block: AccessPolicyBuilder<S>.() -> Unit): AccessPolicy<S>

The access policy of the aggregates whose state is S, from block: it gives AccessPolicyBuilder.read and AccessPolicyBuilder.write, or AccessPolicyBuilder.readWrite for one predicate of both. aggregate names the aggregate when several share the state type.

@Bean
fun documentAccess(): AccessPolicy<DocumentState> = accessPolicy {
read { caller ->
anyOf(
DocumentStateAccess.DEPARTMENT isIn caller.claims("departments"),
DocumentStateAccess.SHARED_WITH contains caller.subject,
DocumentStateAccess.ORG startsWith caller.claim("org"),
allowIf(caller.hasRole("auditor")),
)
}
write { caller -> DocumentStateAccess.DEPARTMENT isIn caller.claims("departments") }
}

fun <S : Any> accessPolicy(stateType: Class<S>, aggregate: AggregateType? = null, block: AccessPolicyBuilder<S>.() -> Unit): AccessPolicy<S>

The access policy of the aggregates whose state is stateType, as the reified accessPolicy builds it.