33import java .util .Set ;
44import java .util .HashSet ;
55import java .util .Properties ;
6+ import javax .crypto .KeyGenerator ;
7+ import javax .crypto .SecretKey ;
68import javax .xml .namespace .QName ;
79import javax .xml .transform .*;
810import javax .xml .transform .dom .DOMResult ;
1214import jakarta .xml .ws .handler .soap .SOAPMessageContext ;
1315import jakarta .xml .soap .*;
1416import javax .xml .parsers .DocumentBuilderFactory ;
15- import org .apache .ws .security .components .crypto .Crypto ;
16- import org .apache .ws .security .components .crypto .CryptoFactory ;
17- import org .apache .ws .security .message .WSSecEncrypt ;
18- import org .apache .ws .security .message .WSSecHeader ;
19- import org .apache .ws .security .message .WSSecSignature ;
20- import org .apache .ws .security .message .WSSecTimestamp ;
17+
18+ import org .apache .wss4j .common .crypto .Crypto ;
19+ import org .apache .wss4j .common .crypto .CryptoFactory ;
20+ import org .apache .wss4j .dom .message .WSSecEncrypt ;
21+ import org .apache .wss4j .dom .message .WSSecHeader ;
22+ import org .apache .wss4j .dom .message .WSSecSignature ;
23+ import org .apache .wss4j .dom .message .WSSecTimestamp ;
24+
2125import org .w3c .dom .*;
2226import java .io .InputStream ;
2327import java .io .ByteArrayInputStream ;
2630import com .genexus .diagnostics .core .LogManager ;
2731import com .genexus .common .interfaces .*;
2832
33+ import static org .apache .wss4j .common .util .KeyUtils .getKeyGenerator ;
34+
2935public class GXHandlerConsumerChain implements SOAPHandler <SOAPMessageContext >
3036{
3137 public static final ILogger logger = LogManager .getLogger (GXHandlerConsumerChain .class );
@@ -156,8 +162,8 @@ public boolean handleMessage(SOAPMessageContext messageContext)
156162 Document doc = messageToDocument (messageContext .getMessage ());
157163
158164 //Security header
159- WSSecHeader secHeader = new WSSecHeader ();
160- secHeader .insertSecurityHeader (doc );
165+ WSSecHeader secHeader = new WSSecHeader (doc );
166+ secHeader .insertSecurityHeader ();
161167 Document signedDoc = null ;
162168
163169 //Signature
@@ -168,7 +174,7 @@ public boolean handleMessage(SOAPMessageContext messageContext)
168174 signatureProperties .put ("org.apache.ws.security.crypto.merlin.keystore.password" , wsSignature .getKeystore ().getPassword ());
169175 signatureProperties .put ("org.apache.ws.security.crypto.merlin.file" , wsSignature .getKeystore ().getSource ());
170176 Crypto signatureCrypto = CryptoFactory .getInstance (signatureProperties );
171- WSSecSignature sign = new WSSecSignature ();
177+ WSSecSignature sign = new WSSecSignature (doc );
172178 sign .setKeyIdentifierType (wsSignature .getKeyIdentifierType ());
173179 sign .setUserInfo (wsSignature .getAlias (), wsSignature .getKeystore ().getPassword ());
174180 if (wsSignature .getCanonicalizationalgorithm () != null )
@@ -177,13 +183,13 @@ public boolean handleMessage(SOAPMessageContext messageContext)
177183 sign .setDigestAlgo (wsSignature .getDigest ());
178184 if (wsSignature .getSignaturealgorithm () != null )
179185 sign .setSignatureAlgorithm (wsSignature .getSignaturealgorithm ());
180- signedDoc = sign .build (doc , signatureCrypto , secHeader );
186+ signedDoc = sign .build ( signatureCrypto );
181187
182188 if (expirationTimeout > 0 )
183189 {
184- WSSecTimestamp timestamp = new WSSecTimestamp ();
190+ WSSecTimestamp timestamp = new WSSecTimestamp (secHeader );
185191 timestamp .setTimeToLive (expirationTimeout );
186- signedDoc = timestamp .build (signedDoc , secHeader );
192+ signedDoc = timestamp .build ();
187193 }
188194 }
189195
@@ -195,14 +201,19 @@ public boolean handleMessage(SOAPMessageContext messageContext)
195201 encryptionProperties .put ("org.apache.ws.security.crypto.merlin.keystore.password" , wsEncryption .getKeystore ().getPassword ());
196202 encryptionProperties .put ("org.apache.ws.security.crypto.merlin.file" , wsEncryption .getKeystore ().getSource ());
197203 Crypto encryptionCrypto = CryptoFactory .getInstance (encryptionProperties );
198- WSSecEncrypt builder = new WSSecEncrypt ();
199- builder .setUserInfo (wsEncryption .getAlias (), wsEncryption .getKeystore ().getPassword ());
200- builder .setKeyIdentifierType (wsEncryption .getKeyIdentifierType ());
201204 if (signedDoc == null )
202205 {
203206 signedDoc = doc ;
204207 }
205- builder .build (signedDoc , encryptionCrypto , secHeader );
208+ WSSecEncrypt builder = new WSSecEncrypt (signedDoc );
209+ builder .setUserInfo (wsEncryption .getAlias (), wsEncryption .getKeystore ().getPassword ());
210+ builder .setKeyIdentifierType (wsEncryption .getKeyIdentifierType ());
211+ //using wss4j default encryption algorithm AES128-CBC
212+ KeyGenerator keyGenerator = KeyGenerator .getInstance ("AES" );
213+ keyGenerator .init (128 );
214+ SecretKey key = keyGenerator .generateKey ();
215+
216+ builder .build (encryptionCrypto , key );
206217 }
207218
208219 Document securityDoc = doc ;
0 commit comments