级别: 初级 Emily Jiang, 软件工程师, IBM
2009 年 6 月 10 日
了解如何配置 Java™ API for XML-based Web Services (JAX-WS) 应用程序,以便使更新的 WS-Notification 功能能够运行在安全的 IBM® WebSphere® Application Server V7.0 上。本文将介绍如何通过使用 WS-Security 保护 WS-Notification JAX-WS 应用程序,其中包括如何启用 WebSphere Application Server 安全性,如何创建 Version 7.0 WS-Notification 服务,以及如何将 WS-Security 策略集和绑定与 WS-Notification 应用程序关联。
来自 IBM WebSphere Developer Technical Journal。
引言
WS-Notification 通过使用一个基于主题的发布/订阅消息传递模式为 Web 服务通信提供了一个开放的标准。正如 WebSphere Application Server V7 中的 WS-Notification:第 1 部分中所述,IBM WebSphere Application Server V7.0 将基于 Java API for XML-based Web Services (JAX-WS) 实施 WS-Notification(即 Version 7.0 WS-Notification)。如果创建 Version 7.0 WS-Notification 服务,则可以使用诸如 WS-ReliableMessaging 或 WS-Security 之类的策略集配置它。本文重点讲述如何在安全的 Version 7.0 WebSphere Application Server 中组合 WS-Notification 服务和 WS-Security 策略集。
WebSphere Application Server“策略集”汇集了有关如何定义 Web 服务的断言。您可以使用策略集简化配置,并将传输与以下相关领域的消息级配置设置结合在一起:WS-Addressing、WS-ReliableMessaging、WS-Security、HTTP Transport、JMS Transport 和 SSL Transport。策略集只适用于 JAX-WS 应用程序,不适用于 Java API for XML-based RPC (JAX-RPC) 应用程序。
WS-Security 提供了端到端的消息安全性,这可确保在传输期间不会对这些消息实施操作,同时还提供了机密性。WebSphere Application Server V7.0 提供了大量缺省的 WS-Security 策略集。在本文中,我们将选择 Username WSSecurity default 策略集来保护 WS-Notification 应用程序的安全。此策略集包含基本身份验证功能和消息级安全性。
在生产环境中,建议启用 WebSphere Application Server 安全性以防止非授权用户访问您的系统。在安装 WebSphere Application Server V7.0 时,除非选择其他设置,否则缺省情况下将启用管理安全性。
以下过程大致介绍了如何先设置安全的 WebSphere Application Server,然后介绍配置 WS-Notification 服务和其他应用程序,使之带有 WS-Security 策略集。该过程既适用于单个服务器又适用于集群拓扑。本文中使用的拓扑是独立的应用服务器。
该过程如下所示:
-
配置 WebSphere Application Server V7.0 的管理安全性
-
在 WebSphere Application Server V7.0 中创建 Version 7.0 WS-Notification 服务和服务点。
-
部署 JAX-WS 应用程序:
-
WS-Notification 生产者和订阅者
-
基于 JAX-WS 的 WS-Notification 使用者 Web 服务。
-
[可选步骤] 通过将 HTTPS 上的 SOAP 指定为您的 WS-Notification 服务点绑定,在客户端和服务提供者之间使用 HTTPS 传输。
-
将策略集
Username WSSecurity default 和适当的绑定应用于 WS-Notification 服务点和服务客户端,以及您的 JAX-WS 生产者、订阅者和使用者应用程序。
本文的其余部分将详述上述步骤。本文的第一部分介绍如何设置系统和安装必需的应用程序。第二部分详述如何将 WS-Notification 应用程序配置为带有所选的策略集和绑定。最后是一个演练示例。
先决条件
本文假定您将创建一个单一 WebSphere Application Server,并使用单一通知代理支持个别生产者和使用者 WS-Notification 应用程序相互之间的通信。
要创建您自己的包含 JAX-WS Web 服务客户端和相关构件的 WS-Notification 应用程序,请按照本系列文章的第 1 部分中的说明操作,或者参阅 IBM 信息中心的主题 Using JAX-WS clients and Web services with new Version 7.0 WS-Notification service points。
配置 WebSphere Application Server 安全性
可以使用两种方法启用管理安全性:在概要创建期间,或者在概要创建后。
在启用安全性的情况下创建应用服务器概要
您可以在 WebSphere Application Server 安装期间创建应用服务器概要,并请求针对该概要启用管理安全性。在概要创建期间,将显示如图 1 中所示的 Enable Administrative Security 屏幕,并在缺省情况下选中 Enable administrative security
选项。如果将此作为缺省项,则必须提供管理用户名称(本文中使用 SecureWsn)和密码(本文中使用 SecureW5n)。此用户名是在联合存储库中创建的,它是在创建概要过程中启用管理安全性时的缺省用户注册表。WebSphere Application Server 支持以下类型的用户注册表:
-
联合存储库
-
本地操作系统注册表
-
单独的轻量级目录访问协议 (LDAP) 注册表
-
单独的自定义注册表
本文选择联合存储库作为用户注册表。本文的其余部分不受您所选择的用户注册表影响。请参考 IBM 信息中心的 Selecting a registry or repository 以了解有关其他注册表的详细信息。
图 1. 安装期间的 Administrative Security 窗口
安装后,您还可以创建一个应用服务器概要。在概要创建期间,您可以启用管理安全性并指定您的用户名(例如 SecureWsn)和密码(例如 SecureW5n),如图 2 中所示。
图 2. 创建概要时的 Administrative Security
创建概要后启用安全性
如果您创建了一个禁用安全性的概要,请按照下面的步骤启用管理安全性。
-
通过选择 Security
=>
Global security 导航到 Global security 窗口。将显示图 3 中的窗口。
图 3. Global security
-
选择 Security Configuration Wizard,然后使用 Federated repositories配置安全性。
-
步骤 1 - 指定保护范围(如图 4 中所示)。
本文详述的方案中没有“应用程序安全性”。在下面的窗口中,取消选择 Enable application security,然后单击 Next。
图 4. 配置安全性 - 步骤 1
-
步骤 2 - 选择用户存储库(图 5)。
选择 Federated repositories,然后单击 Next。
图 5. 配置安全性 - 步骤 2
-
步骤 3 - 配置联合存储库(图 6)。
输入您的用户名(例如 SecureWsn)和密码(例如 SecureW5n)。该用户名和密码将在您登录到管理控制台时使用。单击 Next。
图 6. 配置安全性 - 步骤 3
-
步骤 4 - 总结。
单击 Finish,然后保存更改。重新启动应用服务器。您会注意到,现在登录到该管理控制台时需要用户名和密码。输入您的用户名(例如 SecureWsn)和密码(例如 SecureW5n)登录到 WebSphere Application Server。
创建 WSN 服务和必要的资源
要与新的基于 JAX-WS 的 WS-Notification Web 服务交互,您需要配置该应用服务器以公开一个或多个 WS-Notification 服务点。要做到这一点,请下载本文中包括的示例脚本 WAS7_WSN_JAXWS_Part2_Setup.py。执行这些配置步骤或使用管理控制台均可得到相同的结果,下面将描述相关操作。
创建一个服务集成总线并将该服务器添加为总线成员
本部分将先创建一个总线,然后将该服务器作为总线成员添加到该总线中。如果您有一个总线,且启用了总线安全性和配置了总线成员,则可以跳过此部分。
创建服务集成总线
服务集成总线是 WS-Notification 中的一种必需资源。前面已经提及,WS-Notification 支持发布/订阅消息模式。WS-Notification 应用程序发布的通知将被插入到服务集成总线中,连接到该总线的其他任何应用程序都可以修改、重新路由或使用这些通知。同样,由服务集成总线客户端(如 JMS)发送的发布也可被 WS-Notification 使用者接收。接下来,我们将创建一个总线:
-
通过选择 Service integration
=>
Buses 导航到 WebSphere Application Server 实例中的总线管理面板。
-
单击 New 按钮创建一个新总线,这将显示图 7 中所示的窗口。输入新总线的总线名称,并让 Bus security 保持选中状态,如图 7 中所示。本文中的总线名称是
WSNBus。
图 7. 创建新的服务集成总线
-
接受后续步骤中的所有缺省设置,然后在步骤 2 中单击 Finish。
新创建的总线 WSNBus 已启用了安全性。保护服务集成总线安全可为该总线提供一个授权策略,以防止未授权用户获得访问权。换句话说,只有经过授权的用户才可以通过访问该总线来放置或检索消息。因此,要让 WSN 服务访问该总线,必须提供必要的凭据(如用户名和密码)。
将服务器添加为总线成员
您需要将应用服务器添加为总线成员,这样您才可以创建消息引擎,并使用它管理消息传递资源。您可以配置该消息引擎以使用文件存储或数据存储。本文中我们使用文件存储。
-
要将该服务器添加为总线成员,请选择 Service integration
=>
Buses =>
your_bus_name
=>
[Topology] bus members,其中 your_bus_name 是您刚创建的总线名称(例如
WSNBus)。单击 Add 按钮可以显示图 8 中所示的窗口:
图 8. 添加新的总线成员
-
接受后续步骤中的所有缺省设置,然后单击 Finish。
创建 Version 7.0 WS-Notification 服务和服务点
如果已经使用动态主题命名空间创建了 Version 7.0 WS-Notification 服务和服务点,则可以跳过此部分。不过,建议按照以下说明创建独立的 WS-Notification 服务:
-
在 WebSphere Application Server 实例的管理面板中,通过选择 Service integration =>
WS-Notification
=>
Services 导航到 WS-Notification services。
-
单击 New 创建一个新的 WS-Notification 服务。下列步骤将向您介绍如何创建 WS-Notification 服务。
-
步骤 1 配置 WS-Notification 名称(图 9)。
输入 WS-Notification 服务名称。在本文中,WS-Notification 服务称为 WSNSecureService。确保选择了您新创建的总线(即 WSNBus)作为您的服务集成总线。单击 Next。
图 9. 新的 WS-Notification 服务 - 步骤 1
-
步骤 2:选择 WS-Notification 服务类型。
您可以创建 Version 6.1 或 Version 7.0 WS-Notification。选择 Version 7.0 作为您要创建的服务类型。单击 Next。
-
步骤 3:配置处理程序和 Web 服务策略设置(可选)。
选择一个 JAX-WS 处理程序列表,以应用到由 Version 7.0 WSN 服务发送的出站请求。接受缺省设置,并单击 Next。
-
步骤 4:创建 WS-Notification 服务点(图 10)。 该服务点将通过指定的 Web 服务绑定(HTTP 上的 SOAP)在给定总线成员上定义 WS-Notification 服务的访问点。单击 Next。
-
步骤 5:创建永久主题命名空间。
接受缺省设置并为 Create a new instance 选择 No,如图 12 中所示,这意味首 WS-Notification 服务将使用动态主题空间。如果您的 WS-Notification 服务将与 JMS 应用程序交互或者要将限制应用到主题结构,则需要永久主题空间。在本文中,我们使用动态主题空间。请参考 WebSphere Application Server v7.0 信息中心,了解有关动态主题空间与永久主题空间之间差别的详细信息。单击 Next。
图 12. 新的 WS-Notification 服务 - 步骤 5
-
步骤 6:总结。
在总结页上单击 Finish,这将创建 WS-Notification 服务和服务点。
-
重新启动 Application Server。 通过重新启动应用服务器来启动 WS-Notification 服务点。通过选择 Applications
=>
Application Types => WebSphere enterprise applications 导航到 Enterprise Application 页,这时您会看到有一个新的 WS-Notification 服务应用程序列出,即 WSN_WSNSecureService_WSNSecureServicePt。创建 WS-Notification 服务后,此应用程序将为以下三个 WS-Notification 服务角色中的每个角色公开 WS-Notification Web 服务接口:

 |

|
部署 WSN 发布者、订阅者和使用者
正如本 WS-Notification 系列的第 1 部分中所述,要使用 WS-Notification 服务,一般需要部署三个应用程序:WSN 发布者、WSN 订阅者和 WSN 使用者。(注意,在某些用例中,应用程序设计者可能会选择将订阅者和使用者角色合并到单个应用程序中。)在本文中,我们使用了以下三个应用程序:
-
WSNPublisher.ear——发布 WS-Notification 消息
-
WSNConsumer.ear——使用由 WSN 发布者发布的 WS-Notification 消息
-
WSNSubscriber.ear——在 WS-Notification 服务通过 WS-Notification 服务点订阅特定主题
您可以在本文中下载上述每个应用程序。使用管理控制台导航到 Applications =>
New Application
=>
New Enterprise Application 部署上述三种应用程序。图 13 显示了您创建 WS-Notification 服务并安装上述 WS-Notification 应用程序之后的控制台。
图 13. 安装了 WS-Notification 应用程序
保护传输 [可选]
此步骤是可选的。这说明您可以将传输级安全性与消息级安全性一起使用。传输级 安全性加密客户端与服务之间的完整通信(在单个网络跃点上),而消息级安全性仅加密 SOAP 消息。传输级安全性提供了点对点安全性,由于我们需要端到端的安全性,因此 Web 服务存在一些不足之处,其中两个端点之间可能会存在多个中间节点。消息级 安全性提供了端到端的消息保护。在保护 WS-Notification 应用程序时,通过排除此部分即可只使用消息级 WS-Security。本文演示同时使用传输级和消息级安全性来确保 WS-Notification 应用程序的安全。
缺省情况下,服务点使用的 HTTP 上的 SOAP 端点同时接受 HTTP 和 HTTPS 请求。由于所有信息都是以明文形式发送,因此 HTTP 本身是一个不安全协议。要保证 HTTP 安全,您可以应用传输级安全性,以确保通过基础传输的 Web 服务消息的安全。
可通过以下方式选择 HTTPS:将您的 WS-Notification 服务的每个 WS-Notification 服务点上的端点 URL 前缀更改为 https://,然后修改端口以引用由该服务器使用的 HTTPS 端口(缺省端口为 9443)。要实现这一点,请按照下面的说明操作:
-
通过选择 Applications
=>
Application Types
=>
WebSphere enterprise applications =
>
application name
=>
[Web Services Properties] Provide HTTP endpoint URL information 导航到 Provide HTTP endpoint URL information。application name 就是您的 Web 服务提供者,如 WSNConsumer、WSN_WSNSecureService_WSNSecureServicePt
-
通过单击所有复选框选中该应用程序中的所有模块。
-
指定 HTTPS 协议的端点 URL 前缀,如图 14 中所示(其中有意隐藏了计算机主机名)。从 Select default HTTP URL prefix 的预定义列表中选择缺省的 HTTPS 前缀 (
https://
your_host_name
:9443
),其中
your_host_name
是您的 WebSphere Application Server 安装计算机的主机名称。单击 Apply 将该 HTTPS URL 前缀应用于所选模块。
图 14. 提供 HTTP 端点 URL 信息
对 WS-Notification 服务点应用程序 WSN_WSNSecureService_WSNSecureServicePt 和您的 WSNConsumer 应用程序重复上述操作,以配置您的服务提供者使用安全传输 HTTPS。
保存更改后,通过导航到 Enterprise Applications
=>
WSN_WSNSecureService_WSNSecureServicePt
=>
[Web Services properties] Publish WSDL files 发布 WS-Notification 服务点的 WSDL 文件 (NotificationBroker.wsdl、PublisherRegistrationManager.wsdl 和 SubscriptionManager.wsdl)。您会注意到这三个 Web 服务端口的端点 URL 均以 https://your_host_name:9443 开头。请注意,该配置仅将该端点公开为 HTTPS,您仍可以访问非安全端口。如果您想强制该客户端仅使用 HTTPS,则需要在 WS-Notification 服务点和 WSNConsumer 上附加 HTTPS 策略类型,这超出了本文的讨论范围。
将 WS-Notification 应用程序配置为带有 WS-Security 策略集和绑定
在创建 WS-Notification 服务后,可将适当的策略集和绑定附加到 WS-Notification 应用程序中。本文中使用的策略集是 Username WSSecurity default,该策略集带有基本的身份验证和消息级安全性。策略集绑定包含特定于平台的信息,如密钥存储库、身份验证或永久信息。无论何时将 WS-Security 策略集附加到应用程序,您都需要附加相应的绑定文件。以下步骤将详述如何为策略集 Username WSSecurity default 创建绑定文件,然后如何将该策略集和绑定附加到 WS-Notification 应用程序。
将策略集和绑定附加到 JAX-WS 应用程序
对于 JAX-WS 应用程序,您可以附加 WS-Security 策略集和绑定来保护消息的安全。
如上所述,您可以将绑定与策略集关联,因为该绑定包含有关密钥存储的信息、用于数字签名和加密的密钥,以及身份验证和永久信息。在 WebSphere Application Server V7.0 中,有两种类型的绑定:应用程序绑定和通用绑定。通用绑定是 WebSphere Application Server V7.0 的一项新功能。应用程序绑定 是特定应用程序的专用绑定,而通用绑定 可以由多个应用程序重复使用。本文使用通用绑定以供不同的应用程序重复使用该绑定。
共有两种类型的通用绑定:
-
通用提供者策略集绑定——适用于 Web 服务提供商
-
通用客户端策略集绑定——适用于 Web 服务客户端
创建策略集的通用客户端/提供者绑定
创建通用绑定的一个简便方法是复制现有的客户端/提供者绑定,然后编辑新创建的绑定。本文使用缺省通用绑定 Sample client 和 Sample provider 仅作为模板演示。请注意,由于该示例绑定使用示例密钥和密钥存储,因此建议不要将示例通用绑定用于生产中,并且必须更改密钥和密钥存储。
创建通用客户端绑定的操作方法:
-
复制客户端示例绑定。
通过选择 Services
=>
Policy sets => General client policy set bindings 导航到 General client policy set bindings。通过单击 New… 可以创建新的绑定。选择 Client sample 绑定,然后单击 copy…。在 copy of Client sample 窗口中,输入新创建绑定的名称,在本文中称为 WSNClientGeneralBinding。单击 OK,然后保存该更改。
-
编辑新创建的绑定。
新创建的客户端绑定(例如,WSNClientGeneralBinding)需要包含用户名和密码详细信息,以便关联的应用程序可以使用此信息来访问总线和主题空间。
通过访问 Services => Policy Sets => General client policy set binding =>
client_binding_name
=> WS-Security =>Authentication and protection => gen-signunametoken => [Additional bindings] Callback handler 导航到“Callback Handler”面板。client_binding_name 是您刚创建的绑定 WSNClientGeneralBinding。输入您的管理用户名(例如 SecureWsn)和密码(例如 SecureW5n),如图 15 中所示。单击 OK,然后保存您的更改。
图 15. 通用客户端策略集和绑定——Callback handler
创建通用提供者绑定的操作方法:
-
复制提供者示例绑定。
与复制客户端示例绑定类似,通过选择 Services => Policy sets => General provider policy set bindings 复制提供者示例绑定。在本文中,我们将新创建的提供者绑定称为 WSNProviderGeneralBinding。
配置新创建的绑定的操作方法:
在 WSNProviderGeneralBinding 中,您需要通过配置调用方设置指定身份验证方法,这需要指定用于身份验证的令牌和消息部分。
-
选择 Services => Policy Sets => General provider policy set bindings =>
provider_binding_name
=> WS-Security => Caller。provider_binding_name 是您刚创建的绑定 WSNProviderGeneralBinding。
-
单击 New 创建一个调用方。
-
在 Name 字段中输入调用方名称,图 16 中进行了详细说明。本文使用 wsnCaller 作为调用方名称。在 Caller identity local part 字段中,输入用户名令牌:
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken
该调用方意味着将选择此令牌来创建 WebSphere 安全上下文。
-
单击 OK,然后保存更改。
图 16. 通用提供者策略集和绑定——调用方
通过管理控制台附加策略集和绑定
如前所述,在您将策略集附加到应用程序时,还需要附加适当的绑定以便指定该配置。以下部分将详述如何附加策略集 Username WSSecurity default 和通用客户端/提供者绑定。
将 Username WSSecurity 缺省策略集和 WSNClientGeneralBinding 绑定附加到 JAX-WS 服务客户端的操作步骤:
-
要将该策略集和绑定附加到 WSNPublisher,请选择 Applications =>Application Types => WebSphere enterprise applications => WSNPublisher => [Web Service properties] Service client policy sets and bindings。
-
通过单击最上面的复选框然后选择 Attach Client Policy Set,在该应用程序范围内附加
Username WSSecurity default 策略集。在策略集的下拉列表中,选择 Username WSSecurity default,如图 17 所示。
图 17. 服务客户端策略集和绑定——1
-
接下来,我们将附加该 WSNClientGeneralBinding 绑定。通过单击最上面的复选框选中资源,然后选择 Assign Binding。从绑定列表(如 WSNClientGeneralBinding)中选择您的客户端绑定。
-
保存配置。图 18 显示了策略集和绑定配置。
图 18. 服务客户端策略集和绑定——2
-
对 WSNConsumer 和 WSNSubscriber 执行相同的操作。
将策略集“Username WSSecurity default”和提供者绑定附加到 JAX-WS 服务提供者的操作步骤:
在本文中,有两个 JAX-WS 服务提供者:WSNConsumer 和 WSN_WSNSecureService_WSNSecureServicePt。
-
选择 Applications => Application Types => WebSphere enterprise applications =>
application_name
=> Service provider policy sets and bindings,其中application_name 是 WSNConsumer 或 WSN 服务点应用程序,例如 WSN_WSNSecureService_WSNSecureServicePt。
-
使用前面部分中的说明将
Username
WSSecurity default 策略集和 WSNProviderGeneralBinding 提供者绑定附加到这两个应用程序中。图 19 显示了策略集和绑定附件。
图 19. 服务提供者策略集和绑定
将 Username WSSecurity 缺省策略集和客户端绑定附加到 WS-Notification 服务客户端的操作步骤:
-
通过选择 Service integration => WS-Notification => Service =>
WSN_client_name
=> [Additional Properties] Outbound request policy set and binding 导航到 WS-Notification 出站请求策略集和绑定屏幕,其中 WSN_client_name 是本文中的 WSNSecureService。
-
将 Username WSSecurity default 策略集和客户端绑定(例如“WSNClientGeneralBinding”)附加到 WSNSecureService WSN 客户端。
对于 WS-Notification 服务客户端,该策略集附件在端点(端口)或操作级不受支持。因此,不可选择端点或操作,并且显示为继承附加到该服务客户端的任何策略集或绑定。
您还可以通过 Service clients 页将该策略集和绑定附加到 WS-Notification 出站请求。方法是选择 Service => Service clients,然后选择 OutboundNotificationService 和 OutboundRemotePublisherService 服务来附加 Username WSSecurity default 策略集和 WSNClientGeneralBinding 客户端绑定。
示例方案:订阅、发布和使用
本文的最后一部分介绍了一个示例方案,在此场景中,我们使用示例发布者、使用者和订阅者,在安全的 WebSphere Application Server v7.0 中发布和使用经过加密的通知消息。
准备系统
如果您还没有如本文前面描述的那样配置系统,则可以使用下面的说明和脚本自动准备您的系统。如果已按照前面部分中的说明配置了您的系统,则只需要执行第 8 和第 9 步:
-
安装具有已启用全局安全性的单个服务器概要的 WebSphere Application Server V7(通过接受所有缺省设置)。指定 SecureWsn 作为用户名,SecureW5n 作为密码。重新启动您的应用服务器。
-
解压下载文件,并通过发出以下命令创建 Version 7.0 WS-Notification 服务运行该示例 Version 7.0 WS-Notification 配置脚本:
<WAS>\bin\wsadmin -f WAS7_WSN_JAXWS_Part2_Setup.py WSNBus
WSNSecureService WSNSecureServicePt
|
由于已经启用了管理安全性,因此,在执行 wsadmin 命令时,将提示您提供用户身份和密码。在图 20 所示的窗口中输入您的管理用户 ID (SecureWsn) 和密码 (SecureW5n)。
图 20. wsadmin 命令执行登录窗口
另外,您还可以通过在命令行中提供您的用户名和密码执行 wsadmin 命令,下面将详述此情形。不过,我们建议您不要在生产环境中使用此方法,因为这会泄露您的用户名和密码:
<WAS>\bin\wsadmin -f WAS7_WSN_JAXWS_Part2_Setup.py WSNBus
WSNSecureService WSNSecureServicePt -username SecureWsn -password SecureW5n
|
将这一方法用于下面的 wsadmin 命令执行中。
-
通过执行下面的命令将三个 EAR 文件(也包括在下载文件中)安装到应用服务器中。这些文件包含示例发布者、使用者和订阅者组件,并包括允许组合和调用 WS-Notification 请求的 HTTP Servlet。
<WAS>\bin\wsadmin -f WAS7_WSN_JAXWS_Part2_Install_Apps.py
WSNPublisher.ear WSNSubscriber.ear WSNConsumer.ear
|
-
接下来,我们将 WS-Security 策略集 (Username WSSecurity
default) 和绑定附加到 JAX-WS 应用程序中。首先,您需要创建通用绑定:
<WAS>\bin\wsadmin -f WAS7_WSN_JAXWS_Part2_Create_Bindings.py
WSNClientGeneralBinding WSNProviderGeneralBinding
|
WSNClientGeneralBinding 包含用户名 (SecureWsn) 和密码 (SecureW5n)。如果您选择了其他用户名和密码,请参考 Create a general client/provider binding for a policy set 部分更新该绑定中的用户名和密码,以便与步骤 1 中的用户名和密码设置匹配。
-
将策略集和绑定附加到 JAX-WS WS-Notification 应用程序。
<WAS>\bin\wsadmin -f WAS7_WSN_JAXWS_Part2_AttachPolicySetBinding.py
WSNPublisher usernamewssecuritydefault WSNClientGeneralBinding WebService:/ client
WSNSubscriber usernamewssecuritydefault WSNClientGeneralBinding WebService:/ client
WSNConsumer usernamewssecuritydefault WSNClientGeneralBinding WebService:/ client
WSNConsumer usernamewssecuritydefault
WSNProviderGeneralBinding WebService:/ application
WSN_WSNSecureService_WSNSecureServicePt usernamewssecuritydefault
WSNProviderGeneralBinding WebService:/ application
|
-
将策略集和绑定附加到 WS-Notification 客户端。
<WAS>\bin\wsadmin -f WAS7_WSN_JAXWS_Part2_AttachPolicySetBindingWSNOutbound.py
WSNBus WSNSecureService usernamewssecuritydefault
WSNClientGeneralBinding WebService:/
|
-
[可选步骤] 按照保护传输 [可选] 中的详细说明配置安全传输协议的使用
-
重新启动应用服务器。
-
打开一个 Web 浏览器并创建三个浏览器选项卡(或者打开三个 Web 浏览器),并加载以下 URL(用于 WSN 订阅者、发布者和使用者的 HTTPS URL):
https://localhost:9443/WSNSubscriberWeb/SubscriberServlet
https://localhost:9443/WSNPublisherWeb/PublisherServlet
https://localhost:9443/WSNConsumerWeb/ConsumerServlet
|
如果您要使用不安全的传输协议,则用于 WSN 订阅者、发布者和使用者的 HTTP URL 将如下所示:
http://localhost:9080/WSNSubscriberWeb/SubscriberServlet
http://localhost:9080/WSNPublisherWeb/PublisherServlet
http://localhost:9080/WSNConsumerWeb/ConsumerServlet
|
这些网页显示用于调用 WS-Notification 功能的输入字段和按钮,以及任何请求的结果和所发布及使用的消息。
进行订阅
在 WSN 订阅者的 Web 浏览器中,输入 Broker port address、Broker service name
和 Consumer URI 的值,然后单击 Subscribe,如图 21 中所示。
本文中代理端口地址和使用者 URI 均使用 HTTPS 协议。
WS-Notification 代理的 WSDL 包含代理端口地址和代理服务名称。您可以通过管理控制台上的 Publish WSDL files 查看该 WSDL,也可以通过使用 ?wsdl 查询查看,例如:https://localhost:9443/WSNSecureServiceWSNSecureServicePtNB/Service?wsdl。
图 21. WS-Notification 订阅者
要验证是否加密了 SOAP 消息(消息级安全性的效果,与是否使用传输级安全性无关),您需要打开 Web 服务消息传输跟踪 (com.ibm.ws.websvcs.trace.MessageTrace=all) 来查看该 SOAP 消息。
在 trace.log 中,您可以通过搜索字符串“:Envelop”找到 SOAP 消息。清单 1 中显示了订阅请求 SOAP 消息。由于该消息正文太大,因此本文仅列出了部分 SOAP 消息,“…”表示被删除的加密字符,用粗体显示。由于使用 WS-Security 策略集,因此加密了该消息,使之显示一些随机加密字符,而不显示重要消息(如主题名称等)。
清单 1. 订阅请求 SOAP 消息
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsse:Security xmlns:wsse=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
soapenv:mustUnderstand="1">
<wsu:Timestamp xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="wssecurity_signature_id_21">
<wsu:Created>2009-03-10T21:47:20.241Z
</wsu:Created>
</wsu:Timestamp>
<wsse:BinarySecurityToken xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="x509bst_26" EncodingType=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0
#Base64Binary" ValueType=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">
MIICQzCCAaygAw…
</wsse:BinarySecurityToken>
<enc:EncryptedKey xmlns:enc="http://www.w3.org/2001/04/xmlenc#">
<enc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5">
</enc:EncryptionMethod>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference>
<wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/
oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0
#X509SubjectKeyIdentifier">QdZLf+KjrUg …
</enc:CipherValue>
</enc:CipherData>
<enc:ReferenceList>
<enc:DataReference URI="#wssecurity_encryption_id_27">
</enc:DataReference>
<enc:DataReference URI="#wssecurity_encryption_id_28">
</enc:DataReference>
<enc:DataReference URI="#wssecurity_encryption_id_29">
</enc:DataReference>
</enc:ReferenceList>
</enc:EncryptedKey>
<enc:EncryptedData xmlns:enc="http://www.w3.org/2001/04/xmlenc#"
Id="wssecurity_encryption_id_27" Type="http://www.w3.org/2001/04/xmlenc#Element">
<enc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc">
</enc:EncryptionMethod>
<enc:CipherData>
<enc:CipherValue>3aC/…</enc:CipherValue>
</enc:CipherData>
</enc:EncryptedData>
<enc:EncryptedData xmlns:enc="http://www.w3.org/2001/04/xmlenc#"
Id="wssecurity_encryption_id_29" Type="http://www.w3.org/2001/04/xmlenc#Element">
<enc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc">
</enc:EncryptionMethod>
<enc:CipherData>
<enc:CipherValue>p4Pz6…</enc:CipherValue>
</enc:CipherData>
</enc:EncryptedData>
</wsse:Security>
<wsa:To xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="wssecurity_signature_id_23">
https://localhost:9443/WSNSecureServiceWSNSecureServicePtNB/Service</wsa:To>
<wsa:MessageID xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="wssecurity_signature_id_24">
urn:uuid:B3349624E620E4ED2D1236721647734</wsa:MessageID>
<wsa:Action xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="wssecurity_signature_id_25">
http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest</wsa:Action>
</soapenv:Header>
<soapenv:Body xmlns:wsu=
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="wssecurity_signature_id_22">
<enc:EncryptedData xmlns:enc="http://www.w3.org/2001/04/xmlenc#"
Id="wssecurity_encryption_id_28" Type="http://www.w3.org/2001/04/xmlenc#Content">
<enc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc">
</enc:EncryptionMethod>
<enc:CipherData>
<enc:CipherValue>JznKewK…</enc:CipherValue>
</enc:CipherData>
</enc:EncryptedData>
</soapenv:Body>
</soapenv:Envelope>
|
为了进行对比,以下是未使用消息级安全性的订阅消息。SOAP 消息中显示了用粗体显示的主题名称、使用者 URL 等。
清单 2. 未使用消息级安全性的订阅消息
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>
https://localhost:9443/WSNSecureServiceWSNSecureServicePtNB/Service
</wsa:To>
<wsa:MessageID>
urn:uuid:81DC46116B457C9CD91236876531161
</wsa:MessageID>
<wsa:Action>
http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest
</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<ns3:Subscribe
xmlns="http://docs.oasis-open.org/wsrf/bf-2"
xmlns:ns2="http://www.w3.org/2005/08/addressing"
xmlns:ns3="http://docs.oasis-open.org/wsn/b-2"
xmlns:ns4="http://docs.oasis-open.org/wsrf/rp-2"
xmlns:ns5="http://docs.oasis-open.org/wsn/t-1"
xmlns:ns6="http://docs.oasis-open.org/wsn/br-2"
xmlns:ns7="http://docs.oasis-open.org/wsrf/r-2">
<ns3:ConsumerReference>
<ns2:Address>
"https://localhost:9443/WSNConsumerWeb/PushNotificationConsumer"
</ns2:Address>
</ns3:ConsumerReference>
<ns3:Filter>
<ns3:TopicExpression
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns3:TopicExpressionType"
Dialect="http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple"
xmlns:test="http://wsn.jaxws.dw/topicns01">
test:dW
</ns3:TopicExpression>
</ns3:Filter>
<ns3:InitialTerminationTime>
P1Y
</ns3:InitialTerminationTime>
</ns3:Subscribe>
</soapenv:Body>
</soapenv:Envelope>
|

 |

|
发布消息
在 WSNPublisher 的浏览器选项卡中,输入订阅时使用的 Broker port address 和 Broker service name的值,如图 22 所示。输入您将在 Message payload 字段中发布的消息正文,然后单击 Publish。此步骤将发布消息有效负载。检查 trace.log 中由 WSNPublisher 发布的 SOAP 消息,该消息应该是加密的。
图 22. WS-Notification 发布者
使用消息
导航到 WSN 使用者选项卡,以验证该使用者是否收到了您刚发布的消息。您将需要刷新浏览器,以确保显示最新的使用者状态,如图 23 所示:
图 23. WS-Notification 使用者
检查 trace.log 文件中使用者接收到的 SOAP 消息,该消息应该是加密的。该使用者然后解密了该消息。本文中实施了 WSNConsumer,目的就是为了在 SystemOut.log 中显示该消息内容,如清单 3 中所示:
清单 3. SystemOut.log 中显示的消息内容
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O The consumer has received 1 message(s).
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O Details for message 1:
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O -- Topic dialect: http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O -- Topic expression, including the namespace prefix: wsntopprefix:dW
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O -- Number of namespace mappings in the topic expression: 2
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O ---- Prefix 'b2' maps to namespace 'http://docs.oasis-open.org/wsn/b-2'
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O ---- Prefix 'wsntopprefix' maps to namespace 'http://wsn.jaxws.dw/topicns01'
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O -- Topic expression, without the prefix: dW
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O -- Message payload: Secure WS-Notification test
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O -- Payload namespace: http://wsn.jaxws.dw.ibm.com
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O -- Payload namespace prefix: dW
[02/03/09 23:32:12:625 GMT] 00000024 SystemOut
O -- Payload element name: dWMsg
[02/03/09 23:32:12:641 GMT] 00000024 SystemOut
O -- Subscription ID: sub_352c51ee09165308f5817fdc_11fc987b201_5
|
祝贺您!我们现在已经进行了整个方案的演练。
现在可以通过将您的 WS-Notification 服务与 WS-ReliableMessaging 策略集关联来提高 WS-Notification 消息的可靠性,本系列的后续部分中将讨论该内容。可以在集群环境中将您的 WS-Notification 服务点配置为带有永久主题空间,本系列的后续部分将介绍该内容。
总结
本文解释了如何在安全的 WebSphere Application Server V7.0 中配置带有 WS-Security 的 WS-Notification 的 JAX-WS 新实现。
首先,文章详述了如何配置 WebSphere Application Server 的管理安全性。然后列出了创建和配置 JAX-WS-based WS-Notification 服务的关键步骤。接着,说明了如何创建相应的绑定,以及将策略集和绑定与 WS-Notification 应用程序关联。最后,通过一个演练方案介绍了如何利用 WS-Security 策略集和绑定保护示例 WS-Notification 应用程序。
致谢
作者非常感谢 Alasdair Nottingham、Brian De Pradine、Bill Dodd、Greg Truty、Henry Chung、James Siddle、Lucas Partridge 和 Peter Niblett,感谢他们对本文所作的审阅工作和提出的非常宝贵的意见和建议。Lucas 还提供了示例应用程序。
下载 | 描述 | 名字 | 大小 | 下载方法 |
|---|
| 应用程序示例 | 0904_jiang_JAXWSsampleapp.zip | 711 KB | HTTP |
|---|
参考资料 学习
获得产品和技术
讨论
关于作者  | 
|  | Emily 是在英国的 IBM Hursley Park 工作的一名软件工程师。她在 WebSphere Application Server V7.0 中测试 Web 服务功能,其工作重点是 WS-Notification、WS-Policy、WS-MetadataExchange 和 WS-Security。 |
对本文的评价
|