8.4. 使用安全授权配置缓存
在缓存配置中使用授权来限制用户访问。在他们可以读取或写缓存条目或删除缓存之前,用户必须具有足够级别的权限。
先决条件
确保
authorization元素包含在cache-container配置的security部分中。Data Grid 默认在 Cache Manager 中启用安全授权,并为缓存提供一组全局角色和权限。
- 如有必要,在 Cache Manager 配置中声明自定义角色和权限。
流程
- 打开缓存配置进行编辑。
-
添加
authorization元素以缓存,以根据用户的角色和权限限制用户访问权限。 - 保存对您的配置的更改。
授权配置
以下配置演示了如何将隐式授权配置与默认角色和权限一起使用:
XML
<distributed-cache>
<security>
<!-- Inherit authorization settings from the cache-container. --> <authorization/>
</security>
</distributed-cache>
JSON
{
"distributed-cache": {
"security": {
"authorization": {
"enabled": true
}
}
}
}
YAML
distributedCache:
security:
authorization:
enabled: true
自定义角色和权限
XML
<distributed-cache>
<security>
<authorization roles="admin supervisor"/>
</security>
</distributed-cache>
JSON
{
"distributed-cache": {
"security": {
"authorization": {
"enabled": true,
"roles": ["admin","supervisor"]
}
}
}
}
YAML
distributedCache:
security:
authorization:
enabled: true
roles: ["admin","supervisor"]