3
3
import java .util .Set ;
4
4
import java .util .HashSet ;
5
5
import java .util .Properties ;
6
- import javax .crypto .KeyGenerator ;
7
- import javax .crypto .SecretKey ;
8
6
import javax .xml .namespace .QName ;
9
7
import javax .xml .transform .*;
10
8
import javax .xml .transform .dom .DOMResult ;
14
12
import jakarta .xml .ws .handler .soap .SOAPMessageContext ;
15
13
import jakarta .xml .soap .*;
16
14
import 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 ;
25
21
import org .w3c .dom .*;
26
22
import java .io .InputStream ;
27
23
import java .io .ByteArrayInputStream ;
30
26
import com .genexus .diagnostics .core .LogManager ;
31
27
import com .genexus .common .interfaces .*;
32
28
33
- import static org .apache .wss4j .common .util .KeyUtils .getKeyGenerator ;
34
-
35
29
public class GXHandlerConsumerChain implements SOAPHandler <SOAPMessageContext >
36
30
{
37
31
public static final ILogger logger = LogManager .getLogger (GXHandlerConsumerChain .class );
@@ -162,8 +156,8 @@ public boolean handleMessage(SOAPMessageContext messageContext)
162
156
Document doc = messageToDocument (messageContext .getMessage ());
163
157
164
158
//Security header
165
- WSSecHeader secHeader = new WSSecHeader (doc );
166
- secHeader .insertSecurityHeader ();
159
+ WSSecHeader secHeader = new WSSecHeader ();
160
+ secHeader .insertSecurityHeader (doc );
167
161
Document signedDoc = null ;
168
162
169
163
//Signature
@@ -174,7 +168,7 @@ public boolean handleMessage(SOAPMessageContext messageContext)
174
168
signatureProperties .put ("org.apache.ws.security.crypto.merlin.keystore.password" , wsSignature .getKeystore ().getPassword ());
175
169
signatureProperties .put ("org.apache.ws.security.crypto.merlin.file" , wsSignature .getKeystore ().getSource ());
176
170
Crypto signatureCrypto = CryptoFactory .getInstance (signatureProperties );
177
- WSSecSignature sign = new WSSecSignature (doc );
171
+ WSSecSignature sign = new WSSecSignature ();
178
172
sign .setKeyIdentifierType (wsSignature .getKeyIdentifierType ());
179
173
sign .setUserInfo (wsSignature .getAlias (), wsSignature .getKeystore ().getPassword ());
180
174
if (wsSignature .getCanonicalizationalgorithm () != null )
@@ -183,13 +177,13 @@ public boolean handleMessage(SOAPMessageContext messageContext)
183
177
sign .setDigestAlgo (wsSignature .getDigest ());
184
178
if (wsSignature .getSignaturealgorithm () != null )
185
179
sign .setSignatureAlgorithm (wsSignature .getSignaturealgorithm ());
186
- signedDoc = sign .build ( signatureCrypto );
180
+ signedDoc = sign .build (doc , signatureCrypto , secHeader );
187
181
188
182
if (expirationTimeout > 0 )
189
183
{
190
- WSSecTimestamp timestamp = new WSSecTimestamp (secHeader );
184
+ WSSecTimestamp timestamp = new WSSecTimestamp ();
191
185
timestamp .setTimeToLive (expirationTimeout );
192
- signedDoc = timestamp .build ();
186
+ signedDoc = timestamp .build (signedDoc , secHeader );
193
187
}
194
188
}
195
189
@@ -201,19 +195,14 @@ public boolean handleMessage(SOAPMessageContext messageContext)
201
195
encryptionProperties .put ("org.apache.ws.security.crypto.merlin.keystore.password" , wsEncryption .getKeystore ().getPassword ());
202
196
encryptionProperties .put ("org.apache.ws.security.crypto.merlin.file" , wsEncryption .getKeystore ().getSource ());
203
197
Crypto encryptionCrypto = CryptoFactory .getInstance (encryptionProperties );
198
+ WSSecEncrypt builder = new WSSecEncrypt ();
199
+ builder .setUserInfo (wsEncryption .getAlias (), wsEncryption .getKeystore ().getPassword ());
200
+ builder .setKeyIdentifierType (wsEncryption .getKeyIdentifierType ());
204
201
if (signedDoc == null )
205
202
{
206
203
signedDoc = doc ;
207
204
}
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 );
217
206
}
218
207
219
208
Document securityDoc = doc ;
0 commit comments