Red Hat Single Sign-On 利用 UMA Protection API 允许资源服务器管理其用户的权限。除了 Resource 和 Permission API 外,Red Hat Single Sign-On 还提供了 Policy API,其中权限可以通过代表他们的用户的资源服务器设置为资源。
curl -X POST \
http://localhost:8180/auth/realms/photoz/authz/protection/uma-policy/{resource_id} \
-H 'Authorization: Bearer '$access_token \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"name": "Any people manager",
"description": "Allow access to any people manager",
"scopes": ["read"],
"roles": ["people-manager"]
}'
curl-X POST \
http://localhost:8180/auth/realms/photoz/authz/protection/uma-policy/{resource_id}\-H'Authorization: Bearer '$access_token\-H'Cache-Control: no-cache'\-H'Content-Type: application/json'\-d'{
"name": "Any people manager",
"description": "Allow access to any people manager",
"scopes": ["read"],
"roles": ["people-manager"]
}'
Copy to ClipboardCopied!Toggle word wrapToggle overflow
在上面的示例中,我们会创建新权限并将其与 resource_id 表示的资源关联,其中任何具有 role people-manager 的用户都应该被 读取 范围授予。
您还可以使用其他访问控制机制创建策略,比如使用组:
curl -X POST \
http://localhost:8180/auth/realms/photoz/authz/protection/uma-policy/{resource_id} \
-H 'Authorization: Bearer '$access_token \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"name": "Any people manager",
"description": "Allow access to any people manager",
"scopes": ["read"],
"groups": ["/Managers/People Managers"]
}'
curl-X POST \
http://localhost:8180/auth/realms/photoz/authz/protection/uma-policy/{resource_id}\-H'Authorization: Bearer '$access_token\-H'Cache-Control: no-cache'\-H'Content-Type: application/json'\-d'{
"name": "Any people manager",
"description": "Allow access to any people manager",
"scopes": ["read"],
"groups": ["/Managers/People Managers"]
}'
Copy to ClipboardCopied!Toggle word wrapToggle overflow
或者一个特定的客户端:
curl -X POST \
http://localhost:8180/auth/realms/photoz/authz/protection/uma-policy/{resource_id} \
-H 'Authorization: Bearer '$access_token \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"name": "Any people manager",
"description": "Allow access to any people manager",
"scopes": ["read"],
"clients": ["my-client"]
}'
curl-X POST \
http://localhost:8180/auth/realms/photoz/authz/protection/uma-policy/{resource_id}\-H'Authorization: Bearer '$access_token\-H'Cache-Control: no-cache'\-H'Content-Type: application/json'\-d'{
"name": "Any people manager",
"description": "Allow access to any people manager",
"scopes": ["read"],
"clients": ["my-client"]
}'
Copy to ClipboardCopied!Toggle word wrapToggle overflow