2.2. 使用基于文件的属性身份存储配置身份验证
创建属性文件:
您必须创建两个属性文件:一个用于将用户映射到密码,另一个将用户映射到角色。通常,这些文件位于
jboss.server.config.dir目录中,并遵循命名约定*-users.properties和*-roles.properties,但也可以使用其他位置和名称。*-users.properties文件还必须包含对properties-realm的引用,您要在下一步中创建:#$REALM_NAME=YOUR_PROPERTIES_REALM_NAME$密码文件示例:example-users.properties
#$REALM_NAME=examplePropRealm$ user1=password123 user2=password123
#$REALM_NAME=examplePropRealm$ user1=password123 user2=password123Copy to Clipboard Copied! Toggle word wrap Toggle overflow 角色文件示例:example-roles.properties
user1=Admin user2=Guest
user1=Admin user2=GuestCopy to Clipboard Copied! Toggle word wrap Toggle overflow 在 JBoss EAP
中配置 properties-realm:/subsystem=elytron/properties-realm=examplePropRealm:add(groups-attribute=groups,groups-properties={path=example-roles.properties,relative-to=jboss.server.config.dir},users-properties={path=example-users.properties,relative-to=jboss.server.config.dir,plain-text=true})/subsystem=elytron/properties-realm=examplePropRealm:add(groups-attribute=groups,groups-properties={path=example-roles.properties,relative-to=jboss.server.config.dir},users-properties={path=example-users.properties,relative-to=jboss.server.config.dir,plain-text=true})Copy to Clipboard Copied! Toggle word wrap Toggle overflow properties-realm的名称为examplePropRealm,它用于example-users.properties文件中的上一步中。此外,如果您的属性文件位于jboss.server.config.dir之外,您必须相应地更改路径和相对值。配置
security-domain:/subsystem=elytron/security-domain=exampleSD:add(realms=[{realm=examplePropRealm,role-decoder=groups-to-roles}],default-realm=examplePropRealm,permission-mapper=default-permission-mapper)/subsystem=elytron/security-domain=exampleSD:add(realms=[{realm=examplePropRealm,role-decoder=groups-to-roles}],default-realm=examplePropRealm,permission-mapper=default-permission-mapper)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
undertow子系统中配置application-security-domain:/subsystem=undertow/application-security-domain=exampleApplicationDomain:add(security-domain=exampleSD)
/subsystem=undertow/application-security-domain=exampleApplicationDomain:add(security-domain=exampleSD)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意可以通过导航到 Configuration
Subsystems Web(Under tow)→ Application Security Domain,使用管理控制台配置 undertow 子系统中的application-security-domain。配置应用程序的
web.xml和jboss-web.xml:您的
web.xml和jboss-web.xml必须更新为使用您在 JBoss EAP 中配置的application-security-domain。例如,将 Web 应用程序配置为使用 Elytron 或传统安全性进行身份验证。
您的应用现在使用基于文件的属性身份存储进行身份验证。
属性文件仅在服务器启动时读取。在服务器启动后添加的任何用户(手动或使用 add-user 脚本)都需要重新加载服务器。此重新加载通过从管理 CLI 运行 reload 命令来完成。
reload
reload