accessPolicySpec

fun <S : Any> accessPolicySpec(model: AggregateModel<S>, policy: AccessPolicy<S>, block: AccessPolicySpec<S>.() -> Unit)

Checks the access policy of model's aggregates: given an aggregate (its events, or its state), whether a caller may read it and change it, as the kernel and the queries decide (the access attributes the state derives, the built-in owner and space its scope's).

accessPolicySpec(documentModel, documentAccess) {
given(DocumentCreated("sales"), DocumentShared("bob"))
whenCaller(subject = "bob", claims = mapOf("departments" to listOf("hr"))) {
expectRead()
expectNoWrite()
}
}

A service acting as itself (Caller.service, Caller.ofService) may read and change every aggregate, as the kernel and the queries trust a service under a policy: the policy's predicates are not evaluated for it.

A check fails, too, when the policy compares an attribute model's aggregates do not have (declares): one it does not declare, or the owner of a tenant's aggregate, which records none. A node does not refuse such a policy at its start: its kernel and its queries read every comparison of such an attribute, negated or not and isNull() included, as matching no aggregate (it fails closed), and the queries log it once. A policy's references are typed by its state (AccessAttribute<in S, V>, generated in <State>Access), so an undeclared one hardly compiles; it does in a policy built against another version of the state.