用于tomcat中特定页面/ url-patterns的SSL

Tim*_*nce 5 java ssl configuration tomcat war

我最近使用SSL和客户端身份验证配置了tomcat 6,但我能做到的唯一方法是修改服务器配置文件(web.xml,server.xml).但由于我无法完全控制部署服务器,因此我想在不修改主配置文件的情况下为我的应用程序的某些页面或url-patterns配置所有内容.

例如:主服务器:

  • Application1 - > HTTP
  • Application2 - > HTTP
  • MyApplication - > HTTPS

如果有人知道怎么做,请告诉我.

Ric*_*mon 9

获取https的唯一方法是server.xml<service>标记下的文件上编写适当的连接器.设置连接器后,您可以使用http或https访问服务器中的所有应用程序.唯一的区别是连接器的使用.通常,http和https的连接器如下所示:

<Connector port="80" protocol="HTTP/1.1"
           maxThreads="150" connectionTimeout="20000"
           redirectPort="443"
           URIEncoding="UTF-8" compression="on"/>

<Connector port="443" protocol="HTTP/1.1"
           maxThreads="150" connectionTimeout="20000"
           SSLEnabled="true" scheme="https" secure="true"
           keystoreFile="conf/.keystore"
           keystorePass="changeit"
           clientAuth="false" sslProtocol="TLS"
           URIEncoding="UTF-8" compression="on"/>
Run Code Online (Sandbox Code Playgroud)

然后,您可以通过添加transport-guarantee标签来强制您的应用程序始终使用https web.xml:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Administrators</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>Administrators</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

您可以更改transport-guarantee您定义的不同Web资源.因此,您可以保护网站的某些部分而不是其他部分.

最后,如果连接器中server.xml没有强制您使用https进行所有应用程序.它只允许使用https连接器.