1.3. 创建一个 LDAP 域
1.3.1. Elytron 中的 LDAP 域 复制链接链接已复制到粘贴板!
Elytron 中的轻量级目录访问协议(LDAP)域 ldap-realm 是一个可用于加载 LDAP 身份存储中身份的安全域。
以下示例演示了 LDAP 中的身份如何与 JBoss EAP 中的 Elytron 身份进行映射。
LDAP 数据交换格式(LDIF)文件的示例
创建 LDAP 域的命令示例
/subsystem=elytron/dir-context=exampleDirContext:add(url="ldap://10.88.0.2",principal="cn=admin,dc=wildfly,dc=org",credential-reference={clear-text="secret"})
/subsystem=elytron/ldap-realm=exampleSecurityRealm:add(dir-context=exampleDirContext,identity-mapping={search-base-dn="ou=Users,dc=wildfly,dc=org",rdn-identifier="uid",user-password-mapper={from="userPassword"},attribute-mapping=[{filter-base-dn="ou=Roles,dc=wildfly,dc=org",filter="(&(objectClass=groupOfNames)(member={1}))",from="cn",to="Roles"}]})
/subsystem=elytron/dir-context=exampleDirContext:add(url="ldap://10.88.0.2",principal="cn=admin,dc=wildfly,dc=org",credential-reference={clear-text="secret"})
/subsystem=elytron/ldap-realm=exampleSecurityRealm:add(dir-context=exampleDirContext,identity-mapping={search-base-dn="ou=Users,dc=wildfly,dc=org",rdn-identifier="uid",user-password-mapper={from="userPassword"},attribute-mapping=[{filter-base-dn="ou=Roles,dc=wildfly,dc=org",filter="(&(objectClass=groupOfNames)(member={1}))",from="cn",to="Roles"}]})
命令会产生以下配置:
- 1
- realm 定义。
-
name是ldap-realm域名。 -
dir-context是连接到 LDAP 服务器的配置。
-
- 2
- 定义身份是如何映射的。
rdn-identifier是主体可分辨名称(DN)的相对可分辩名称(DN),用于从 LDAP 条目获取主体的名称。在示例 LDIF 中,uid配置为代表来自基础DN=ou=Users,dc=wildfly,dc=org的主体名称。search-base-dn是用于搜索身份的基础 DN。在示例 LDIF 中,它被定义为dn: ou=Users,dc=wildfly,dc=org。
- 3
- 定义 LDAP 属性到身份的属性的映射。
- 4
- 配置如何将特定的 LDAP 属性映射为 Elytron 身份属性。
-
from是要映射的 LDAP 属性。如果没有定义,则使用条目的 DN。 -
to是从 LDAP 属性映射的身份属性的名称。如果没有提供,则属性的名称与from中定义的属性名称相同。如果from也未定义,则使用条目的 DN。 filter是一个过滤器,用于获取特定属性的值。字符串 '{0}' 被 username 替换, '{1}' 被用户身份 DN 替换。-
objectClass是要使用的 LDAP 对象类。在示例 LDIF 中,要使用的对象类定义为groupOfNames。 -
member是要映射的成员。{0}被用户名替换,{1}被用户身份 DN 替换。在这个示例中,{1}用于将member映射为user1。
-
filter-base-dn是应该应用过滤器的上下文的名称。示例过滤器的结果是用户
user1使用Admin角色进行映射。
-
- 5
user-password-mapper定义从中获取身份密码的 LDAP 属性。在示例中,它被配置为userPassword,它在 LDIF 中被定义为userPassword1。
1.3.2. 在 Elytron 中创建一个 ldap-realm 复制链接链接已复制到粘贴板!
创建一个由轻量级目录访问协议(LDAP)身份存储支持的 Elytron 安全域。使用安全域创建一个安全域,向管理界面或服务器上部署的应用程序添加身份验证和授权。
配置为缓存域的 ldap-realm 不支持活动目录。如需更多信息,请参阅 通过 Elytron 的 JBossEAP CLI 修改 LDAP/AD 用户密码 。
在 elytron 子系统使用 LDAP 服务器执行身份验证的情况,如果该 LDAP 服务器无法访问,JBoss EAP 将返回 500 错误码或内部服务器错误。
为确保使用 LDAP 域保护的管理界面和应用程序可以访问,即使使用故障切换域使 LDAP 服务器变得可用。如需更多信息,请参阅 创建故障转移域。
对于此过程中的示例,使用了以下 LDAP 数据交换格式(LDIF):
用于示例的 LDAP 连接参数如下:
-
LDAP URL
:ldap://10.88.0.2 LDAP admin 密码:
secret您需要此内容来使 Elytron 与 LDAP 服务器连接。
-
LDAP admin 可分辨名称(DN):
(cn=admin,dc=wildfly,dc=org) LDAP 机构:
wildfly如果没有指定机构名称,则默认为
Example Inc。LDAP 域:
wildfly.org这是当平台收到 LDAP 搜索参考时匹配的名称。
先决条件
- 您已配置了一个 LDAP 身份存储。
- JBoss EAP 正在运行。
流程
配置一个提供 URL 的目录上下文,以及用于连接到 LDAP 服务器的主体。
语法
/subsystem=elytron/dir-context=<dir_context_name>:add(url="<LDAP_URL>",principal="<principal_distinguished_name>",credential-reference=<credential_reference>)
/subsystem=elytron/dir-context=<dir_context_name>:add(url="<LDAP_URL>",principal="<principal_distinguished_name>",credential-reference=<credential_reference>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/dir-context=exampleDirContext:add(url="ldap://10.88.0.2",principal="cn=admin,dc=wildfly,dc=org",credential-reference={clear-text="secret"})/subsystem=elytron/dir-context=exampleDirContext:add(url="ldap://10.88.0.2",principal="cn=admin,dc=wildfly,dc=org",credential-reference={clear-text="secret"})Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建一个引用目录上下文的 LDAP 域。指定搜索基础 DN 以及用户的映射方式。
语法
/subsystem=elytron/ldap-realm=<ldap_realm_name>add:(dir-context=<dir_context_name>,identity-mapping=search-base-dn="ou=<organization_unit>,dc=<domain_component>",rdn-identifier="<relative_distinguished_name_identifier>",user-password-mapper={from=<password_attribute_name>},attribute-mapping=[{filter-base-dn="ou=<organization_unit>,dc=<domain_component>",filter="<ldap_filter>",from="<ldap_attribute_name>",to="<identity_attribute_name>"}]})/subsystem=elytron/ldap-realm=<ldap_realm_name>add:(dir-context=<dir_context_name>,identity-mapping=search-base-dn="ou=<organization_unit>,dc=<domain_component>",rdn-identifier="<relative_distinguished_name_identifier>",user-password-mapper={from=<password_attribute_name>},attribute-mapping=[{filter-base-dn="ou=<organization_unit>,dc=<domain_component>",filter="<ldap_filter>",from="<ldap_attribute_name>",to="<identity_attribute_name>"}]})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/ldap-realm=exampleSecurityRealm:add(dir-context=exampleDirContext,identity-mapping={search-base-dn="ou=Users,dc=wildfly,dc=org",rdn-identifier="uid",user-password-mapper={from="userPassword"},attribute-mapping=[{filter-base-dn="ou=Roles,dc=wildfly,dc=org",filter="(&(objectClass=groupOfNames)(member={1}))",from="cn",to="Roles"}]})/subsystem=elytron/ldap-realm=exampleSecurityRealm:add(dir-context=exampleDirContext,identity-mapping={search-base-dn="ou=Users,dc=wildfly,dc=org",rdn-identifier="uid",user-password-mapper={from="userPassword"},attribute-mapping=[{filter-base-dn="ou=Roles,dc=wildfly,dc=org",filter="(&(objectClass=groupOfNames)(member={1}))",from="cn",to="Roles"}]})Copy to Clipboard Copied! Toggle word wrap Toggle overflow 如果您在 LDIF 文件中存储了哈希密码,您可以指定以下属性:
-
hash-encoding:如果密码没有以纯文本存储,则此属性指定密码的字符串格式。默认情况下,它被设置为base64编码,但也支持hex。 -
hash-charset:此属性指定在将密码字符串转换为字节数组时要使用的字符集。默认设为UTF-8。
警告如果引用的 LDAP 服务器在引用中包含了一个循环,则可能会在 JBoss EAP 中导致
java.lang.OutOfMemoryError错误。-
创建一个角色解码器,来将属性映射到角色。
语法
/subsystem=elytron/simple-role-decoder=<role_decoder_name>:add(attribute=<attribute>)
/subsystem=elytron/simple-role-decoder=<role_decoder_name>:add(attribute=<attribute>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=Roles)
/subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=Roles)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建一个引用 LDAP 域和角色解码器的安全域。
语法
/subsystem=elytron/security-domain=<security_domain_name>:add(realms=[{realm=<ldap_realm_name>,role-decoder=<role_decoder_name>}],default-realm=<ldap_realm_name>,permission-mapper=<permission_mapper>)/subsystem=elytron/security-domain=<security_domain_name>:add(realms=[{realm=<ldap_realm_name>,role-decoder=<role_decoder_name>}],default-realm=<ldap_realm_name>,permission-mapper=<permission_mapper>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/security-domain=exampleSecurityDomain:add(realms=[{realm=exampleSecurityRealm,role-decoder=from-roles-attribute}],default-realm=exampleSecurityRealm,permission-mapper=default-permission-mapper)/subsystem=elytron/security-domain=exampleSecurityDomain:add(realms=[{realm=exampleSecurityRealm,role-decoder=from-roles-attribute}],default-realm=exampleSecurityRealm,permission-mapper=default-permission-mapper)Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,您可以使用创建的安全域来向管理界面和应用程序添加身份验证和授权。如需更多信息,请参阅 保护管理界面和应用程序。