密钥斗篷中基于属性的策略

Attribute Based Policy in keycloak

如何创建基于用户属性的策略?

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

用户的属性位置和值为 mumbai。

你可以这样做,因为属性是列表,你可以先检查一下 元素

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