首页 > 解决方案 > 如何在 tomcat 中为特定项目设置 Java truststore 和 truststorepassword 属性?

问题描述

我在 tomcat 中运行两个应用程序,而 tomcat 在 https 上运行。我需要为 application1 发送证书,而 application2 不需要它。我在 application1 中配置 truststore 和 truststorepassword 以使用来自服务器“x”的服务。配置系统属性后,第二个应用程序正在发送证书,因此我从服务器“y”收到异常(不需要任何证书即可从第二个应用程序访问服务器)。我怎么解决这个问题 ?

在 application2 web.xml 中添加了 security-constraint 元素以禁用 url 模式的 SSL 选项:

<security-constraint>
   <web-resource-collection>
        <web-resource-name>ShipConsoleSCMCloud</web-resource-name>
        <url-pattern>/application2/*</url-pattern>
   </web-resource-collection>
   <user-data-constraint>
         <transport-guarantee>NONE</transport-guarantee>
   </user-data-constraint>
</security-constraint> 

标签: httpstomcat8truststorejava-security

解决方案


不要使用系统属性。

根据您用于与服务通信的 API,它应该具有配置选项来专门为一个连接配置 TLS 参数,而不是仅仅将系统属性作为默认值。


推荐阅读