Grant Relationships Conditionally
Relationships can be granted dynamically, based on a specified condition. In order to conditionally grant a relationship, the schemas for the resources you are creating a relationship between need to be configured to support conditional association. To do this, three fields in the schema are used:
conditionalAssociation
Boolean. This property is applied to the
resourceCollection
for the grantor of the relationship. For example, themembers
relationship onmanaged/role
specifies that there is a conditional association with themanaged/user
resource:"resourceCollection" : [ { "notify" : true, "conditionalAssociation" : true, "path" : "managed/user", "label" : "User", "query" : { "queryFilter" : "true", "fields" : [ "userName", "givenName", "sn" ] } } ]
conditionalAssociationField
This property is a string, specifying the field used to determine whether a conditional relationship is granted. The field is applied to the
resourceCollection
of the grantee of the relationship. For example, theroles
relationship onmanaged/user
specifies that the conditional association withmanaged/role
is defined by thecondition
field inmanaged/role
:"resourceCollection" : [ { "path" : "managed/role", "label" : "Role", "conditionalAssociationField" : "condition", "query" : { "queryFilter" : "true", "fields" : [ "name" ] } } ]
The field name specified will usually be
condition
if you are using default schema, but can be any field that evaluates a condition and has been flagged asisConditional
.isConditional
Boolean. This is applied to the field you wish to check to determine whether membership in a relationship is granted. Only one field on a resource can be marked as
isConditional
. For example, in the relationship betweenmanaged/user
andmanaged/role
, conditional membership in the relationship is determined by the query filter specified in themanaged/role
condition
field:"condition" : { "description" : "A conditional filter for this role", "title" : "Condition", "viewable" : false, "searchable" : false, "isConditional" : true, "type" : "string" }
Conditions can be a powerful tool for dynamically creating relationships between two objects. An example of conditional relationships in use can be seen in Grant a Role Based on a Condition.