问题描述
运行 Wildfly 16,我在应用程序的 WEB-INF/jboss-web.xml 中指定了一个安全域,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>MyDomain</security-domain>
</jboss-web>
在 Wildfly 的 standalone.xml 中的 undertow 部分,我将安全域指定为应用程序安全域,如下所示:
<subsystem xmlns="urn:jboss:domain:undertow:8.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other" statistics-enabled="${wildfly.undertow.statistics-enabled:${wildfly.statistics-enabled:false}}">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
<https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<http-invoker security-realm="ApplicationRealm"/>
</host>
</server>
...
<application-security-domains>
<application-security-domain name="MyDomain" security-domain="OAuth2Domain"/>
</application-security-domains>
接下来,在 elytron 部分,我指定安全域如下:
<subsystem xmlns="urn:wildfly:elytron:6.0" final-providers="combined-providers" disallowed-providers="OracleUcrypto">
...
<security-domain name="OAuth2Domain" default-realm="OAuth2Realm" permission-mapper="default-permission-mapper">
<realm name="OAuth2Realm"/>
</security-domain>
当然,随后也定义了 OAuth2Realm,Wildfly 毫无怨言地开始了。但是,当通过http访问应用程序时,Wildfly总是在legacy security部分使用安全域“other”,而不是在elytron部分使用我的安全域。如何强制 Wildfly 使用我的 elytron 安全域?
解决方法
找到解决方案:应用程序使用 JAAS 登录上下文使用编程登录,但这仅知道旧安全系统中定义的安全域。要以编程方式登录 elytron 系统中的域,必须使用 elytron 身份验证上下文,如 https://docs.jboss.org/author/display/WFLY/Client%20Authentication%20with%20Elytron%20Client.html
中所述