46
46
import org .springframework .ws .soap .security .AbstractWsSecurityInterceptor ;
47
47
import org .springframework .ws .soap .security .WsSecuritySecurementException ;
48
48
import org .springframework .ws .soap .security .WsSecurityValidationException ;
49
+ import org .springframework .ws .soap .security .callback .CallbackHandlerChain ;
49
50
50
51
/**
51
52
* A WS-Security endpoint interceptor based on Apache's WSS4J. This inteceptor supports messages created by the {@link
52
53
* org.springframework.ws.soap.axiom.AxiomSoapMessageFactory} and the {@link org.springframework.ws.soap.saaj.SaajSoapMessageFactory}.
53
54
* <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.
56
57
* <p/>
57
58
* 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>
67
59
* <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>
78
64
* <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.
82
74
*
83
75
* @author Tareq Abed Rabbo
84
76
* @author Arjen Poutsma
@@ -89,8 +81,6 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl
89
81
90
82
public static final String SECUREMENT_USER_PROPERTY_NAME = "Wss4jSecurityInterceptor.securementUser" ;
91
83
92
- private CallbackHandler validationCallbackHandler ;
93
-
94
84
private int securementAction ;
95
85
96
86
private String securementActions ;
@@ -99,9 +89,7 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl
99
89
100
90
private String securementUsername ;
101
91
102
- private boolean timestampStrict = true ;
103
-
104
- private int timeToLive = 300 ;
92
+ private CallbackHandler validationCallbackHandler ;
105
93
106
94
private int validationAction ;
107
95
@@ -115,10 +103,14 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl
115
103
116
104
private Crypto validationSignatureCrypto ;
117
105
118
- private Wss4jHandler handler = new Wss4jHandler () ;
106
+ private boolean timestampStrict = true ;
119
107
120
108
private boolean enableSignatureConfirmation ;
121
109
110
+ private int timeToLive = 300 ;
111
+
112
+ private Wss4jHandler handler = new Wss4jHandler ();
113
+
122
114
public void setSecurementActions (String securementActions ) {
123
115
this .securementActions = securementActions ;
124
116
securementActionsVector = new Vector ();
@@ -141,10 +133,24 @@ public void setSecurementActor(String securementActor) {
141
133
handler .setOption (WSHandlerConstants .ACTOR , securementActor );
142
134
}
143
135
136
+ /**
137
+ * Sets the {@link org.apache.ws.security.WSPasswordCallback} handler to use when securing messages.
138
+ *
139
+ * @see #setSecurementCallbackHandlers(CallbackHandler[])
140
+ */
144
141
public void setSecurementCallbackHandler (CallbackHandler securementCallbackHandler ) {
145
142
handler .setSecurementCallbackHandler (securementCallbackHandler );
146
143
}
147
144
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
+
148
154
public void setSecurementEncryptionCrypto (Crypto securementEncryptionCrypto ) {
149
155
handler .setSecurementEncryptionCrypto (securementEncryptionCrypto );
150
156
}
@@ -333,10 +339,24 @@ public void setValidationActor(String validationActor) {
333
339
this .validationActor = validationActor ;
334
340
}
335
341
342
+ /**
343
+ * Sets the {@link org.apache.ws.security.WSPasswordCallback} handler to use when validating messages.
344
+ *
345
+ * @see #setValidationCallbackHandlers(CallbackHandler[])
346
+ */
336
347
public void setValidationCallbackHandler (CallbackHandler callbackHandler ) {
337
348
this .validationCallbackHandler = callbackHandler ;
338
349
}
339
350
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
+
340
360
/** Sets the Crypto to use to decrypt incoming messages */
341
361
public void setValidationDecryptionCrypto (Crypto decryptionCrypto ) {
342
362
this .validationDecryptionCrypto = decryptionCrypto ;
@@ -410,6 +430,9 @@ protected void secureMessage(SoapMessage soapMessage, MessageContext messageCont
410
430
if (securementAction == WSConstants .NO_SECURITY && !enableSignatureConfirmation ) {
411
431
return ;
412
432
}
433
+ if (logger .isDebugEnabled ()) {
434
+ logger .debug ("Securing message [" + soapMessage + "] with actions [" + securementActions + "]" );
435
+ }
413
436
RequestData requestData = initializeRequestData (messageContext );
414
437
415
438
Document envelopeAsDocument = toDocument (soapMessage );
@@ -450,7 +473,7 @@ private RequestData initializeRequestData(MessageContext messageContext) {
450
473
protected void validateMessage (SoapMessage soapMessage , MessageContext messageContext )
451
474
throws WsSecurityValidationException {
452
475
if (logger .isDebugEnabled ()) {
453
- logger .debug ("Validating message [" + soapMessage + "] with actions " + validationActions );
476
+ logger .debug ("Validating message [" + soapMessage + "] with actions [ " + validationActions + "]" );
454
477
}
455
478
456
479
if (validationAction == WSConstants .NO_SECURITY ) {
@@ -508,11 +531,7 @@ private void updateContextWithResults(MessageContext messageContext, Vector resu
508
531
messageContext .setProperty (WSHandlerConstants .RECV_RESULTS , handlerResults );
509
532
}
510
533
511
- /**
512
- * Verifies the trust of a certificate.
513
- * @param results
514
- * @throws WSSecurityException
515
- */
534
+ /** Verifies the trust of a certificate. */
516
535
protected void verifyCertificateTrust (Vector results ) throws WSSecurityException {
517
536
RequestData requestData = new RequestData ();
518
537
requestData .setSigCrypto (validationSignatureCrypto );
0 commit comments