Sindhu Arju
Sindhu Arju

Reputation: 438

Attribute Based Policy in keycloak

How to create a user attribute based policy?

var context = $evaluation.getContext();
var identity = context.getIdentity();
var attributes = identity.getAttributes();
if (identity.location=='mumbai') {
    $evaluation.grant();
}

A User has an attribute location and value as mumbai.

Upvotes: 2

Views: 656

Answers (1)

ravthiru
ravthiru

Reputation: 9633

You could to some thing like this, as attributes are list, you can check first element

var context = $evaluation.getContext();
var identity = context.getIdentity();
var attributes = identity.getAttributes();
if (attributes.location !== null && attributes.location[0] == "mumbai") {
    $evaluation.grant();
} 

Upvotes: 1

Related Questions