我正在使用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>
Run Code Online (Sandbox Code Playgroud)
我的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>
Run Code Online (Sandbox Code Playgroud)
最后,我的jboss-web.xml
<jboss-web>
<security-domain>client_cert_domain</security-domain>
</jboss-web>
Run Code Online (Sandbox Code Playgroud)
这几乎完全符合我的要求.主页面不需要任何身份验证,而/ register /需要客户端证书.唯一的问题是,因为这不是注册用户,所以没有为其分配角色,因此页面被阻止,因为它们不在auth-constraint标记中指定的"用户"角色中.
是否有一种简单的方法可以自动为使用客户端证书进行身份验证的任何用户分配默认角色,而无需在roles.properties文件中预先定义它们?