33import java .util .Set ;
44import java .util .HashSet ;
55import java .util .Properties ;
6- import javax .crypto .KeyGenerator ;
7- import javax .crypto .SecretKey ;
86import javax .xml .namespace .QName ;
97import javax .xml .transform .*;
108import javax .xml .transform .dom .DOMResult ;
1412import jakarta .xml .ws .handler .soap .SOAPMessageContext ;
1513import jakarta .xml .soap .*;
1614import javax .xml .parsers .DocumentBuilderFactory ;
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-
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 ;
2521import org .w3c .dom .*;
2622import java .io .InputStream ;
2723import java .io .ByteArrayInputStream ;
3026import com .genexus .diagnostics .core .LogManager ;
3127import com .genexus .common .interfaces .*;
3228
33- import static org .apache .wss4j .common .util .KeyUtils .getKeyGenerator ;
34-
3529public class GXHandlerConsumerChain implements SOAPHandler <SOAPMessageContext >
3630{
3731 public static final ILogger logger = LogManager .getLogger (GXHandlerConsumerChain .class );
@@ -162,8 +156,8 @@ public boolean handleMessage(SOAPMessageContext messageContext)
162156 Document doc = messageToDocument (messageContext .getMessage ());
163157
164158 //Security header
165- WSSecHeader secHeader = new WSSecHeader (doc );
166- secHeader .insertSecurityHeader ();
159+ WSSecHeader secHeader = new WSSecHeader ();
160+ secHeader .insertSecurityHeader (doc );
167161 Document signedDoc = null ;
168162
169163 //Signature
@@ -174,7 +168,7 @@ public boolean handleMessage(SOAPMessageContext messageContext)
174168 signatureProperties .put ("org.apache.ws.security.crypto.merlin.keystore.password" , wsSignature .getKeystore ().getPassword ());
175169 signatureProperties .put ("org.apache.ws.security.crypto.merlin.file" , wsSignature .getKeystore ().getSource ());
176170 Crypto signatureCrypto = CryptoFactory .getInstance (signatureProperties );
177- WSSecSignature sign = new WSSecSignature (doc );
171+ WSSecSignature sign = new WSSecSignature ();
178172 sign .setKeyIdentifierType (wsSignature .getKeyIdentifierType ());
179173 sign .setUserInfo (wsSignature .getAlias (), wsSignature .getKeystore ().getPassword ());
180174 if (wsSignature .getCanonicalizationalgorithm () != null )
@@ -183,13 +177,13 @@ public boolean handleMessage(SOAPMessageContext messageContext)
183177 sign .setDigestAlgo (wsSignature .getDigest ());
184178 if (wsSignature .getSignaturealgorithm () != null )
185179 sign .setSignatureAlgorithm (wsSignature .getSignaturealgorithm ());
186- signedDoc = sign .build ( signatureCrypto );
180+ signedDoc = sign .build (doc , signatureCrypto , secHeader );
187181
188182 if (expirationTimeout > 0 )
189183 {
190- WSSecTimestamp timestamp = new WSSecTimestamp (secHeader );
184+ WSSecTimestamp timestamp = new WSSecTimestamp ();
191185 timestamp .setTimeToLive (expirationTimeout );
192- signedDoc = timestamp .build ();
186+ signedDoc = timestamp .build (signedDoc , secHeader );
193187 }
194188 }
195189
@@ -201,19 +195,14 @@ public boolean handleMessage(SOAPMessageContext messageContext)
201195 encryptionProperties .put ("org.apache.ws.security.crypto.merlin.keystore.password" , wsEncryption .getKeystore ().getPassword ());
202196 encryptionProperties .put ("org.apache.ws.security.crypto.merlin.file" , wsEncryption .getKeystore ().getSource ());
203197 Crypto encryptionCrypto = CryptoFactory .getInstance (encryptionProperties );
198+ WSSecEncrypt builder = new WSSecEncrypt ();
199+ builder .setUserInfo (wsEncryption .getAlias (), wsEncryption .getKeystore ().getPassword ());
200+ builder .setKeyIdentifierType (wsEncryption .getKeyIdentifierType ());
204201 if (signedDoc == null )
205202 {
206203 signedDoc = doc ;
207204 }
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 );
205+ builder .build (signedDoc , encryptionCrypto , secHeader );
217206 }
218207
219208 Document securityDoc = doc ;
0 commit comments