我想在我的 WildFly 9 服务器上运行的 Web 应用程序上启用客户端证书身份验证。
为此,我使用以下元素配置了我的应用程序:
我创建了一个服务器 keystore ,一个客户端 keystore 。从他们那里,我导出了一个包含在我的服务器信任库中的自签名证书。
我的 standalone.xml 文件包含这些部分:
...
<management>
<security-realms>
<security-realm name="my-realm">
<server-identities>
<ssl>
<keystore path="server.keystore" relative-to="jboss.server.config.dir" keystore-password="password"/>
</ssl>
</server-identities>
<authentication>
<jaas name="my-domain"/>
</authentication>
</security-realm>
</security-realms>
</management>
...
<subsystem xmlns="urn:jboss:domain:security:1.2">
<security-domains>
<security-domain name="my-domain" cache-type="default">
<authentication>
<login-module code="Remoting" flag="optional">
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required">
<module-option name="usersProperties" value="${jboss.server.config.dir}/app-users.properties"/>
<module-option name="rolesProperties" value="${jboss.server.config.dir}/app-roles.properties"/>
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
</authentication>
</security-domain>
</security-domains>
</subsystem>
...
<subsystem xmlns="urn:jboss:domain:undertow:2.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https"/>
<https-listener name="https" socket-binding="https" security-realm="my-realm"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="WildFly/9"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
</filters>
</subsystem>
...
我的 web.xml 文件包含以下内容:
...
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin Resource</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
...
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>my-realm</realm-name>
</login-config>
<security-role>
<role-name>my-role</role-name>
</security-role>
...
我的 jboss-web.xml 包含:
<security-domain>my-domain</security-domain>
我还在我的 JDK 中添加了以下参数:
-Djavax.net.debug=ssl:handshake
-Djavax.net.ssl.trustStore=[WILDFLY_HOME]\\standalone\\configuration\\server.truststore
-Djavax.net.ssl.trustStorePassword=password
然后我尝试使用 Web 浏览器在 URL http://localhost:8080/my-app-web/
访问我的 Web 应用程序。我被重定向到 https://localhost:8443/my-app-web/
,即使浏览器不包含客户端证书,我也可以访问页面的内容。
你能告诉我我的配置有什么问题吗?
最佳答案
你需要一个 Certificate
您的安全域中的登录模块。
看看这个quickstart更多细节。
关于java - WildFly 9 启用客户端证书认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34360869/