【问题标题】:WildFly and Java EE security configuration with Elytron使用 Elytron 的 WildFly 和 Java EE 安全配置
【发布时间】:2019-03-22 10:59:40
【问题描述】:

我正在尝试更加熟悉 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

【问题讨论】:

    标签: java security jakarta-ee wildfly elytron


    【解决方案1】:
    1. 您需要在服务器配置中配置基本类型的身份验证,而不是在web.xml
    2. 领域的名称并不重要。当您获得401 UnauthorizedWWW-Authenticate 标头)时,它只会显示在浏览器中。如果在web.xml 中配置了组名,则使用该组名,否则使用服务器配置中的组名。

    【讨论】:

    • 我是如何从一些实验中发现的。在服务器端,我们正在定义我们在此服务器上运行的应用程序应该可能的所有身份验证方法。在 web.xml 中,我们选择要在此应用程序中使用的确切方法。如果我在服务器配置蚂蚁中只有 BASIC 身份验证,请尝试在应用程序中使用其他身份验证,我会收到错误消息。可能是我在这里的某个地方错了。计划重新检查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 1970-01-01
    • 2017-06-20
    • 2020-07-15
    • 2015-05-16
    • 2019-12-31
    相关资源
    最近更新 更多