我在apache tomcat中部署了一些web服务,所有web服务都可以通过http和https访问。我希望少数web服务只能通过https访问,而不能通过http访问。是否可以在apache tomcat或cxf或spring框架中进行配置。
这方面的任何帮助对我都非常有用。
Lokesh
ServletRequest.isSecure()
即可。检查后,您可以重定向到仅安全的版本,反之亦然。
以上所有内容都可以在许多地方完成,但根据我的口味,编写一个servlet过滤器是最容易的,它可以透明地处理上面提到的check&重定向。
注意:如果Tomcat落后于Apache或负载均衡器,并且SSL在该过程的早期终止,则上述方法可能不起作用。
在web.xml中将<transport-guarantee>
设置为CONFIDENTIAL
允许您对某些页面要求SSL。
它看起来像这样:
<security-constraint>
<web-resource-collection>
<web-resource-name>SSL forwarding</web-resource-name>
<url-pattern>/secured</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>
CONFIDENTIAL
</transport-guarantee>
</user-data-constraint>
</security-constraint>
希望这能有所帮助。