7.3. 迁移身份验证配置
7.3.1. 将基于属性的身份验证和授权迁移到 Elytron 复制链接链接已复制到粘贴板!
7.3.1.1. 将基于 PicketBox Properties 的配置迁移到 Elytron 复制链接链接已复制到粘贴板!
这部分论述了如何将基于 PicketBox 属性的身份验证迁移到 Elytron。您可以选择将 PicketBox 安全域公开到 Elytron,或者完全迁移基于属性的身份验证配置以使用 Elytron,从而部分迁移 基于属性的身份验证配置。
以下流程假定您计划迁移的已部署的 Web 应用已配置为需要基于表单的身份验证。应用引用 PicketBox 安全域,并使用 UsersRolesLoginModule
从 example -users.properties
和 example-roles.properties
文件中加载用户信息。这些示例还假定安全性域在传统 安全
子系统中通过下列管理 CLI 命令定义:
示例:基于 PicketBox Properties 的配置命令
/subsystem=security/security-domain=application-security:add /subsystem=security/security-domain=application-security/authentication=classic:add(login-modules=[{code=UsersRoles, flag=Required, module-options={usersProperties=file://${jboss.server.config.dir}/example-users.properties, rolesProperties=file://${jboss.server.config.dir}/example-roles.properties}}])
/subsystem=security/security-domain=application-security:add
/subsystem=security/security-domain=application-security/authentication=classic:add(login-modules=[{code=UsersRoles, flag=Required, module-options={usersProperties=file://${jboss.server.config.dir}/example-users.properties, rolesProperties=file://${jboss.server.config.dir}/example-roles.properties}}])
这将产生以下服务器配置:
示例:基于 PicketBox Properties 的安全域配置
选择以下迁移选项之一:
通过将 PicketBox 安全域扩展到 Elytron 来部分迁移
您可以将 PicketBox 安全域公开为 Elytron 安全域,以便它可以连接到 Elytron 配置中;但是,这样做会创建依赖于旧 安全性
子系统的依赖。如果您仅迁移基于属性的身份验证,建议您 将应用完全迁移到 Elytron,以避免对旧 安全
子系统造成不必要的依赖。但是,当无法完全迁移应用程序以使用 Elytron 时,部分迁移可能是一个中间解决方案。
按照以下步骤,将现有的 PicketBox 安全域配置添加为 Elytron 安全域。
添加到传统
security
子系统内 Elytron 安全域的映射。/subsystem=security/elytron-realm=application-security:add(legacy-jaas-config=application-security)
/subsystem=security/elytron-realm=application-security:add(legacy-jaas-config=application-security)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这会在服务器配置文件
的安全
子系统中配置下列 Elytron 安全域:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
elytron
子系统中定义一个安全性域,以引用导出的安全域。/subsystem=elytron/security-domain=application-security:add(realms=[{realm=application-security}], default-realm=application-security, permission-mapper=default-permission-mapper)
/subsystem=elytron/security-domain=application-security:add(realms=[{realm=application-security}], default-realm=application-security, permission-mapper=default-permission-mapper)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这会在服务器配置文件中产生以下
elytron
子系统配置:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
undertow
子系统中,将部署所引用的应用安全域映射到新定义的安全域。/subsystem=undertow/application-security-domain=application-security:add(security-domain=application-security)
/subsystem=undertow/application-security-domain=application-security:add(security-domain=application-security)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这会在服务器配置文件中产生以下
undertow
子系统配置:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意- 如果应用在此配置之前已部署,您必须重新加载服务器或重新部署应用以使新的应用安全域映射生效。
- 在当前的 Web service-Elytron 集成中,为保护 Web 服务端点而指定的安全域名称,Elytron 安全域名必须相同。
使用以下管理 CLI 命令,验证映射是否已应用到部署:本例中使用的部署是
HelloWorld.war
。此命令的输出显示此部署正在引用 Elytron 映射。Copy to Clipboard Copied! Toggle word wrap Toggle overflow
在此阶段,之前定义的安全域用于其 LoginModule
配置,但它由接管身份验证的 Elytron 组件封装。
在 Elytron 中完全迁移基于属性的身份验证
按照以下步骤,将基于 PicketBox 属性的身份验证完全迁移到 Elytron。此流程假设您从本节介绍中所述的传统配置开始,但没有 ??? 迁移到部分迁移的解决方案。完成此过程后,传统 安全性
子系统中存在的任何安全域定义都将完全独立于 Elytron 配置。
在
elytron
子系统中定义一个新的安全域,以引用 PicketBox 属性文件。/subsystem=elytron/properties-realm=application-properties:add(users-properties={path=example-users.properties, relative-to=jboss.server.config.dir, plain-text=true, digest-realm-name="Application Security"}, groups-properties={path=example-roles.properties, relative-to=jboss.server.config.dir}, groups-attribute=Roles)
/subsystem=elytron/properties-realm=application-properties:add(users-properties={path=example-users.properties, relative-to=jboss.server.config.dir, plain-text=true, digest-realm-name="Application Security"}, groups-properties={path=example-roles.properties, relative-to=jboss.server.config.dir}, groups-attribute=Roles)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
elytron
子系统中定义安全域子系统。/subsystem=elytron/security-domain=application-security:add(realms=[{realm=application-properties}], default-realm=application-properties, permission-mapper=default-permission-mapper)
/subsystem=elytron/security-domain=application-security:add(realms=[{realm=application-properties}], default-realm=application-properties, permission-mapper=default-permission-mapper)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这会在服务器配置文件中产生以下
elytron
子系统配置:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将部署引用的应用安全域映射到
undertow
子系统中新定义的 HTTP 身份验证工厂。/subsystem=undertow/application-security-domain=application-security:add(security-domain=application-security)
/subsystem=undertow/application-security-domain=application-security:add(security-domain=application-security)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这会在服务器配置文件中产生以下
undertow
子系统配置:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意在当前的 Web service-Elytron 集成中,为保护 Web 服务端点而指定的安全域名称,Elytron 安全域名必须相同。
- 您必须重新加载服务器或重新部署应用,才能使新应用安全域映射生效。
现在,身份验证已配置为等同于 PicketBox 配置,但 Elytron 组件现在只用于身份验证。
7.3.1.2. 将基于传统属性的配置迁移到 Elytron 复制链接链接已复制到粘贴板!
本节论述了如何将传统安全域从属性文件加载用户、密码和组信息到 Elytron。这种类型的传统安全域通常用于保护管理接口或远程连接器的安全。
这些示例假定使用以下管理 CLI 命令定义传统安全域:
示例:传统安全域命令
/core-service=management/security-realm=ApplicationSecurity:add /core-service=management/security-realm=ApplicationSecurity/authentication=properties:add(relative-to=jboss.server.config.dir, path=example-users.properties, plain-text=true) /core-service=management/security-realm=ApplicationSecurity/authorization=properties:add(relative-to=jboss.server.config.dir, path=example-roles.properties)
/core-service=management/security-realm=ApplicationSecurity:add
/core-service=management/security-realm=ApplicationSecurity/authentication=properties:add(relative-to=jboss.server.config.dir, path=example-users.properties, plain-text=true)
/core-service=management/security-realm=ApplicationSecurity/authorization=properties:add(relative-to=jboss.server.config.dir, path=example-roles.properties)
这将产生以下服务器配置:
示例:传统安全域配置
为应用服务器添加 Elytron 安全性的动机之一是允许在整个服务器使用一致的安全解决方案。将基于属性的传统安全域迁移到 Elytron 的初始步骤与用于将基于 PicketBox 属性的身份验证迁移到 Elytron 的初始步骤类似。按照以下步骤将基于属性的传统安全域迁移到 Elytron。
在
elytron
子系统中定义一个新的安全域,以引用这些属性文件。/subsystem=elytron/properties-realm=application-properties:add(users-properties={path=example-users.properties, relative-to=jboss.server.config.dir, plain-text=true, digest-realm-name="Application Security"}, groups-properties={path=example-roles.properties, relative-to=jboss.server.config.dir}, groups-attribute=Roles)
/subsystem=elytron/properties-realm=application-properties:add(users-properties={path=example-users.properties, relative-to=jboss.server.config.dir, plain-text=true, digest-realm-name="Application Security"}, groups-properties={path=example-roles.properties, relative-to=jboss.server.config.dir}, groups-attribute=Roles)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
elytron
子系统中定义安全域子系统。/subsystem=elytron/security-domain=application-security:add(realms=[{realm=application-properties}], default-realm=application-properties, permission-mapper=default-permission-mapper)
/subsystem=elytron/security-domain=application-security:add(realms=[{realm=application-properties}], default-realm=application-properties, permission-mapper=default-permission-mapper)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这将产生以下 Elytron 配置:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 定义
sasl-authentication-factory
,以便传统安全域也可用于简单身份验证安全层(SASL)身份验证。/subsystem=elytron/sasl-authentication-factory=application-security-sasl:add(sasl-server-factory=elytron, security-domain=application-security, mechanism-configurations=[{mechanism-name=PLAIN}])
/subsystem=elytron/sasl-authentication-factory=application-security-sasl:add(sasl-server-factory=elytron, security-domain=application-security, mechanism-configurations=[{mechanism-name=PLAIN}])
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这将产生以下 Elytron 配置:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 配置用于 SASL 身份验证的远程连接器,并移除与传统安全域的关联。
/subsystem=remoting/http-connector=http-remoting-connector:write-attribute(name=sasl-authentication-factory, value=application-security-sasl) /subsystem=remoting/http-connector=http-remoting-connector:undefine-attribute(name=security-realm)
/subsystem=remoting/http-connector=http-remoting-connector:write-attribute(name=sasl-authentication-factory, value=application-security-sasl) /subsystem=remoting/http-connector=http-remoting-connector:undefine-attribute(name=security-realm)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这会在服务器配置文件
的远程子系统中产生以下配置
:<subsystem xmlns="urn:jboss:domain:remoting:4.0"> ... <http-connector name="http-remoting-connector" connector-ref="default" sasl-authentication-factory="application-security-sasl"/> </subsystem>
<subsystem xmlns="urn:jboss:domain:remoting:4.0"> ... <http-connector name="http-remoting-connector" connector-ref="default" sasl-authentication-factory="application-security-sasl"/> </subsystem>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 添加两个身份验证工厂,并删除传统的安全域引用,从而通过 Elytron 保护
http-interface
。/core-service=management/management-interface=http-interface:write-attribute(name=http-authentication-factory, value=application-security-http) /core-service=management/management-interface=http-interface:write-attribute(name=http-upgrade.sasl-authentication-factory, value=application-security-sasl) /core-service=management/management-interface=http-interface:undefine-attribute(name=security-realm)
/core-service=management/management-interface=http-interface:write-attribute(name=http-authentication-factory, value=application-security-http) /core-service=management/management-interface=http-interface:write-attribute(name=http-upgrade.sasl-authentication-factory, value=application-security-sasl) /core-service=management/management-interface=http-interface:undefine-attribute(name=security-realm)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 这将产生以下配置:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意您应该选择比这些示例中用于保护管理接口的名称更合适的名称。
旧基于属性的配置迁移到 Elytron 现已完成。