0

我正在尝试使微服务环境正常工作。我已经设置了 config-server、eureka-server、zuul-server 和 service。为了处理安全问题,我安装并运行了 Cloud Foundry 的 UAA 服务器。

按照有关如何设置 UAA 服务器的文档,可以选择将Ldap 组作为我拥有的范围,我可以看到它们是如何在 UAA 服务器日志上创建的,但它们不会进入 JWT 令牌。Zuul 正确代理到 UAA 服务器,我在 UAA 上执行身份验证过程并在 Zuul 上获取 JWT 令牌,然后 zuul 将代理添加到它后面的服务中,但没有登录用户的组/范围只有 openid 范围关于客户端配置。我错过了什么吗?或者这就是事情的工作方式,我必须实施一种解决方法,即从令牌中获取用户的用户名并获得他对每个服务的每个请求的访问权限?

这是我的 uaa.yml:

spring_profiles: ldap,mysql

disableInternalUserManagement: true

zones:
  internal:
    hostnames:
      - sso.example.com

oauth:
  user:
    authorities:
      - openid
      - scim.me
      - password.write
      - scim.userids
      - uaa.user
      - approvals.me
      - oauth.approvals
  clients:
    sso:
      secret: changeme!
      authorized-grant-types: authorization_code, refresh_token
      # How do I add the user groups as scopes?
      # Is it possible with this grant type?
      scope: openid
      authorities: uaa.resource

ldap:
  profile:
    file: ldap/ldap-search-and-bind.xml
  base:
    url: ldap://ldap.example.com:389
    mailAttributeName: mail
    mailSubstitute: '{0}@example.com'
    mailSubstituteOverridesLdap: true
    userDn: 'CN=Example User,OU=Admins,DC=example,DC=com'
    password: 'changeme!'
    searchBase: 'dc=example,dc=com'
    searchFilter: 'sAMAccountName={0}'
  groups:
    file: ldap/ldap-groups-as-scopes.xml
    searchBase: 'dc=example,dc=com'
    groupRoleAttribute: cn
    searchSubtree: true
    groupSearchFilter: 'member={0}'
    maxSearchDepth: 1
    autoAdd: true
  attributeMappings:
    first_name: 'givenName'
    last_name: 'sn'

smtp:
  host: mail.example.com
  port: 25

database:
  url: jdbc:mysql://mysql.example.com/uaa
  username: uaa
  password: changeme!

jwt:
  token:
    verification-key: |
      -----BEGIN PUBLIC KEY-----
      -----END PUBLIC KEY-----
    signing-key: |
      -----BEGIN RSA PRIVATE KEY-----
      -----END RSA PRIVATE KEY-----

login:
  url: https://sso.example.com/uaa/login
  branding:
    companyName: 'Example Company'
4

1 回答 1

0

您的问题源于客户端上未配置的范围。只有该客户端范围列表中的范围才能出现在用户 JWT 上。将范围添加到此列表将不允许用户获取他们没有的范围,也不会导致这些范围出现在客户端的客户端凭据令牌上。

如果您配置了组作为范围,您的客户端需要在其允许范围列表中配置您希望它使用的每个范围。

于 2016-06-16T21:34:07.417 回答