Securing SOAP with WS-Security: A Practical Guide
The OASIS Web Services Security (WS-Security) 1.0 specification, published in April 2002, defines a framework for attaching security credentials to SOAP messages. While the specification itself is thorough, practical guidance on implementing WS-Security across different application servers remains scarce. This article attempts to fill that gap with working examples for the three most common enterprise SOAP stacks.
The core mechanism of WS-Security is the <wsse:Security> SOAP header block, which carries security tokens (UsernameToken, X.509 certificates, Kerberos tickets), XML Signatures over message elements, and XML Encryption of sensitive data. The key insight that WS-Security provides over transport-level SSL is that security properties travel with the message through intermediaries. In a multi-hop SOAP processing chain where a message passes through routing nodes or transformation engines, SSL protects only the immediate link, while WS-Security protects the message end-to-end.
This article covers: constructing UsernameToken with password digest, signing SOAP body elements with X.509 certificates, encrypting sensitive elements with symmetric keys wrapped in the recipient's public key, and handling timestamp validation to prevent replay attacks. Code samples are provided for BEA WebLogic 8.1, IBM WebSphere 5.0, and Apache Axis 1.1 with the WSS4J library.