4646import org .springframework .ws .soap .security .AbstractWsSecurityInterceptor ;
4747import org .springframework .ws .soap .security .WsSecuritySecurementException ;
4848import org .springframework .ws .soap .security .WsSecurityValidationException ;
49+ import org .springframework .ws .soap .security .callback .CallbackHandlerChain ;
4950
5051/**
5152 * A WS-Security endpoint interceptor based on Apache's WSS4J. This inteceptor supports messages created by the {@link
5253 * org.springframework.ws.soap.axiom.AxiomSoapMessageFactory} and the {@link org.springframework.ws.soap.saaj.SaajSoapMessageFactory}.
5354 * <p/>
54- * The validation and securement actions executed by this interceptor are configured via <code>validationActions</code> and
55- * <code>securementActions</code> properties, respectively. Actions should be passed as a space-separated strings.
55+ * The validation and securement actions executed by this interceptor are configured via <code>validationActions</code>
56+ * and <code>securementActions</code> properties, respectively. Actions should be passed as a space-separated strings.
5657 * <p/>
5758 * Valid <strong>validation</strong> actions are:
58- *
59- * <blockquote><table>
60- * <tr><th>Validation action</th><th>Description</th></tr>
61- * <tr><td><code>UsernameToken</code></td><td>Validates username token</td></tr>
62- * <tr><td><code>Timestamp</code></td><td>Validates the timestamp</td></tr>
63- * <tr><td><code>Encrypt</code></td><td>Decrypts the message</td></tr>
64- * <tr><td><code>Signature</code></td><td>Validates the signature</td></tr>
65- * <tr><td><code>NoSecurity</code></td><td>No action performed</td></tr>
66- * </table></blockquote>
6759 * <p/>
68- * <strong>Securement</strong> actions are:
69- * <blockquote><table>
70- * <tr><th>Securement action</th><th>Description</th></tr>
71- * <tr><td><code>UsernameToken</td></code><td>Adds a username token</td></tr>
72- * <tr><td><code>UsernameTokenSignature</td></code><td>Adds a username token and a signature username token secrect key</td></tr>
73- * <tr><td><code>Timestamp</td></code><td>Adds a timestamp</td></tr>
74- * <tr><td><code>Encrypt</td></code><td>Encrypts the response</td></tr>
75- * <tr><td><code>Signature</td></code><td>Signs the response</td></tr>
76- * <tr><td><code>NoSecurity</td></code><td>No action performed</td></tr>
77- * </table></blockquote>
60+ * <blockquote><table> <tr><th>Validation action</th><th>Description</th></tr> <tr><td><code>UsernameToken</code></td><td>Validates
61+ * username token</td></tr> <tr><td><code>Timestamp</code></td><td>Validates the timestamp</td></tr>
62+ * <tr><td><code>Encrypt</code></td><td>Decrypts the message</td></tr> <tr><td><code>Signature</code></td><td>Validates
63+ * the signature</td></tr> <tr><td><code>NoSecurity</code></td><td>No action performed</td></tr> </table></blockquote>
7864 * <p/>
79- * The order of the actions that the client performed to secure the messages is significant and is
80- * enforced by the interceptor.
81- *
65+ * <strong>Securement</strong> actions are: <blockquote><table> <tr><th>Securement action</th><th>Description</th></tr>
66+ * <tr><td><code>UsernameToken</td></code><td>Adds a username token</td></tr> <tr><td><code>UsernameTokenSignature</td></code><td>Adds
67+ * a username token and a signature username token secrect key</td></tr> <tr><td><code>Timestamp</td></code><td>Adds a
68+ * timestamp</td></tr> <tr><td><code>Encrypt</td></code><td>Encrypts the response</td></tr>
69+ * <tr><td><code>Signature</td></code><td>Signs the response</td></tr> <tr><td><code>NoSecurity</td></code><td>No action
70+ * performed</td></tr> </table></blockquote>
71+ * <p/>
72+ * The order of the actions that the client performed to secure the messages is significant and is enforced by the
73+ * interceptor.
8274 *
8375 * @author Tareq Abed Rabbo
8476 * @author Arjen Poutsma
@@ -89,8 +81,6 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl
8981
9082 public static final String SECUREMENT_USER_PROPERTY_NAME = "Wss4jSecurityInterceptor.securementUser" ;
9183
92- private CallbackHandler validationCallbackHandler ;
93-
9484 private int securementAction ;
9585
9686 private String securementActions ;
@@ -99,9 +89,7 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl
9989
10090 private String securementUsername ;
10191
102- private boolean timestampStrict = true ;
103-
104- private int timeToLive = 300 ;
92+ private CallbackHandler validationCallbackHandler ;
10593
10694 private int validationAction ;
10795
@@ -115,10 +103,14 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl
115103
116104 private Crypto validationSignatureCrypto ;
117105
118- private Wss4jHandler handler = new Wss4jHandler () ;
106+ private boolean timestampStrict = true ;
119107
120108 private boolean enableSignatureConfirmation ;
121109
110+ private int timeToLive = 300 ;
111+
112+ private Wss4jHandler handler = new Wss4jHandler ();
113+
122114 public void setSecurementActions (String securementActions ) {
123115 this .securementActions = securementActions ;
124116 securementActionsVector = new Vector ();
@@ -141,10 +133,24 @@ public void setSecurementActor(String securementActor) {
141133 handler .setOption (WSHandlerConstants .ACTOR , securementActor );
142134 }
143135
136+ /**
137+ * Sets the {@link org.apache.ws.security.WSPasswordCallback} handler to use when securing messages.
138+ *
139+ * @see #setSecurementCallbackHandlers(CallbackHandler[])
140+ */
144141 public void setSecurementCallbackHandler (CallbackHandler securementCallbackHandler ) {
145142 handler .setSecurementCallbackHandler (securementCallbackHandler );
146143 }
147144
145+ /**
146+ * Sets the {@link org.apache.ws.security.WSPasswordCallback} handlers to use when securing messages.
147+ *
148+ * @see #setSecurementCallbackHandler(CallbackHandler)
149+ */
150+ public void setSecurementCallbackHandlers (CallbackHandler [] securementCallbackHandler ) {
151+ handler .setSecurementCallbackHandler (new CallbackHandlerChain (securementCallbackHandler ));
152+ }
153+
148154 public void setSecurementEncryptionCrypto (Crypto securementEncryptionCrypto ) {
149155 handler .setSecurementEncryptionCrypto (securementEncryptionCrypto );
150156 }
@@ -333,10 +339,24 @@ public void setValidationActor(String validationActor) {
333339 this .validationActor = validationActor ;
334340 }
335341
342+ /**
343+ * Sets the {@link org.apache.ws.security.WSPasswordCallback} handler to use when validating messages.
344+ *
345+ * @see #setValidationCallbackHandlers(CallbackHandler[])
346+ */
336347 public void setValidationCallbackHandler (CallbackHandler callbackHandler ) {
337348 this .validationCallbackHandler = callbackHandler ;
338349 }
339350
351+ /**
352+ * Sets the {@link org.apache.ws.security.WSPasswordCallback} handlers to use when validating messages.
353+ *
354+ * @see #setValidationCallbackHandler(CallbackHandler)
355+ */
356+ public void setValidationCallbackHandlers (CallbackHandler [] callbackHandler ) {
357+ this .validationCallbackHandler = new CallbackHandlerChain (callbackHandler );
358+ }
359+
340360 /** Sets the Crypto to use to decrypt incoming messages */
341361 public void setValidationDecryptionCrypto (Crypto decryptionCrypto ) {
342362 this .validationDecryptionCrypto = decryptionCrypto ;
@@ -410,6 +430,9 @@ protected void secureMessage(SoapMessage soapMessage, MessageContext messageCont
410430 if (securementAction == WSConstants .NO_SECURITY && !enableSignatureConfirmation ) {
411431 return ;
412432 }
433+ if (logger .isDebugEnabled ()) {
434+ logger .debug ("Securing message [" + soapMessage + "] with actions [" + securementActions + "]" );
435+ }
413436 RequestData requestData = initializeRequestData (messageContext );
414437
415438 Document envelopeAsDocument = toDocument (soapMessage );
@@ -450,7 +473,7 @@ private RequestData initializeRequestData(MessageContext messageContext) {
450473 protected void validateMessage (SoapMessage soapMessage , MessageContext messageContext )
451474 throws WsSecurityValidationException {
452475 if (logger .isDebugEnabled ()) {
453- logger .debug ("Validating message [" + soapMessage + "] with actions " + validationActions );
476+ logger .debug ("Validating message [" + soapMessage + "] with actions [ " + validationActions + "]" );
454477 }
455478
456479 if (validationAction == WSConstants .NO_SECURITY ) {
@@ -508,11 +531,7 @@ private void updateContextWithResults(MessageContext messageContext, Vector resu
508531 messageContext .setProperty (WSHandlerConstants .RECV_RESULTS , handlerResults );
509532 }
510533
511- /**
512- * Verifies the trust of a certificate.
513- * @param results
514- * @throws WSSecurityException
515- */
534+ /** Verifies the trust of a certificate. */
516535 protected void verifyCertificateTrust (Vector results ) throws WSSecurityException {
517536 RequestData requestData = new RequestData ();
518537 requestData .setSigCrypto (validationSignatureCrypto );
0 commit comments