可以使用安全套接字层 (SSL) 传输层安全性保护 JAX-RS 2.0 资源。
关于此任务
此任务旨在指导您通过配置 web.xml 文件来保护 JAX-RS 2.0 服务器端。
过程
- 在 WebSphere® Application Server(传统) 管理控制台中,启用管理安全性和应用程序安全性。
转到安全性 -> 全局安全性。在“全局安全性”面板上,选中管理安全性字段下的启用管理安全性框,以及应用程序安全性字段下的启用应用程序安全性框。
- 开发 JAX-RS 2.0 Web 应用程序。
- 配置 web.xml 文件。
要保护 JAX-RS 资源,请将 user-data-constraint 元素下的
transport-guarantee 子元素添加到 web.xml 文件,并将其值设置为
CONFIDENTIAL。请参阅以下示例作为参考:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_3_0.xsd"
version="3.0">
<display-name>Security Test Application</display-name>
<description>Server-side application for Security Tests</description>
<servlet>
<servlet-name>com.ibm.ws.jaxrs.security.ssl.SSLApplication
</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>com.ibm.ws.jaxrs.security.ssl.SSLApplication
</servlet-name>
<url-pattern>/ssltest/*</url-pattern>
</servlet-mapping>
<security-constraint id="SecurityConstraint_1">
<web-resource-collection id="WebResourceCollection_1">
<web-resource-name>com.ibm.ws.jaxrs.security.ssl.SSLApplication
</web-resource-name>
<description>Protection area for Rest Servlet</description>
<url-pattern>/ssltest/ssl/get</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>test</realm-name>
</login-config>
<security-role id="SecurityRole_1">
<description>blabla</description>
<role-name>Role1</role-name>
</security-role>
<security-role id="SecurityRole_2">
<role-name>Role2</role-name>
</security-role>
<security-role id="SecurityRole_3">
<role-name>AuthenticationRole</role-name>
</security-role>
</web-app>