Jboss Wildfly:将默认角色分配给具有客户端证书身份验证的用户

Jboss Wildfly:将默认角色分配给具有客户端证书身份验证的用户,jboss,wildfly,roles,client-certificates,Jboss,Wildfly,Roles,Client Certificates,我正在为我的应用程序使用Wildfly构建一个注册页面,该页面要求用户使用智能卡进行注册。我希望有一个不需要任何身份验证的初始登录页,然后当他们访问注册页时,它将提示他们从智能卡中选择证书 我已经非常接近我所期望的完成这项工作,但我认为这肯定是因为我对Wildfly/JBOSS缺乏了解 我在standalone.xml中定义了以下安全域 <security-domain name="client_cert_domain" cache-type="default">

我正在为我的应用程序使用Wildfly构建一个注册页面,该页面要求用户使用智能卡进行注册。我希望有一个不需要任何身份验证的初始登录页,然后当他们访问注册页时,它将提示他们从智能卡中选择证书

我已经非常接近我所期望的完成这项工作,但我认为这肯定是因为我对Wildfly/JBOSS缺乏了解

我在standalone.xml中定义了以下安全域

<security-domain name="client_cert_domain" cache-type="default">
                <authentication>
                    <login-module code="Certificate" flag="required">
                        <module-option name="verifier" value="org.jboss.security.auth.certs.AnyCertVerifier"/>
                        <module-option name="securityDomain" value="client_cert_domain"/>
                    </login-module>
                </authentication>
                <jsse keystore-password="secret" keystore-url="file:${jboss.server.config.dir}/Certificates/HQ/KeyStore" truststore-password="secret" truststore-url="file:${jboss.server.config.dir}/Certificates/HQ/cacerts.jks" client-auth="true"/>
            </security-domain>
我的web.xml是

<?xml version="1.0" encoding="UTF-8"?>
<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">
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Registration page only</web-resource-name>
        <url-pattern>/register/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>User</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>CLIENT-CERT</auth-method>
    <realm-name>Some Name For User To See</realm-name>
</login-config>
最后,我的jboss-web.xml

<jboss-web>
    <security-domain>client_cert_domain</security-domain>
</jboss-web>
这几乎正是我想要的。主页不需要任何身份验证,并且/register/需要客户端证书。唯一的问题是,由于这不是注册用户,因此他们没有分配给他们的角色,因此页面被阻止,因为他们不在auth constraint标记中指定的用户角色中


有没有一种简单的方法可以自动将默认角色分配给任何使用客户端证书进行身份验证的用户,而无需在roles.properties文件中预定义这些证书?

通常,在发布此问题后不久,我似乎偶然发现了我的答案

我一直在浏览列出的所有登录模块。在查看了标识模块之后,我想我应该在证书身份验证之后尝试将其包括在内,并只指定角色模块选项。因此,我最终得出以下结论

<security-domain name="client_cert_domain" cache-type="default">
    <authentication>
        <login-module code="Certificate" flag="required">
            <module-option name="password-stacking" value="useFirstPass"/>
            <module-option name="verifier" value="org.jboss.security.auth.certs.AnyCertVerifier"/>
            <module-option name="securityDomain" value="client_cert_domain"/>
        </login-module>
        <login-module code="Identity" flag="required">
            <module-option name="password-stacking" value="useFirstPass"/>
            <module-option name="roles" value="User"/>
        </login-module>
    </authentication>
    <jsse keystore-password="Password1" keystore-url="file:${jboss.server.config.dir}/Certificates/HQ/KeyStore" truststore-password="Password1" truststore-url="file:${jboss.server.config.dir}/Certificates/HQ/cacerts.jks" client-auth="true"/>
</security-domain>
这似乎在功能上符合我的要求。通过在两个登录模块上指定密码堆叠选项,它确保仅使用客户端证书进行身份验证。第二个登录模块Identity只是将角色User添加到登录的用户。现在,当我访问web.xml中指定的受保护目录下的任何资源时,系统会提示我输入证书并允许我进入

希望这能在将来帮助其他人