This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • WS-SecurityPolicy
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 22 Next »


CXF 2.2 introduced support for using WS-SecurityPolicy to configure WSS4J instead of the custom configuration documented on the WS-Security page. However, all of the "background" material on the WS-Security page still applies and is important to know. WS-SecurityPolicy just provides an easier and more standards based way to configure and control the security requirements. With the security requirements documented in the WSDL as WS-Policy fragments, other tools such as .NET can easily know how to configure themselves to inter-operate with CXF services.

Enabling WS-SecurityPolicy

In CXF 2.2, if the cxf-rt-ws-policy and cxf-rt-ws-security modules are available on the classpath, the WS-SecurityPolicy stuff is automatically enabled. Since the entire security runtime is policy driven, the only requirement is that the policy engine and security policies be available.

If you are using the full "bundle" jar, all the security and policy stuff is already included.

Policy description

With WS-SecurityPolicy, the binding and/or operation in the wsdl references a WS-Policy fragment that describes the basic security requirements for interacting with that service. The WS-SecurityPolicy specification allows for specifying things like asymmetric/symmetric keys, using transports (https) for encryption, which parts/headers to encrypt or sign, whether to sign then encrypt or encrypt then sign, whether to include timestamps, whether to use derived keys, etc... Basically, it describes what actions are necessary to securely interact with the service described in the WSDL.

However, the WS-SecurityPolicy fragment does not include "everything" that is required for a runtime to be able to able to create the messages. It does not describe things such as locations of key stores, user names and passwords, etc... Those need to be configured in at runtime to augment the WS-SecurityPolicy fragment.

Configuring the extra properties

There are several extra properties that may need to be set to provide the additional bits of information to the runtime. Note that you should check that a particular property is supported in the version of CXF you are using.

User properties


The user's name. It is used differently by each of the WS-Security functions, see here for more information.


The user's password when "ws-security.callback-handler" is not defined. It is currently only used for the case of adding a password to a UsernameToken.


The user's name for signature. It is used as the alias name in the keystore to get the user's cert and private key for signature. See here for more information.


The user's name for encryption. It is used as the alias name in the keystore to get the user's public key for encryption. See here for more information.

Callback Class and Crypto properties


The CallbackHandler implementation class used to obtain passwords.


The SAML CallbackHandler implementation class used to construct SAML Assertions.

The Crypto property configuration to use for signature, if "ws-security.signature.crypto" is not set instead.

The Crypto property configuration to use for encryption, if "ws-security.encryption.crypto" is not set instead.


A Crypto object to be used for signature. If this is not defined then "" is used instead.


A Crypto object to be used for encryption. If this is not defined then "" is used instead.

Boolean WS-Security configuration tags, e.g. the value should be "true" or "false".


Whether to validate the password of a received UsernameToken or not. The default is true.


Whether to enable Certificate Revocation List (CRL) checking or not when verifying trust in a certificate. The default value is "false".


Whether to always encrypt UsernameTokens whenever possible. The default is true.

Whether to ensure compliance with the Basic Security Profile (BSP) 1.1 or not. The default value is "true".


Whether to self-sign a SAML Assertion or not. If this is set to true, then an enveloped signature will be generated when the SAML Assertion is constructed. The default is false.


Whether to cache UsernameToken nonces. See here for more information.


Whether to cache Timestamp Created Strings. See here for more information.

Non-boolean WS-Security Configuration parameters


The time in seconds after Creation that an incoming Timestamp is valid for. The default value is 300 seconds (5 minutes).


The time in seconds in the future within which the Created time of an incoming Timestamp is valid. The default value is "60". See here for more information.


The attribute URI of the SAML AttributeStatement where the role information is stored. The default is "".


A reference to the KerberosClient class used to obtain a service ticket.


The SpnegoClientAction implementation to use for SPNEGO. This allows the user to plug in a different implementation to obtain a service ticket.


The JAAS Context name to use for Kerberos. This is currently only supported for SPNEGO.


The Kerberos Service Provider Name (spn) to use. This is currently only supported for SPNEGO.


This holds a reference to a ReplayCache instance used to cache UsernameToken nonces. The default instance that is used is the EHCacheReplayCache.


This holds a reference to a ReplayCache instance used to cache Timestamp Created Strings. The default instance that is used is the EHCacheReplayCache.


Set this property to point to a configuration file for the underlying caching implementation. The default configuration file that is used is cxf-ehcache.xml in the cxf-rt-ws-security module.

The TokenStore instance to use to cache security tokens. By default this uses the EHCacheTokenStore if EhCache is available. Otherwise it uses the MemoryTokenStore.


A comma separated String of regular expressions which will be applied to the subject DN of the certificate used for signature validation, after trust verification of the certificate chain associated with the certificate. These constraints are not used when the certificate is contained in the keystore (direct trust).

Note: for Symmetric bindings that specify a protection token, the ws-security-encryption properties are used.

Configuring via Spring

The properties are easily configured as client or endpoint properties--use the former for the SOAP client, the latter for the web service provider.

<beans xmlns=""

   <jaxws:client name="{}MyPortName"
         <entry key="ws-security.callback-handler"
         <entry key=""
         <entry key=""
         <entry key="ws-security.encryption.username"


For the jaxws:client's name attribute above, use the namespace of the WSDL along with the name attribute of the desired wsdl:port element under the WSDL's service section. (See here and here for an example.)

<beans xmlns=""


         <entry key="ws-security.callback-handler"
         <entry key=""
         <entry key=""
         <entry key="ws-security.encryption.username"


See this blog entry for a more end-to-end example of using WS-SecurityPolicy with X.509 keys.

Configuring via API's

Configuring the properties for the client just involves setting the properties in the client's RequestContext:

Map<String, Object> ctx = ((BindingProvider)port).getRequestContext();
ctx.put("", properties);
  • No labels