keycloak-scim/authorization_services/topics/policy-drools-policy.adoc

97 lines
3.1 KiB
Text
Raw Normal View History

2016-11-29 15:30:53 +00:00
[[_policy_drools]]
= Rule-Based Policy
2016-06-05 22:17:31 +00:00
:tech_feature_name: Drools Policy
:tech_feature_setting: -Dkeycloak.profile.feature.authz_drools_policy=enabled
include::./templates/techpreview.adoc[]
With this type of policy you can define conditions for your permissions using http://www.drools.org[Drools], which is a rule evaluation environment. It is one of the _Rule-Based_ policy types
2017-08-28 12:50:14 +00:00
supported by {project_name}, and provides flexibility to write any policy based on the <<_policy_evaluation_api, Evaluation API>>.
2016-06-05 22:17:31 +00:00
2017-04-25 22:52:57 +00:00
To create a new Rule-based policy, in the dropdown list in the right upper corner of the policy listing,
2016-11-29 15:30:53 +00:00
select *Rule*.
2016-11-29 15:30:53 +00:00
.Add Rule Policy
2017-08-28 12:50:14 +00:00
image:{project_images}/policy/create-drools.png[alt="Add Rule Policy"]
== Configuration
2016-06-05 22:17:31 +00:00
* *Name*
+
A human-readable and unique string describing the policy. We strongly suggest that you use names that are closely related with your business and security requirements, so you
can identify them more easily and also know what they actually mean.
2016-06-05 22:17:31 +00:00
+
* *Description*
+
A string with more details about this policy.
2016-06-05 22:17:31 +00:00
+
* *Policy Maven Artifact*
+
A Maven groupId-artifactId-version (GAV) pointing to an artifact where the rules are defined. Once you have provided the GAV, you can click *Resolve* to load both *Module* and *Session* fields.
2016-06-05 22:17:31 +00:00
+
** Group Id
+
The groupId of the artifact.
2016-06-05 22:17:31 +00:00
+
** Artifact Id
+
The artifactId of the artifact.
2016-06-05 22:17:31 +00:00
+
** Version
+
The version of the artifact.
2016-06-05 22:17:31 +00:00
+
* *Module*
+
The module used by this policy. You must provide a module to select a specific session from which rules will be loaded.
2016-06-05 22:17:31 +00:00
+
* *Session*
+
The session used by this policy. The session provides all the rules to evaluate when processing the policy.
2016-06-05 22:17:31 +00:00
+
* *Update Period*
+
Specifies an interval for scanning for artifact updates.
2016-06-05 22:17:31 +00:00
+
* *Logic*
+
2017-08-28 12:50:14 +00:00
The <<_policy_logic, Logic>> of this policy to apply after the other conditions have been evaluated.
2016-06-05 22:17:31 +00:00
== Examples
2016-06-05 22:17:31 +00:00
Here is a simple example of a Drools-based policy that uses attribute-based access control (ABAC) to define a condition that evaluates to a GRANT
2016-06-05 22:17:31 +00:00
only if the authenticated user is the owner of the requested resource:
```javascript
import org.keycloak.authorization.policy.evaluation.Evaluation;
rule "Authorize Resource Owner"
dialect "mvel"
when
$evaluation : Evaluation(
$identity: context.identity,
$permission: permission,
$permission.resource != null && $permission.resource.owner.equals($identity.id)
)
then
$evaluation.grant();
end
```
You can even use another variant of ABAC to obtain attributes from the identity and define a condition accordingly:
```javascript
import org.keycloak.authorization.policy.evaluation.Evaluation;
rule "Authorize Using Identity Information"
dialect "mvel"
when
$evaluation : Evaluation(
$identity: context.identity,
identity.attributes.containsValue("someAttribute", "you_can_access")
)
then
$evaluation.grant();
end
```
2017-08-28 12:50:14 +00:00
For more information about what you can access from the `org.keycloak.authorization.policy.evaluation.Evaluation` interface, see <<_policy_evaluation_api, Evaluation API>>.