5

keycloak~授权功能的使用

 2 years ago
source link: https://www.cnblogs.com/lori/p/15457498.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

keycloak提供了完善的授权功能,即在kc端对资源服务器的各种资源进行管理,然后就可以完成对它们的管控,这些资源可以根据kc的用户、角色、组等信息进行授权。

资源服务器客户端配置

  • 以springboot接口KC为例,说一下它的配置文件
keycloak:
  auth-server-url: http://192.168.xx.xx:8080/auth
  realm: fabao
  resource: democlient # client-id
  client-key-password: ec0fd1c6-68b0-4c39-a9fa-c3be25c8ef01 #客户端密钥
  credentials.secret: ec0fd1c6-68b0-4c39-a9fa-c3be25c8ef01 #客户端密钥,policy-enforcer-config.enforcement-mode: ENFORCING时,需要添加这个值
  principal-attribute: preferred_username # principal.getName()返回为用户名
  policy-enforcer-config:
    enforcement-mode: ENFORCING #kc远程授权方式
  security-constraints:
    - auth-roles:
        - "*"
      security-collections:
        - name:
          patterns:
            - /*

kc远程集中授权图

  • 策略与权限
  • 资源与权限scope

kc服务端-资源服务器配置

  1. 需要为当前客户端,添加它的uma_protected角色
  2. 开启远程授权
  3. 添加权限,实现了为资源绑定策略

上面各图中,配置了资源admin-resource,路径是admin开头的uri;配置了策略admin,包换ROLE_ADMIN角色的人;配置了admin-permission权限,让它绑定了admin策略,最后把它绑定到资源admin-resource上面。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK