使用 SSL 通信保护 JAX-RS 2.0 资源

 可以使用安全套接字层 (SSL) 传输层安全性保护 JAX-RS 2.0 资源。

开始之前

此任务假定您已完成下列步骤:
  • 已定义应用程序服务器或联合到网络 Deployment Manager 的应用程序服务器的单元概要文件。阅读关于创建单元概要文件的信息以了解如何创建包含联合应用程序服务器节点和 Deployment Manager 的单元概要文件。
  • 已在应用程序服务器上安装 JAX-RS 2.0 应用程序。

关于此任务

此任务旨在指导您通过配置 web.xml 文件来保护 JAX-RS 2.0 服务器端。

过程

  1. WebSphere® Application Server(传统) 管理控制台中,启用管理安全性和应用程序安全性。

    转到安全性 -> 全局安全性。在“全局安全性”面板上,选中管理安全性字段下的启用管理安全性框,以及应用程序安全性字段下的启用应用程序安全性框。

  2. 开发 JAX-RS 2.0 Web 应用程序。
  3. 配置 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>

结果

现在,您可以调用已加密的资源。


指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_jaxrs_impl_securejaxrs2
文件名:twbs_jaxrs_impl_securejaxrs2.0_serverssl.html