PrivMX DOCS
Kotlin

Policy Builders

PrivMX Endpoint has configurable policies that determine who can perform specified actions in Containers and Items.

To learn more about Policies, see the Policies documentation.

PrivMX Endpoint Kotlin Extra library provides classes that provide static fields of available policy values in ItemPolicyValues, ContainerPolicyValues and SpecialPolicyValue, as well as ItemPolicyBuilder and ContainerPolicyBuilder classes for configuring the respective policies.

Combining Policy Values

Some policy values like ContainerPolicyComplexValue or ItemPolicyComplexValue can be combined with the same type of policy value using AND and OR methods.

val itemPolicyValue: ItemPolicyValue = ItemPolicyValues.ITEM_OWNER AND
    ItemPolicyValues.MANAGER OR
    ItemPolicyValues.USER

Configuring a Container Policy

Builder will create an empty policy, if it's not configured yet, which is equivalent to setting inherit in all fields. To configure it, call the methods responsible for setting particular policies. Those calls can be chained together, since each of the methods setting a policy value returns the reference to the builder. The ContainerPolicyBuilder can build both ContainerPolicy and ContainerPolicyWithoutItem by calling .build() and .buildWithoutItem() respectively.

To build the ItemPolicy, use ItemPolicyBuilder which works in the same way as ContainerPolicyBuilder.

val itemPolicy: ItemPolicy = ItemPolicyBuilder()
    .update(
        ItemPolicyValues.ITEM_OWNER AND
                ItemPolicyValues.MANAGER OR
                ItemPolicyValues.USER
    )
    .listMy(ContainerPolicyValues.USER)
    .build()

Alternatively, you can use helper functions like itemPolicy, containerPolicy or containerPolicyWithoutItem, which offer a cleaner way to define your policies.

val itemPolicy: ItemPolicy = itemPolicy {
    update(
        ItemPolicyValues.ITEM_OWNER AND
                ItemPolicyValues.MANAGER OR
                ItemPolicyValues.USER
    )
    listMy(ContainerPolicyValues.USER)
}

We use cookies on our website. We use them to ensure the proper functioning of the site and, if you agree, for purposes we set, such as analytics or marketing.

PrivMX Endpoint Kotlin v2.2

This package is not up to date with the core documentation. Some of the features you've seen described in other parts of the documentation might not be mentioned here. Those changes do not influence compatibility, however

On this page