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

时间:2018-11-30 09:01:08

标签: spring-boot keycloak

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

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

用户的属性位置和值都为孟买。

1 个答案:

答案 0 :(得分:1)

您可以进行如下操作,因为属性是列表,所以可以先检查 元素

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