为Web服务应用HTTPS的最佳实践

时间:2012-05-25 13:05:14

标签: web-services apache tomcat https

我正在开发使用CXF 2.5.2实现的JAVA中的webservices开发。 我使用apache Tomcat作为Web服务器。

我需要在某些web服务方法中添加HTTPS安全性,我想知道最好实现HTTPS安全性。 我听说我可以通过指定安全约束来在web.xml中配置HTTPS ...或者我可以在Apache tomcat中为任何方法配置HTTPS。

我对每种解决方案的优势和劣势的看法, 我认为在web.xml中配置https的优点是在webservice的同一webapp中进行本地化。 apache tomcat配置的优点是不允许耦合到任何webapp。

我确信有更多方法可以实施HTTPS。

谢谢!

1 个答案:

答案 0 :(得分:0)

在web.xml中配置安全性(例如)

<security-constraint>
      <web-resource-collection>
         <web-resource-name>REST Service </web-resource-name>
         <url-pattern>/*</url-pattern>
      </web-resource-collection>
       <auth-constraint>
         <role-name>User</role-name>
      </auth-constraint>
  </security-constraint>

  <login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>Test</realm-name>
   </login-config>
   <security-role>
      <role-name>User</role-name>
   </security-role>
相关问题