5.4. LDAP 域

LDAP 域连接到 LDAP 服务器(如 OpenLDAP、Red Hat Directory Server、Apache Directory Server 或 Microsoft Active Directory)以验证用户身份并获取成员资格信息。

注意

LDAP 服务器可以有不同的条目布局,具体取决于服务器和部署的类型。此文档超出了本文档的范围,提供了有关所有可能的配置的示例。

重要

LDAP 连接主体必须具有必要的权限才能执行 LDAP 查询和访问特定属性。

作为使用 direct-verification 属性验证用户凭据的替代选择,您可以指定一个 LDAP 属性来验证密码的 user-password-mapper 元素。

注意

您不能使用通过 直接验证属性执行哈希的端点 身份验证机制。

由于 Active Directory 没有公开 密码 属性,所以只能使用 direct-verification 属性,而不是 user-password-mapper 元素。因此,您必须将 BASIC 身份验证机制与 REST 端点搭配使用,PL AIN 与 Hot Rod 端点与 Active Directory 服务器集成。更为安全的替代方案是使用 Kerberos,它允许 SPNEGOGSSAPIGS2-KRB5 身份验证机制。

rdn-identifier 属性指定 LDAP 属性,它根据提供的标识符查找用户条目,后者通常是用户名;例如,uidsAMAccountName 属性。将 search-recursive="true" 添加到配置中,以递归搜索目录。默认情况下,搜索用户条目使用 (rdn_identifier={0}) 过滤器。使用 filter-name 属性指定不同的过滤器。

attribute-mapping 元素检索用户所属的所有组。通常,存储成员资格信息的方法有两种:

  • member 属性中通常具有类 groupOfNames 的组条目下。在这种情况下,您可以使用如上例配置中的属性过滤器。此过滤器搜索与提供的过滤器匹配的条目,该过滤器查找带有与用户 DN 相等的 member 属性的组。然后,过滤器提取组条目的 CN ( 指定),并将其添加到用户的 Roles 中。
  • memberOf 属性中的用户条目中。在这种情况下,您应该使用属性引用,如下所示:

    <attribute-reference reference="memberOf" from="cn" to="Roles" />

    此引用从用户的条目获取所有 memberOf 属性,按照 提取 CN,并将它们添加到用户的 Roles 中。

LDAP 域配置

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="LdapRealm">
        <!-- Specifies connection properties. -->
        <ldap-realm url="ldap://my-ldap-server:10389"
                    principal="uid=admin,ou=People,dc=infinispan,dc=org"
                    credential="strongPassword"
                    connection-timeout="3000"
                    read-timeout="30000"
                    connection-pooling="true"
                    referral-mode="ignore"
                    page-size="30"
                    direct-verification="true">
          <!-- Defines how principals are mapped to LDAP entries. -->
          <identity-mapping rdn-identifier="uid"
                            search-dn="ou=People,dc=infinispan,dc=org"
                            search-recursive="false">
            <!-- Retrieves all the groups of which the user is a member. -->
            <attribute-mapping>
              <attribute from="cn" to="Roles"
                         filter="(&amp;(objectClass=groupOfNames)(member={1}))"
                         filter-dn="ou=Roles,dc=infinispan,dc=org"/>
            </attribute-mapping>
          </identity-mapping>
        </ldap-realm>
      </security-realm>
    </security-realms>
  </security>
</server>

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "LdapRealm",
        "ldap-realm": {
          "url": "ldap://my-ldap-server:10389",
          "principal": "uid=admin,ou=People,dc=infinispan,dc=org",
          "credential": "strongPassword",
          "connection-timeout": "3000",
          "read-timeout": "30000",
          "connection-pooling": "true",
          "referral-mode": "ignore",
          "page-size": "30",
          "direct-verification": "true",
          "identity-mapping": {
            "rdn-identifier": "uid",
            "search-dn": "ou=People,dc=infinispan,dc=org",
            "search-recursive": "false",
            "attribute-mapping": [{
              "from": "cn",
              "to": "Roles",
              "filter": "(&(objectClass=groupOfNames)(member={1}))",
              "filter-dn": "ou=Roles,dc=infinispan,dc=org"
            }]
          }
        }
      }]
    }
  }
}

YAML

server:
  security:
    securityRealms:
      - name: LdapRealm
        ldapRealm:
          url: 'ldap://my-ldap-server:10389'
          principal: 'uid=admin,ou=People,dc=infinispan,dc=org'
          credential: strongPassword
          connectionTimeout: '3000'
          readTimeout: '30000'
          connectionPooling: true
          referralMode: ignore
          pageSize: '30'
          directVerification: true
          identityMapping:
            rdnIdentifier: uid
            searchDn: 'ou=People,dc=infinispan,dc=org'
            searchRecursive: false
            attributeMapping:
              - filter: '(&(objectClass=groupOfNames)(member={1}))'
                filterDn: 'ou=Roles,dc=infinispan,dc=org'
                from: cn
                to: Roles

5.4.1. LDAP 域主体重新编写

SASL 验证机制(如 GSSAPIGS2-KRB5Negotiate )包括需要 清理 的用户名,然后才能使用它来搜索 LDAP 目录。

XML

<server xmlns="urn:infinispan:server:13.0">
  <security>
    <security-realms>
      <security-realm name="LdapRealm">
        <ldap-realm url="ldap://${org.infinispan.test.host.address}:10389"
                    principal="uid=admin,ou=People,dc=infinispan,dc=org"
                    credential="strongPassword">
          <name-rewriter>
            <!-- Defines a rewriter that extracts the username from the principal using a regular expression. -->
            <regex-principal-transformer name="domain-remover"
                                         pattern="(.*)@INFINISPAN\.ORG"
                                         replacement="$1"/>
          </name-rewriter>
          <identity-mapping rdn-identifier="uid"
                            search-dn="ou=People,dc=infinispan,dc=org">
            <attribute-mapping>
              <attribute from="cn" to="Roles"
                         filter="(&amp;(objectClass=groupOfNames)(member={1}))"
                         filter-dn="ou=Roles,dc=infinispan,dc=org"/>
            </attribute-mapping>
            <user-password-mapper from="userPassword"/>
          </identity-mapping>
        </ldap-realm>
      </security-realm>
    </security-realms>
  </security>
</server>

JSON

{
  "server": {
    "security": {
      "security-realms": [{
        "name": "LdapRealm",
        "ldap-realm": {
          "principal": "uid=admin,ou=People,dc=infinispan,dc=org",
          "url": "ldap://${org.infinispan.test.host.address}:10389",
          "credential": "strongPassword",
          "name-rewriter": {
            "regex-principal-transformer": {
              "pattern": "(.*)@INFINISPAN\\.ORG",
              "replacement": "$1"
            }
          },
          "identity-mapping": {
            "rdn-identifier": "uid",
            "search-dn": "ou=People,dc=infinispan,dc=org",
            "attribute-mapping": {
              "attribute": {
                "filter": "(&(objectClass=groupOfNames)(member={1}))",
                "filter-dn": "ou=Roles,dc=infinispan,dc=org",
                "from": "cn",
                "to": "Roles"
              }
            },
            "user-password-mapper": {
              "from": "userPassword"
            }
          }
        }
      }]
    }
  }
}

YAML

server:
  security:
    securityRealms:
      - name: "LdapRealm"
        ldapRealm:
          principal: "uid=admin,ou=People,dc=infinispan,dc=org"
          url: "ldap://${org.infinispan.test.host.address}:10389"
          credential: "strongPassword"
          nameRewriter:
            regexPrincipalTransformer:
              pattern: (.*)@INFINISPAN\.ORG
              replacement: "$1"
          identityMapping:
            rdnIdentifier: "uid"
            searchDn: "ou=People,dc=infinispan,dc=org"
            attributeMapping:
              attribute:
                filter: "(&(objectClass=groupOfNames)(member={1}))"
                filterDn: "ou=Roles,dc=infinispan,dc=org"
                from: "cn"
                to: "Roles"
            userPasswordMapper:
              from: "userPassword"