Wildfly 安全子系统:从 Legacy 迁移到 Elytron,未找到安全域

Wildfly Security Subsystem: Migrating from Legacy to Elytron, security-domain not found

我正在尝试将一个项目从使用 Legacy Security 迁移到使用 Elytron Security。

直到现在(旧版),身份验证工作所需的全部是在子系统中创建一个安全域 -> 具有正确名称的安全性(“referencesApplicationDomain” ).

我的web.xml:

<web-app ..>
    ...
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>referencesApplicationDomain</realm-name>
    </login-config>
    <security-role>
        <role-name>authenticated</role-name>
    </security-role>
    <security-role>
        <role-name>anonymous</role-name>
    </security-role>
    <security-constraint>
        <web-resource-collection>
            ....
        </web-resource-collection>
    </security-constraint>
        <auth-constraint>
            <role-name>authenticated</role-name>
        </auth-constraint>
    </security-constraint>
...
</web-app>

我的jboss-web.xml:

<jboss-web ...>
    <deny-uncovered-http-methods>false</deny-uncovered-http-methods>
    <context-root>/references</context-root>
    <security-domain>referencesApplicationDomain</security-domain>
</jboss-web>

当然,我们的想法是让我们的应用程序只与 Elytron 一起工作。

但是,问题是我看不到在 Elytron 中创建安全域的位置。

我按照 Wildfly Elytron Documentation 使用 jboss-cli 创建安全域和 http 工厂。

当我签入 jboss-cli 时,我看到安全域已创建。

然而,当我尝试启动 Wildfly 服务器时,出现以下错误:

"WFLYCTL0412: Required services that are not installed:" => [
        "jboss.security.security-domain.referencesApplicationDomain"
    ],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.deployment.unit.\"references-war-1.0.11-SNAPSHOT.war\".component.BranchService.CREATE is missing [jboss.security.security-domain.java:/jaas/referencesApplicationDomain]"
    ]

似乎 jboss 试图在旧的安全子系统而不是 Elytron 中找到安全域。但是我不明白为什么?

小提示:我想使用 ApplicaationRealm,使用 jboss 配置文件中的用户和组。

事实证明,Elytron 不需要它(事实上,它仅适用于 Legacy)。所以解决方案只是从 xml 文件中删除这些:

web.xml

<web-app ..>
    ...
    <login-config>
        <auth-method>BASIC</auth-method>
        <!--<realm-name>referencesApplicationDomain</realm-name>-->
    </login-config>
</web-app>

jboss-web.xml:

<jboss-web ...>
    <deny-uncovered-http-methods>false</deny-uncovered-http-methods>
    <context-root>/references</context-root>
    <!--<security-domain>referencesApplicationDomain</security-domain>-->
</jboss-web>

这是有效的,因为默认情况下,Wildlfly 的暗流系统使用 ApplicationRealm 作为默认安全域。 您可以通过查看 standalone.xml.

来验证这一点