1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  package org.apache.wss4j.dom.message;
21  
22  import org.apache.wss4j.common.util.SOAPUtil;
23  import org.apache.wss4j.dom.WSConstants;
24  
25  import org.apache.wss4j.dom.engine.WSSConfig;
26  import org.apache.wss4j.dom.engine.WSSecurityEngine;
27  
28  import org.junit.jupiter.api.Test;
29  import org.apache.wss4j.common.crypto.Crypto;
30  import org.apache.wss4j.common.crypto.CryptoFactory;
31  import org.apache.wss4j.common.util.XMLUtils;
32  import org.w3c.dom.Document;
33  
34  
35  
36  
37  
38  public class NoSoapPrefixSignatureTest {
39      private static final org.slf4j.Logger LOG =
40          org.slf4j.LoggerFactory.getLogger(NoSoapPrefixSignatureTest.class);
41      private WSSecurityEngine secEngine = new WSSecurityEngine();
42      private Crypto crypto;
43  
44      public NoSoapPrefixSignatureTest() throws Exception {
45          WSSConfig.init();
46          crypto = CryptoFactory.getInstance();
47      }
48  
49      
50  
51  
52      @Test
53      public void testNoSOAPNamespacePrefix() throws Exception {
54          Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
55          WSSecHeader secHeader = new WSSecHeader(doc);
56          secHeader.setActor("bob");
57          secHeader.insertSecurityHeader();
58  
59          WSSecSignature sign = new WSSecSignature(secHeader);
60          sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
61          sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
62  
63          Document signedDoc = sign.build(crypto);
64  
65          if (LOG.isDebugEnabled()) {
66              String outputString =
67                  XMLUtils.prettyDocumentToString(signedDoc);
68              LOG.debug(outputString);
69          }
70          verify(signedDoc);
71      }
72  
73      
74  
75  
76  
77  
78  
79  
80      private void verify(Document doc) throws Exception {
81          secEngine.processSecurityHeader(doc, null, null, crypto);
82          if (LOG.isDebugEnabled()) {
83              LOG.debug("Verfied and decrypted message:");
84              String outputString =
85                  XMLUtils.prettyDocumentToString(doc);
86              LOG.debug(outputString);
87          }
88      }
89  
90  }