简体   繁体   English

Tomcat / Spring SSL配置

[英]Tomcat/Spring SSL configuration

I'm trying to configure my Spring application to use an SSL certificate I purchased from a CA. 我正在尝试将Spring应用程序配置为使用从CA购买的SSL证书。 I followed the directions for the Tomcat 6.0 configuration and have imported the key into my Tomcat keystore and uncommented the SSL connector in the server.xml. 我按照Tomcat 6.0配置的说明进行操作 ,并将密钥导入到我的Tomcat密钥库中,并且未注释server.xml中的SSL连接器。 When I start Tomcat, I see the connector start on port 8443 in the Tomcat logs, but when I go to https://example.com:8443 or http: //example.com:8443 or https: //example.com (without the spaces - I don't have the reputation to post links), it times out. 当我启动Tomcat时,我看到连接器在Tomcat日志中的端口8443上启动,但是当我转到https://example.com:8443或http://example.com:8443或https://example.com时(没有空格-我没有发布链接的声誉),它超时。 What other configuration do I need to do to enable SSL for my Spring application. 要为Spring应用程序启用SSL,我还需要执行其他哪些配置。 Do I have to change the application configuration? 我是否需要更改应用程序配置?

I'd also like to only have some URLs over SSL (login, edit profile, etc.). 我还想只通过SSL提供一些网址(登录,编辑个人资料等)。 How can I allow this in the Spring configuration? 如何在Spring配置中允许这样做? If I have to have all URLs accessible over SSL, that would be ok, but not desirable. 如果必须通过SSL访问所有URL,那可以,但是不希望如此。 I haven't found any tutorials that are Spring specific. 我还没有找到任何特定于Spring的教程。

about the second point 关于第二点

I'd also like to only have some URLs over SSL (login, edit profile, etc.). 我还想只通过SSL提供一些网址(登录,编辑个人资料等)。 ??? ???

you could determine it by modify configration in web.xml 您可以通过修改web.xml中的配置来确定它

  <security-constraint> <web-resource-collection> <web-resource-name>securedapp</web-resource-name> <!-- <url-pattern>/*</url-pattern> --> <!--all pages--> <url-pattern>/yourapp/login</url-pattern> <url-pattern>/yourapp/edit</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> 

hope that help you 希望对你有帮助

What you'll need to do is to edit your server.xml file to enable ssl. 您需要做的是编辑server.xml文件以启用ssl。 Here's Tomcat's guide, please check it out: 这是Tomcat的指南,请检查一下:

http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html

In order to programmatically know if a request has arrived through port 80 or 443, you need to inspect the value returned by request.isSecure() . 为了以编程方式知道请求是否已通过端口80或443到达,您需要检查request.isSecure()返回的值。

To secure URLs altogether, I'd recommend using a Filter. 要完全保护URL,建议您使用过滤器。

I don't remember how all of this is handled by Spring, but I don't think you'll have any problems to obtain the request object. 我不记得Spring如何处理所有这些事情,但是我认为获取请求对象不会有任何问题。

Hope that helps. 希望能有所帮助。

After you've configured Tomcat as per the document cited by @mschonaker, he simplest thing is to define the action in the j_security_check and edit profile forms, etc, specify the https: protocol, eg in a Facelet, https://# {request.serverName}:8443#{request.contextPath}/j_security_check. 在按照@mschonaker引用的文档配置了Tomcat之后,他最简单的方法是在j_security_check中定义操作并编辑配置文件表单,等等,指定https:协议,例如在Facelet中, https://# { request.serverName}:8443#{request.contextPath} / j_security_check。 Then when the user hits the login button, the form POSTs via HTTPS, so they are secure. 然后,当用户单击登录按钮时,表单将通过HTTPS进行POST,因此它们是安全的。

This leaves you in HTTPS for the rest of the session: to get back to HTTP but still stay in the same session, just provide a link to a fully-specified HTTP url, eg in a Facelet, http://# {request.serverName}:8443#{request.contextPath}/ some link . 这将使您在整个会话的其余时间都留在HTTPS中:要返回HTTP但仍停留在同一会话中,只需提供指向完全指定的HTTP URL的链接,例如在Facelet中, http://# {request。 serverName}:8443#{request.contextPath} / 一些链接

If you have other pages you want secured when read, define appropriate security-constraint, user-data-constraint, and transport-guarantee CONFIDENTIAL elements for them in web.xml. 如果还有其他页面需要在读取时进行保护,请在web.xml中为其定义适当的安全性约束,用户数据约束和传输保证机密元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM