Mic*_*art 3 jboss roles client-certificates wildfly
我正在使用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文件中预先定义它们?
通常情况下,我似乎在发布此问题后不久就偶然发现了我的回答.
我一直在挖掘这里列出的所有登录模块.在查看身份模块后,我想我会在证书身份验证后尝试包含它,并且只需指定"roles"模块选项.所以我最终得到了以下内容.
<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>
Run Code Online (Sandbox Code Playgroud)
这似乎在功能上做我想要的.通过在两个登录模块上指定密码堆叠选项,它可确保仅使用客户端证书进行身份验证.第二个登录模块Identity只是将角色"User"添加到已登录的任何人.现在当我访问我的web.xml中指定的受保护目录下的任何资源时,系统会提示我输入我的证书并允许进入.
希望这将有助于其他人在未来.
| 归档时间: |
|
| 查看次数: |
1256 次 |
| 最近记录: |