Tomcat安全访问

时间:2011-06-13 16:00:18

标签: security authentication tomcat client web.xml

我有两个Web服务(MyService和MyProtectedService)。我希望两者都在相同的端口HTTPS下,但只有受保护的端口才能进行客户端身份验证(clientAuth = true)。

所有安全性都正常,但问题是两个服务的客户端身份验证都是ON,而不仅仅是受保护的服务。我想要的是为其中一个删除客户端身份验证,或仅将客户端身份验证应用于另一个。

有人有任何提示吗?感谢

在web.xml中:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>protected element</web-resource-name>
        <description/>
        <url-pattern>/MyProtectedService</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

更新: 我试图将服务划分为两个约束:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>OpenService</web-resource-name>
        <description/>
        <url-pattern>/OpenService</url-pattern>
    </web-resource-collection>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>protected</web-resource-name>
        <description/>
        <url-pattern>/MyProtectedService</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    <login-config>
        <auth-metod>CLIENT-CERT</auth-metod>
    </login-config>
</security-constraint>

在server.xml中使用ClientAuth = false。

但是我可以在没有任何客户端身份验证的情况下访问它: https://MACHINE/MyProtectedService/MyProtectedService?wsdl

1 个答案:

答案 0 :(得分:2)

该方法是有两个单独的安全约束,即使公共服务的约束根本没有约束(既不是auth-constraint也不是user-data-constraint)。它假设这两个服务具有不同的URL,这很可能就是这种情况:

<security-role>
    <role-name>ProtectedServiceRole</role-name>
</security-role>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Public Service</web-resource-name>
        <url-pattern>/PublicService/*</url-pattern>
    </web-resource-collection>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Protected Service</web-resource-name>
        <url-pattern>/ProtectedService/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    <auth-constraint>
        <role-name>ProtectedServiceRole</role-name>
    </auth-constraint>
</security-constraint>

auth-constraint中指定的角色名称将触发身份验证。

<强>更新

我担心我没有正确阅读您的问题并忽略了证书身份验证部分。虽然我过去曾经使用它,但我从来没有使用过您需要的混合设置,因此我只能提供一些选项,您可以尝试下一步:

目前,您需要在传输级别进行身份验证。那是低级别而且太早。您是否尝试将 clientAuth 设置为 false ,而是将以下行添加到您的web.xml中:

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

另一种方法是为两个服务使用两个不同的端口。为此,您可以在server.xml中定义两个不同的连接器

相关问题