1

我正在尝试更加熟悉 WildFly 安全配置,并且在理解服务器端配置(如 和 )中的选项之间的关系时遇到了一些standalone.xml问题。web.xmljboss-web.xml

我有几个关于这个基于 Wildfly servlet 安全示例的配置的问题。我已经尝试过了,它可以工作,但有几件事对我来说还不清楚。

  1. 我如何看待身份验证的基本类型是在服务器端的身份验证工厂和应用程序端的 web.xml 中定义的。哪个优先。是不是必须申报两次。
  2. 领域“RealmUsersRoles”的名称。它是否意味着服务器端配置和 web.xml 中的同一实体
  3. 在理想情况下,我想了解此配置中提到的所有安全实体之间的互连。

这是 JBoss CLI 配置脚本

# 1. Add the JDBC security realm creation
/subsystem=elytron/jdbc-realm=servlet-security-jdbc-realm:add(\
principal-query=[\
{sql="SELECT PASSWORD FROM USERS WHERE USERNAME = ?", data-source="MySQLDS", clear-password-mapper={password-index=1}},\
{sql="SELECT R.NAME, 'Roles' FROM USERS_ROLES UR INNER JOIN ROLES R ON R.ID = UR.ROLE_ID INNER JOIN USERS U ON U.ID = UR.USER_ID WHERE U.USERNAME = ?", data-source="MySQLDS", attribute-mapping=[{index=1, to=roles}]}])

# 2. Add a simple role decoder for the "roles" attribute mapping
/subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=roles)

# 3. Configure the servlet-security-quickstart security domain
/subsystem=elytron/security-domain=servlet-security-quickstart-sd:add(\
default-realm=servlet-security-jdbc-realm, \
realms=[{realm=servlet-security-jdbc-realm, role-decoder=from-roles-attribute}], \
permission-mapper=default-permission-mapper)

# 4. Configure the HTTP Authentication Factory
/subsystem=elytron/http-authentication-factory=servlet-security-quickstart-http-auth:add(\
http-server-mechanism-factory=global,\
security-domain=servlet-security-quickstart-sd,\
mechanism-configurations=[{mechanism-name=BASIC,mechanism-realm-configurations=[{realm-name=RealmUsersRoles}]}])

# 5. Configure Undertow's application security domain
/subsystem=undertow/application-security-domain=servlet-security-quickstart:add(\
http-authentication-factory=servlet-security-quickstart-http-auth)

web.xml

<?xml version="1.0"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>RealmUsersRoles</realm-name>
    </login-config>
</web-app>

jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <security-domain>servlet-security-quickstart</security-domain>
</jboss-web>

这是我用作基础的 Wildfly 示例的链接https://github.com/wildfly/quickstart/tree/master/servlet-security

这是我基于此示例的所有代码,并进行了一些修改https://github.com/usharik/GeekBrainsJavaEE/tree/master/lesson8-security

4

1 回答 1

2
  1. 您需要在服务器配置中配置基本类型的身份验证,而不是在web.xml
  2. 领域的名称并不重要。401 Unauthorized当您获得(WWW-Authenticate标题)时,它仅显示在浏览器中。如果其中配置了组名web.xml,则使用该组名,否则使用服务器配置中的组名。
于 2019-04-03T20:27:44.633 回答