1.3. 创建分布式域
1.3.1. Elytron 中的分布式域 复制链接链接已复制到粘贴板!
有了分布式域,您可以通过引用现有的安全域来跨不同的身份存储进行搜索。获取的身份用于身份验证和授权。Elytron 在分布式域中跟俊您在 distributed-realm
资源中定义的顺序调用安全域。
distributed-realm
配置示例
/subsystem=elytron/distributed-realm=exampleSecurityRealm:add(realms=[exampleLDAPRealm,exampleFilesystemRealm])
/subsystem=elytron/distributed-realm=exampleSecurityRealm:add(realms=[exampleLDAPRealm,exampleFilesystemRealm])
在示例中,配置的 distributed-realm
引用两个现有的安全域:"exampleLDAPRealm",它是一个 LDAP 域,以及"exampleFilesystemRealm",它是一个文件系统域。Elytron 按如下顺序搜索引用的安全域:
- Elytron 首先搜索 LDAP 域以匹配身份。
- 如果 Elytron 找到匹配项,则身份验证会成功。
- 如果 Elytron 没有找到匹配项,它会搜索文件系统域。
默认情况下,如果在匹配身份前与任何身份存储的连接失败,则身份验证会失败,但有一个例外的 RealmUnavailableException
,且不会搜索更多域。您可以通过将属性 ignore-unavailable-realms
设置为 true
来更改此行为。当 ignore-unavailable-realms
设为 true
时与身份存储的连接失败,Elytron 会继续搜索剩余的域。
当 ignore-unavailable-realms
设置为 true
时,emit-events
默认被设置为 true
,因此当任何查询的域不可用时会发出 SecurityEvent
。您可以通过将 emit-events
设置为 false
来关闭此关闭。
1.3.2. 分布式域所需的创建安全域的示例 复制链接链接已复制到粘贴板!
以下示例演示了创建 ldap-realm
和 filesystem-realm
。您可以在 distributed-realm
中引用这些安全域。
1.3.2.1. 在 Elytron 示例中创建一个 ldap-realm 复制链接链接已复制到粘贴板!
创建由轻量级目录访问协议(LDAP)身份存储支持的 Elytron 安全域,来保护 JBoss EAP 服务器接口或在服务器上部署的应用程序。
对于此过程中的示例,使用了以下 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"}) {"outcome" => "success"}
/subsystem=elytron/dir-context=exampleDirContext:add(url="ldap://10.88.0.2",principal="cn=admin,dc=wildfly,dc=org",credential-reference={clear-text="secret"}) {"outcome" => "success"}
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=exampleLDAPRealm: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"}]}) {"outcome" => "success"}
/subsystem=elytron/ldap-realm=exampleLDAPRealm: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"}]}) {"outcome" => "success"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,您可以使用这个域来创建安全域,或与 failover-realm
、distributed-realm
或 aggregate-realm
中的其它域合并。您还可以为 ldap-realm
配置一个 caching-realm
来缓存查找的结果,并提高性能。
1.3.2.2. 在 Elytron 示例中创建一个 filesystem-realm 复制链接链接已复制到粘贴板!
创建一个由基于文件系统的身份存储支持的 Elytron 安全域,来保护 JBoss EAP 服务器接口或在服务器上部署的应用程序。
先决条件
- JBoss EAP 正在运行。
流程
在 Elytron 中创建一个
filesystem-realm
。语法
/subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add(path=<file_path>)
/subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add(path=<file_path>)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add(path=fs-realm-users,relative-to=jboss.server.config.dir) {"outcome" => "success"}
/subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add(path=fs-realm-users,relative-to=jboss.server.config.dir) {"outcome" => "success"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将用户添加到域,并配置用户的角色。
添加用户。
语法
/subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add-identity(identity=<user_name>)
/subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add-identity(identity=<user_name>)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add-identity(identity=user2) {"outcome" => "success"}
/subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add-identity(identity=user2) {"outcome" => "success"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 设置用户的密码。
语法
/subsystem=elytron/filesystem-realm=<filesystem_realm_name>:set-password(identity=<user_name>, clear={password=<password>})
/subsystem=elytron/filesystem-realm=<filesystem_realm_name>:set-password(identity=<user_name>, clear={password=<password>})
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/filesystem-realm=exampleFileSystemRealm:set-password(identity=user2, clear={password="passwordUser2"}) {"outcome" => "success"}
/subsystem=elytron/filesystem-realm=exampleFileSystemRealm:set-password(identity=user2, clear={password="passwordUser2"}) {"outcome" => "success"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 为用户设置角色。
语法
/subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add-identity-attribute(identity=<user_name>, name=<roles_attribute_name>, value=[<role_1>,<role_N>])
/subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add-identity-attribute(identity=<user_name>, name=<roles_attribute_name>, value=[<role_1>,<role_N>])
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add-identity-attribute(identity=user2, name=Roles, value=["Admin","Guest"]) {"outcome" => "success"}
/subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add-identity-attribute(identity=user2, name=Roles, value=["Admin","Guest"]) {"outcome" => "success"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,您可以使用这个域来创建一个安全域,或与 failover-realm
、distributed-realm
或 aggregate-realm
中的另一个域合并。
1.3.3. 在 Elytron 中创建一个 distributed-realm 复制链接链接已复制到粘贴板!
在 Elytron 中创建一个 distributed-realm
,以引用现有的安全域来搜索身份。使用 distributed-realm
创建一个安全域,来向管理界面或部署在服务器上的应用程序添加身份验证和授权。
先决条件
- JBoss EAP 正在运行。
-
您已创建了要在
distributed-realm
中引用的域。
流程
创建一个引用现有安全域的
distributed-realm
。语法
/subsystem=elytron/distributed-realm=<distributed_realm_name>:add(realms=[<security_realm_1>, <security_realm_2>, ..., <security_realm_N>])
/subsystem=elytron/distributed-realm=<distributed_realm_name>:add(realms=[<security_realm_1>, <security_realm_2>, ..., <security_realm_N>])
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/distributed-realm=exampleSecurityRealm:add(realms=[exampleLDAPRealm, exampleFileSystemRealm]) {"outcome" => "success"}
/subsystem=elytron/distributed-realm=exampleSecurityRealm:add(realms=[exampleLDAPRealm, exampleFileSystemRealm]) {"outcome" => "success"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建一个角色解码器,来将属性映射到角色。
语法
/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) {"outcome" => "success"}
/subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=Roles) {"outcome" => "success"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建一个引用
distributed-realm
的安全域,以及角色解码器。语法
/subsystem=elytron/security-domain=<security_domain_name>:add(realms=[{realm=<distributed_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=<distributed_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(default-realm=exampleSecurityRealm,permission-mapper=default-permission-mapper,realms=[{realm=exampleSecurityRealm,role-decoder="from-roles-attribute"}]) {"outcome" => "success"}
/subsystem=elytron/security-domain=exampleSecurityDomain:add(default-realm=exampleSecurityRealm,permission-mapper=default-permission-mapper,realms=[{realm=exampleSecurityRealm,role-decoder="from-roles-attribute"}]) {"outcome" => "success"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,您可以使用创建的安全域来向管理界面和应用程序添加身份验证和授权。如需更多信息,请参阅 保护管理界面和应用程序。