Web Service 安全性缺省配置

Web Service 安全性 (WS-Security) 配置是对运行时 WS-Security 策略的补充。WS-Security 配置遵循 CXF 名称/值对样式,并且保留 CXF 属性名。某些属性具有缺省值,而某些属性则没有。

server.xml 文件中,WebSphere® Application Server Liberty 提供了适用于所有服务的服务器级配置。此配置称为缺省 WS-Security 配置。

server.xml 文件具有两个缺省 WS-Security 配置:一个配置适用于客户机应用程序,另一个配置适用于提供者应用程序。server.xml 文件中不能存在其他 WS-Security 配置。如果您需要应用程序具有不同于缺省配置的定制 WS-Security 配置,那么必须通过程序来完成配置。

以下示例显示了缺省客户机配置:
<wsSecurityClient id="default"
                  ws-security.username="user2"
                  ws-security.password="security">
  <signatureProperties org.apache.ws.security.crypto.merlin.keystore.type="jks"
                       org.apache.ws.security.crypto.merlin.keystore.password="LibertyX509Client"
                       org.apache.ws.security.crypto.merlin.keystore.alias="x509ClientCert"
                       org.apache.ws.security.crypto.merlin.file="${server.config.dir}/x509ClientDefault.jks"/>
</wsSecurityClient>
以下示例显示了缺省提供者配置:
<wsSecurityProvider id="default"
                    ws-security.username="user2">
  <encryptionProperties org.apache.ws.security.crypto.merlin.keystore.type="jks"
                        org.apache.ws.security.crypto.merlin.keystore.password="LibertyX509Server"
                        org.apache.ws.security.crypto.merlin.keystore.alias="x509ServerCert"
                        org.apache.ws.security.crypto.merlin.file="${server.config.dir}/x509ServerDefault.jks"/>
</wsSecurityProvider>
下表显示了 Liberty 中的缺省 WS-Security 用户属性。可以在 CXF 中找到这些相同的属性。
表 1. Liberty 和 CXF 中的缺省 WS-Security 用户属性
Liberty/CXF 属性 缺省值
ws-security.username
ws-security.password
ws-security.signature.username
ws-security.encryption.username
下表显示了 Liberty 中的 WS-Security 回调处理程序类和 crypto 属性以及等效的 CXF 属性(如果这些属性不同)。
表 2. Liberty 中的 WS-Security 回调处理程序类和 crypto 属性以及等效的 CXF 属性
Libertyproperty CXF 属性 缺省值
ws-security.callback-handler  
<signatureProperties> ws-security.signature.properties
<encryptionProperties> ws-security.encryption.properties
在 WebSphere Application Server 中,wss4j 属性指定为 signaturePropertiesencryptionProperties 元素的属性。以下示例显示了 wss4j 属性:
<signatureProperties org.apache.ws.security.crypto.merlin.keystore.type="jks"
                     org.apache.ws.security.crypto.merlin.keystore.password="LibertyX509Client"
                     org.apache.ws.security.crypto.merlin.keystore.alias="x509ClientDefault"
                     org.apache.ws.security.crypto.merlin.file="${server.config.dir}/x509ClientDefault.jks">
</signatureProperties>
下表显示了 Liberty 中的 wss4j crypto 属性。可以在 CXF 中找到这些相同的属性。
表 3. Liberty 和 CXF 中的 wss4j crypto 属性
Liberty/CXF 属性 缺省值
org.apache.ws.security.crypto.provider

org.apache.ws.security.components.
crypto.Merlin

org.apache.ws.security.crypto.
merlin.keystore.provider

缺省为所安装的提供者

org.apache.ws.security.crypto.
merlin.cert.provider

缺省为密钥库提供者

org.apache.ws.security.crypto.
merlin.x509crl.file

下表显示了 Liberty 中的 wss4j 密钥库属性。可以在 CXF 中找到这些相同的属性。
表 4. Liberty 和 CXF 中的 wss4j 密钥库属性
Liberty/CXF 属性 缺省值

org.apache.ws.security.crypto.
merlin.keystore.file

org.apache.ws.security.crypto.
merlin.keystore.password

org.apache.ws.security.crypto.
merlin.keystore.type

org.apache.ws.security.crypto.
merlin.keystore.alias

org.apache.ws.security.crypto.
merlin.keystore.private.password

下表显示了 Liberty 中的 wss4j truststore 属性。可以在 CXF 中找到这些相同的属性。
表 5. Liberty 和 CXF 中的 wss4j truststore 属性
Libertyproperty 缺省值

org.apache.ws.security.crypto.
merlin.truststore.file

org.apache.ws.security.crypto.
merlin.truststore.password

org.apache.ws.security.crypto.
merlin.truststore.type

下表显示了 Liberty 中的 WS-Security 其他属性。可以在 CXF 中找到这些相同的属性。
表 6. Liberty 和 CXF 中的 WS-Security 其他属性
Liberty/CXF 属性 缺省值
ws-security.enable.nonce.cache true
ws-security.cache.config.file
下表显示了仅在 Liberty 中受支持的属性。
表 7. 仅在 Liberty 中受支持的属性
Libertyproperty CXF 属性 缺省值
callerToken

配置其他属性

您可以设置若干额外的属性,以向 WS-Security 运行时环境提供其他配置信息。请参阅下列链接以了解有关这些属性的详细信息:

可以在 server.xml 文件中的缺省 WS-Security 配置中指定任何其他属性。

例如,要指定任何其他属性,请在 wsSecurityClient 和/或 wsSecurityProvider 部分指定这些属性。
<wsSecurityProvider id="default"
  <signatureProperties ... />
  <encryptionProperties ... />
  ws-security.cache.config.file = "${server.config.dir}/resources/ws-security/new_cxf-ehcache.xml"
</wsSecurityProvider>

<wsSecurityClient id="default"
  <signatureProperties ... />
  <encryptionProperties ... />
  ws-security.username-token.always.encrypted="false"
</wsSecurityClient>

配置高速缓存

WS-Security 提供了 UsernameToken 中的 noncecreated 时间戳记和安全性令牌的缺省高速缓存实现。缺省高速缓存实现基于 ehCache,并且具有下列缺省设置:
maxEntriesLocalHeap="5000"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"

要修改缺省高速缓存设置,您可以提供 ehCache 配置 XML 文件。使用 ws-security.cache.config.file 定制属性来指定具有定制的属性的文件名以不同于缺省设置。必须将此文件放入服务器概要文件中的某个位置。可以从以下网址找到另外的样本高速缓存设置配置文件:http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/resources/cxf-ehcache.xml?view=markup

配置更强大的签名算法

因为 SHA1 签名算法较脆弱,所以美国国家标准技术学会 (NIST) 建议您使用更强大的签名算法。

但是,WS-Security 策略 1.3 定义了 HmacSha1 或 RsaSha1(统称为 sha1)作为唯一的签名算法。Liberty 中的 WS-Security 有一个使用以下更强大的签名算法的配置选项:
  • RSA-SHA-256
  • RSA-SHA-384
  • RSA-SHA-512
  • HMAC-SHA-256
  • HMAC-SHA-384
  • HMAC-SHA-512

要配置 Liberty 中的 WS-Security 以支持更强大的签名算法,请使用 signatureAlgorithm 属性在 server.xml 文件的 <signatureProperties> 元素中定义必需的算法。signatureAlgorithm 属性的有效值为 sha256、sha384 和 sha512。例如,如果您将 signatureAlgorithm 属性的值指定为 sha512,那么在具有非对称密钥的签名中使用的签名算法为 RSA-SHA-512,而在具有对称密钥的签名中使用的签名算法为 HMAC-SHA-512。

以下示例显示了一个需要 sha256 签名算法的样本客户端配置:
<wsSecurityClient id="default"
  ws-security.password="security"
  ws-security.username="user1"
  ws-security.callback-handler="com.ibm.ws.wssecurity.example.cbh.CommonPasswordCallback"
  ws-security.signature.username="soaprequester">
  <signatureProperties
    signatureAlgorithm="sha256"
    org.apache.ws.security.crypto.merlin.keystore.type="jks"
    org.apache.ws.security.crypto.merlin.keystore.password="client"
    org.apache.ws.security.crypto.merlin.keystore.alias="soaprequester"
    org.apache.ws.security.crypto.merlin.file="${server.config.dir}/dsig-sender.ks" />
</wsSecurityClient>
以下示例显示了一个需要 sha256 签名算法的样本提供程序端配置:
<wsSecurityProvider id="default"
  ws-security.callback-handler="com.ibm.ws.wssecurity.example.cbh.CommonPasswordCallback"
  ws-security.signature.username="soapprovider">
  <signatureProperties
    signatureAlgorithm="sha256"
    org.apache.ws.security.crypto.merlin.keystore.type="jks"
    org.apache.ws.security.crypto.merlin.keystore.password="server"
    org.apache.ws.security.crypto.merlin.keystore.alias="soapprovider"
    org.apache.ws.security.crypto.merlin.file="${server.config.dir}/dsig-receiver.ks" /> 
</wsSecurityProvider>

用于指示主题类型的图标 概念主题

文件名:cwlp_wssec_defaultconfig.html