java - WildFly 9 启用客户端证书认证

标签 java ssl https wildfly client-certificates

我想在我的 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/

相关文章:

java - 在 Java 中表示和操作概率和百分比的正确方法是什么?

Java:Clob 到 byte[]

java utillogging在属性文件中配置过滤器

apache - 谷歌云平台 : Cannot get https (SSL) working on Wordpress Instance

java - Spring MVC 4 + Tomcat 7,如何用JavaConfig实现HTTPS?

Java 内存中即时类编译(和加载)

php - Magento 1.9 中的类别页面未显示 SSL。其余所有页面,包括主页和产品页面都工作正常

ios - SSL Pinning 的安全性

python - 请求(由于 SSL 模块不可用,由 SSLError ("Can' t 连接到 HTTPS URL 引起。”)PyCharm 请求网站中的错误

python - 如何在 WebTest 下模拟 HTTPS 请求?