|
17 | 17 | package org.springframework.ws.soap.security.wss4j2; |
18 | 18 |
|
19 | 19 | import org.apache.wss4j.common.crypto.Merlin; |
| 20 | +import org.apache.wss4j.dom.WSConstants; |
| 21 | +import org.apache.wss4j.dom.engine.WSSConfig; |
| 22 | +import org.apache.wss4j.dom.validate.Validator; |
20 | 23 | import org.junit.jupiter.api.Test; |
21 | 24 | import org.w3c.dom.Document; |
22 | 25 |
|
|
25 | 28 | import org.springframework.ws.soap.SoapMessage; |
26 | 29 | import org.springframework.ws.soap.security.wss4j2.support.CryptoFactoryBean; |
27 | 30 |
|
| 31 | +import static org.mockito.ArgumentMatchers.any; |
| 32 | +import static org.mockito.Mockito.mock; |
| 33 | +import static org.mockito.Mockito.times; |
| 34 | +import static org.mockito.Mockito.verify; |
| 35 | + |
28 | 36 | public abstract class Wss4jMessageInterceptorX509Test extends Wss4jTest { |
29 | 37 |
|
30 | 38 | protected Wss4jSecurityInterceptor interceptor; |
@@ -67,4 +75,25 @@ public void testAddCertificate() throws Exception { |
67 | 75 | this.interceptor.validateMessage(message, messageContext); |
68 | 76 | } |
69 | 77 |
|
| 78 | + @Test |
| 79 | + void validateSignatureWithWssConfig() throws Exception { |
| 80 | + this.interceptor.setSecurementPassword("123456"); |
| 81 | + this.interceptor.setSecurementUsername("rsaKey"); |
| 82 | + SoapMessage message = loadSoap11Message("empty-soap.xml"); |
| 83 | + MessageContext messageContext = getSoap11MessageContext(message); |
| 84 | + |
| 85 | + this.interceptor.setSecurementSignatureKeyIdentifier("DirectReference"); |
| 86 | + |
| 87 | + this.interceptor.secureMessage(message, messageContext); |
| 88 | + Document document = getDocument(message); |
| 89 | + assertXpathExists("Absent BinarySecurityToken element", |
| 90 | + "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:BinarySecurityToken", document); |
| 91 | + WSSConfig wssConfig = WSSConfig.getNewInstance(); |
| 92 | + Validator validator = mock(Validator.class); |
| 93 | + wssConfig.setValidator(WSConstants.SIGNATURE, validator); |
| 94 | + this.interceptor.setWssConfig(wssConfig); |
| 95 | + this.interceptor.validateMessage(message, messageContext); |
| 96 | + verify(validator, times(2)).validate(any(), any()); // Also SignatureProcessor |
| 97 | + } |
| 98 | + |
70 | 99 | } |
0 commit comments