【问题标题】:Tomcat secure accessTomcat 安全访问
【发布时间】:2011-09-14 01:08:54
【问题描述】:

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

所有的安全措施都工作正常,但问题是客户端身份验证对这两种服务都是开启的,而不仅仅是受保护的服务。我想要的是删除其中一个的客户端身份验证,或者仅将客户端身份验证应用于另一个。

有人有什么提示吗?谢谢

在 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

【问题讨论】:

    标签: security authentication tomcat client web.xml


    【解决方案1】:

    该方法是有两个单独的安全约束,即使用于公共服务的一个根本没有约束(auth-constraintuser-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 中定义了两个不同的 连接器

    【讨论】:

    • 感谢您的回答。我试过这个,我认为还有其他事情,因为我仍然被要求提供证书。如果我使用 http:443 而不是 https,那么我会得到奇怪的字符。有什么想法吗?
    • @Codo,似乎 Tomcat 总是要求客户端身份验证(server.xml 在 web.xml 之前检查,这是有道理的),所以我不认为你提到的可以工作。 .. :-?
    • 谢谢,@Codo。显然没有做任何事情......在问题中查看我上面的更新
    • @Codo,对于不同的连接器......它应该工作吗?因为如果我有一个没有 clientAuth 的连接器,它仍然会提供“MyProtectedService”,不是吗?或者有没有办法限制 WAR 应用程序中的 servlet?
    • 需要两个连接器(一个带有 clientAuth 的 HTTPS,另一个是 HTTP),然后是两个 servlet 的 web.xml 配置。谢谢@Codo
    猜你喜欢
    • 1970-01-01
    • 2012-04-26
    • 2016-12-27
    • 2011-10-12
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多