JBOSS 7有两个上下文。一个使用SSL Mutual Auth,另一个使用SSL

时间:2013-05-03 02:44:53

标签: java authentication ssl jboss jaas

我们在配置JBoss时遇到问题。我们正在配置它以使其可以同时使用Mutual auth并且不使用它。 像:

https://example.com/contextA/(需要SSL相互身份验证) https://example.com/contextB/(只是SSL)

有可能吗?

我能做的是制作或所有JBoss使用SSL相互认证或不使用。如何将其配置为同时进行?

我的contextA web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>ContextA</display-name>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>services</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>*</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <login-config>
        <auth-method>CLIENT-CERT</auth-method>
    </login-config>

    <security-role>
        <role-name />
    </security-role>
</web-app>

我的上下文a jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <security-domain>RequireCertificateDomain</security-domain>
</jboss-web>

ContextB web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <display-name>ContextB</display-name>

    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <trim-directive-whitespaces>true</trim-directive-whitespaces>
        </jsp-property-group>
    </jsp-config>

    <session-config>
        <session-timeout>10</session-timeout>
        <cookie-config>
            <http-only>true</http-only>
        </cookie-config>
    </session-config>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <security-constraint>
        <display-name>SecureApplicationConstraint</display-name>
        <web-resource-collection>
            <web-resource-name>ContextB</web-resource-name>
            <description>Auth applications are secured</description>
            <url-pattern>/login/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description>Only Users with roles are allowed</description>
            <role-name>USER</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <security-constraint>
        <display-name>SecureChannelConstraint</display-name>
        <web-resource-collection>
            <web-resource-name>Entire site is protected through SSL</web-resource-name>
            <description />
            <url-pattern>/contextB/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <description>Require encrypted channel</description>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>ContextBPolicy</realm-name>
        <form-login-config>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/loginError.jsp</form-error-page>
        </form-login-config>
    </login-config>

    <security-role>
        <description/>
        <role-name>USER</role-name>
    </security-role>

</web-app>

ContextB jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <security-domain>java:/jaas/ContextBPolicy</security-domain>
</jboss-web>

standalone.xml的内容

<security-domain name="ContextBPolicy">
    <authentication>
        <login-module code="org.ContextBLoginModule" flag="required"/>
    </authentication>
</security-domain>

(...)

<security-domain name="RequireCertificateDomain">
    <authentication>
        <login-module code="CertificateRoles" flag="required">
            <module-option name="securityDomain" value="RequireCertificateDomain"/>
            <module-option name="verifier" value="org.jboss.security.auth.certs.AnyCertVerifier"/>
            <module-option name="usersProperties" value="file:c:/tmp/my-users.properties"/>
            <module-option name="rolesProperties" value="file:c:/tmp/my-roles.properties"/>
        </login-module>
    </authentication>
    <jsse keystore-password="changethis" keystore-url="file:c:/tmp/localhost.jks" truststore-password="changethis" truststore-url="file:c:/tmp/cacerts.jks"/>
</security-domain>

(...)

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
    <configuration>
        <jsp-configuration x-powered-by="false"/>
    </configuration>
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true">
        <ssl name="ssl" key-alias="localhost" password="changethis" certificate-key-file="../standalone/configuration/localhost.jks" verify-client="require" ca-certificate-file="../standalone/configuration/cacerts.jks" truststore-type="JKS"/>
    </connector>
    <virtual-server name="default-host" enable-welcome-root="true">
        <alias name="localhost"/>
        <alias name="example.com"/>
    </virtual-server>
</subsystem>

3 个答案:

答案 0 :(得分:4)

有可能,因为您要为不同的Web应用程序配置不同类型的身份验证。

请将verify-client的值修改为want

<connector name="https" ...>
    <ssl .. verify-client="want" .../>
</connector>

<强>加

根据与verify-client属性相关的JBoss文档: http://docs.jboss.org/jbossweb/7.0.x/config/ssl.html

如果您希望SSL堆栈在接受连接之前需要来自客户端的有效证书链,请设置为"true"。如果您希望SSL堆栈请求客户端证书,则设置为"want",但如果未显示SSL堆栈,则设置为verify-client=”true”

如果verify-client="want" JBoss需要证书,那是正确的。但是,如果您在{{1}} JBOSS需要客户端证书时访问证书。如果兄弟包含客户端证书并且应用程序受到客户端证书身份验证(web.xml中的CLIENT-CERT)的保护,那么它应该会成功。

答案 1 :(得分:1)

您可以通过定义需要证书的领域来实现此目的:

<security-realm name="CertRequiredRealm">
    <authentication>
        <truststore path="mytruststore.jks" password="mytruststorepassword"/>
    </authentication>
</security-realm>

然后将WebApplication放入该领域:

在WEB-INF / web.xml中:

<login-config>
    <auth-method>CLIENT-CERT</auth-method>
    <realm-name>CertRequiredRealm</realm-name>
</login-config>

答案 2 :(得分:1)

在我看来,基于http端点不可能做到这一点。

原因是在客户端将http请求发送到服务器之前发生SSL / TLS握手。

端点(例如/contextA)驻留在该http请求中!

在SSL / TLS握手开始时,只有主机名(例如example.com)可用(并且仅当客户端启用了SNI时)。

所以你需要2个不同的主机名。例如contexta.example.comcontextb.example.com