第 1 章 配置身份存储


1.1. 创建聚合域

1.1.1. Elytron 中的聚合域

有了聚合域 aggregate-realm ,您可以对身份验证以及另一个安全域使用安全域,或对 Elytron 中的授权使用多个安全域的聚合。

例如,您可以将 aggregate-realm 配置为对身份验证使用 ldap-realm ,对授权使用 filesystem-realmldap-realm 的聚合。

在配置了多个授权域的聚合域中创建的一个身份,如下所示:

  • 来自每个授权域的属性值被加载。
  • 如果属性在多个授权域中定义,则将使用该属性第一次出现的值。

以下示例演示了当多个授权域包含同一身份属性的定义时身份是如何创建的。

聚合域配置示例

/subsystem=elytron/aggregate-realm=exampleSecurityRealm:add(authentication-realm=exampleLDAPRealm,authorization-realms=[exampleLDAPRealm,exampleFileSystemRealm])
Copy to Clipboard Toggle word wrap

在示例中,配置的 aggregate-realm 引用两个现有的安全域:"exampleLDAPRealm",它是一个 LDAP 域,以及"exampleFilesystemRealm",它是文件系统域。

  • 从 LDAP 域中获取的属性值:

    mail: administrator@example.com
    telephoneNumber: 0000 0000
    Copy to Clipboard Toggle word wrap
  • 从文件系统域中获取的属性值:

    mail: user@example.com
    website: http://www.example.com/
    Copy to Clipboard Toggle word wrap

从聚合域中获取生成的身份:

mail: administrator@example.com
telephoneNumber: 0000 0000
website: http://www.example.com/
Copy to Clipboard Toggle word wrap

示例 aggregate-realm 使用 LDAP 域中定义的属性 mail 的值,因为 LDAP 域在文件系统域之前被引用。

1.1.2. 创建聚合域所需的安全域的示例

以下示例演示了创建 ldap-realmfilesystem-realm。您可以在 aggregate-realm 中引用这些安全域。

1.1.2.1. 在 Elytron 示例中创建一个 ldap-realm

创建由轻量级目录访问协议(LDAP)身份存储支持的 Elytron 安全域,来保护 JBoss EAP 服务器接口或在服务器上部署的应用程序。

对于此过程中的示例,使用了以下 LDAP 数据交换格式(LDIF):

dn: ou=Users,dc=wildfly,dc=org
objectClass: organizationalUnit
objectClass: top
ou: Users

dn: uid=user1,ou=Users,dc=wildfly,dc=org
objectClass: top
objectClass: person
objectClass: inetOrgPerson
cn: user1
sn: user1
uid: user1
userPassword: passwordUser1
mail: administrator@example.com
telephoneNumber: 0000 0000

dn: ou=Roles,dc=wildfly,dc=org
objectclass: top
objectclass: organizationalUnit
ou: Roles

dn: cn=Admin,ou=Roles,dc=wildfly,dc=org
objectClass: top
objectClass: groupOfNames
cn: Admin
member: uid=user1,ou=Users,dc=wildfly,dc=org
Copy to Clipboard Toggle word wrap

用于示例的 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 正在运行。

流程

  1. 配置一个提供 URL 的目录上下文,以及用于连接到 LDAP 服务器的主体。

    /subsystem=elytron/dir-context=<dir_context_name>:add(url="<LDAP_URL>",principal="<principal_distinguished_name>",credential-reference=<credential_reference>)
    Copy to Clipboard Toggle word wrap

    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"}
    Copy to Clipboard Toggle word wrap

  2. 创建一个引用目录上下文的 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>"}]})
    Copy to Clipboard Toggle word wrap

    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"},{from="mail",to="mail"},{from="telephoneNumber",to="telephoneNumber"}]})
    {"outcome" => "success"}
    Copy to Clipboard Toggle word wrap

现在,您可以使用这个域来创建一个安全域,或与 failover-realmdistributed-realmaggregate-realm 中的另一个域合并。

1.1.2.2. 在 Elytron 示例中创建一个 filesystem-realm

创建一个由基于文件系统的身份存储支持的 Elytron 安全域,来保护 JBoss EAP 服务器接口或在服务器上部署的应用程序。

先决条件

  • JBoss EAP 正在运行。

流程

  1. 在 Elytron 中创建一个 filesystem-realm

    语法

    /subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add(path=<file_path>)
    Copy to Clipboard Toggle word wrap

    Example

    /subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add(path=fs-realm-users,relative-to=jboss.server.config.dir)
    {"outcome" => "success"}
    Copy to Clipboard Toggle word wrap

  2. 将用户添加到域,并配置用户的角色。

    1. 添加用户。

      语法

      /subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add-identity(identity=<user_name>)
      Copy to Clipboard Toggle word wrap

      Example

      /subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add-identity(identity=user1)
      {"outcome" => "success"}
      Copy to Clipboard Toggle word wrap

    2. 为用户设置角色。

      语法

      /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 Toggle word wrap

      Example

      /subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add-identity-attribute(identity=user1, name=Roles, value=["Admin","Guest"])
      {"outcome" => "success"}
      Copy to Clipboard Toggle word wrap

    3. 设置用户的属性。

      语法

      /subsystem=elytron/filesystem-realm=<filesystem_realm_name>:add-identity-attribute(identity=<user_name>,name=<attribute_name>, value=[<attribute_value>])
      Copy to Clipboard Toggle word wrap

      Example

      /subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add-identity-attribute(identity=user1, name=mail, value=["user@example.com"])
      /subsystem=elytron/filesystem-realm=exampleFileSystemRealm:add-identity-attribute(identity=user1, name=website, value=["http://www.example.com/"])
      Copy to Clipboard Toggle word wrap

现在,您可以使用这个域来创建一个安全域,或与 failover-realmdistributed-realmaggregate-realm 中的另一个域合并。

1.1.3. 在 Elytron 中创建一个 aggregate-realm

在 Elytron 中创建一个 aggregate-realm,它使用一个安全域进行身份验证,使用多个安全域的聚合进行授权。使用 aggregate-realm 创建一个安全域来添加身份验证和授权,以管理界面和部署的应用程序。

先决条件

  • JBoss EAP 正在运行。
  • 您已创建了一个要从聚合域中引用的域。

流程

  1. 从现有的安全域创建一个 aggregate-realm

    语法

    /subsystem=elytron/aggregate-realm=<aggregate_realm_name>:add(authentication-realm=<security_realm_for_authentication>, authorization-realms=[<security_realm_for_authorization_1>,<security_realm_for_authorization_2>,...,<security_realm_for_authorization_N>])
    Copy to Clipboard Toggle word wrap

    Example

    /subsystem=elytron/aggregate-realm=exampleSecurityRealm:add(authentication-realm=exampleLDAPRealm,authorization-realms=[exampleLDAPRealm,exampleFileSystemRealm])
    {"outcome" => "success"}
    Copy to Clipboard Toggle word wrap

  2. 创建一个角色解码器,来将属性映射到角色。

    语法

    /subsystem=elytron/simple-role-decoder=<role_decoder_name>:add(attribute=<attribute>)
    Copy to Clipboard Toggle word wrap

    Example

    /subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=Roles)
    {"outcome" => "success"}
    Copy to Clipboard Toggle word wrap

  3. 创建一个引用 aggregate-realm 和角色解码器的安全域。

    语法

    /subsystem=elytron/security-domain=<security_domain_name>:add(default-realm=<aggregate_realm_name>,permission-mapper=default-permission-mapper,realms=[{realm=<aggregate_realm_name>,role-decoder="<role_decoder_name>"}])
    Copy to Clipboard Toggle word wrap

    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"}
    Copy to Clipboard Toggle word wrap

现在,您可以使用创建的安全域来向管理界面和应用程序添加身份验证和授权。如需更多信息,请参阅 保护管理界面和应用程序

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat