Skip to content

Commit ac019d3

Browse files
authored
Merge pull request #45 from mahendya/future
Upgraded 3rd party dependencies jars to latest stable versions
2 parents c72d0b0 + 1a5b2b1 commit ac019d3

25 files changed

+155
-177
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To install the cybersource-sdk-java from central repository,add dependency to yo
1111
<dependency>
1212
<groupId>com.cybersource</groupId>
1313
<artifactId>cybersource-sdk-java</artifactId>
14-
<version>6.2.1</version>
14+
<version>6.2.2</version>
1515
</dependency>
1616
````
1717
Run mvn install, to install dependency
@@ -20,7 +20,7 @@ To install the cybersource-sdk-java from central repository,add dependency to yo
2020
Add the dependency to your build.gradle
2121
````
2222
dependencies {
23-
compile 'com.cybersource:cybersource-sdk-java:6.2.1'
23+
compile 'com.cybersource:cybersource-sdk-java:6.2.2'
2424
}
2525
````
2626
##Requirements

java/pom.xml

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -177,53 +177,49 @@
177177
<dependency>
178178
<groupId>junit</groupId>
179179
<artifactId>junit</artifactId>
180-
<version>4.11</version>
180+
<version>4.12</version>
181181
<scope>test</scope>
182182
</dependency>
183183
<dependency>
184184
<groupId>commons-httpclient</groupId>
185185
<artifactId>commons-httpclient</artifactId>
186-
<version>3.0.1</version>
186+
<version>3.1</version>
187+
<exclusions>
188+
<exclusion>
189+
<groupId>commons-logging</groupId>
190+
<artifactId>commons-logging</artifactId>
191+
</exclusion>
192+
</exclusions>
187193
</dependency>
188194
<dependency>
189195
<groupId>org.bouncycastle</groupId>
190-
<artifactId>bcprov-jdk16</artifactId>
191-
<version>1.45</version>
196+
<artifactId>bcprov-jdk15on</artifactId>
197+
<version>1.55</version>
192198
</dependency>
193199
<dependency>
194-
<groupId>wss4j</groupId>
200+
<groupId>org.apache.ws.security</groupId>
195201
<artifactId>wss4j</artifactId>
196-
<version>1.5.0</version>
197-
</dependency>
198-
<dependency>
199-
<groupId>xml-security</groupId>
200-
<artifactId>xmlsec</artifactId>
201-
<version>1.3.0</version>
202-
</dependency>
203-
<dependency>
204-
<groupId>xalan</groupId>
205-
<artifactId>xalan</artifactId>
206-
<version>2.7.0</version>
207-
</dependency>
202+
<version>1.6.19</version>
203+
</dependency>
208204
<dependency>
209205
<groupId>org.slf4j</groupId>
210206
<artifactId>slf4j-api</artifactId>
211-
<version>1.7.7</version>
207+
<version>1.7.21</version>
212208
</dependency>
213209
<dependency>
214210
<groupId>org.slf4j</groupId>
215211
<artifactId>slf4j-jcl</artifactId>
216-
<version>1.7.7</version>
212+
<version>1.7.21</version>
217213
</dependency>
218214
<dependency>
219-
<groupId>commons-lang</groupId>
220-
<artifactId>commons-lang</artifactId>
221-
<version>2.6</version>
215+
<groupId>org.apache.commons</groupId>
216+
<artifactId>commons-lang3</artifactId>
217+
<version>3.4</version>
222218
</dependency>
223219
<dependency>
224220
<groupId>org.mockito</groupId>
225221
<artifactId>mockito-all</artifactId>
226-
<version>1.8.5</version>
222+
<version>1.10.19</version>
227223
<scope>test</scope>
228224
</dependency>
229225
</dependencies>

java/src/main/java/com/cybersource/ws/client/Client.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.io.StringReader;
3434
import java.text.MessageFormat;
3535
import java.util.HashMap;
36-
import java.util.Iterator;
3736
import java.util.Map;
3837
import java.util.Properties;
3938

@@ -182,7 +181,6 @@ private static Document soapWrapAndSign(
182181
Logger.LT_REQUEST,
183182
mapToString(request, true, PCI.REQUEST));
184183
}
185-
Document doc;
186184

187185
// wrap in SOAP envelope
188186
Object[] arguments
@@ -201,14 +199,14 @@ private static Document soapWrapAndSign(
201199
if ( !mc.getUseSignAndEncrypted() ) {
202200
// sign Document object
203201
logger.log(Logger.LT_INFO, "Signing request...");
204-
resultDocument = handler.createSignedDoc(wrappedDoc,mc.getMerchantID(),null);
202+
resultDocument = handler.createSignedDoc(wrappedDoc,mc.getMerchantID(),mc.getKeyPassword(),null);
205203
if (logSignedData) {
206204
logger.log(Logger.LT_REQUEST,
207205
Utility.nodeToString(resultDocument, PCI.REQUEST));
208206
}
209207
} else {
210208
logger.log(Logger.LT_INFO, "Signing and encrypting request...");
211-
resultDocument = handler.handleMessageCreation(wrappedDoc,mc.getMerchantID());
209+
resultDocument = handler.handleMessageCreation(wrappedDoc,mc.getMerchantID(),mc.getKeyPassword());
212210
if (logSignedData) {
213211
logger.log(Logger.LT_REQUEST,XMLUtils.PrettyDocumentToString(resultDocument));
214212
}

java/src/main/java/com/cybersource/ws/client/SignedAndEncryptedMessageHandler.java

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package com.cybersource.ws.client;
22

3-
4-
53
import org.apache.ws.security.WSConstants;
64
import org.apache.ws.security.WSEncryptionPart;
75
import org.apache.ws.security.WSSecurityException;
8-
import org.apache.ws.security.conversation.ConversationException;
9-
import org.apache.ws.security.message.WSSecDKEncrypt;
10-
import org.apache.ws.security.message.WSSecEncryptedKey;
6+
import org.apache.ws.security.message.WSSecEncrypt;
117
import org.apache.ws.security.message.WSSecHeader;
128
import org.apache.ws.security.message.WSSecSignature;
13-
import org.apache.xml.security.signature.XMLSignature;
149
import org.bouncycastle.jce.provider.BouncyCastleProvider;
1510
import org.w3c.dom.Document;
1611

@@ -27,7 +22,7 @@
2722
import java.util.Collections;
2823
import java.util.Enumeration;
2924
import java.util.List;
30-
import java.util.Vector;
25+
3126

3227
/**
3328
* Created by jeaton on 3/1/2016.
@@ -42,6 +37,11 @@ public class SignedAndEncryptedMessageHandler extends BaseMessageHandler {
4237

4338
private static final String SERVER_ALIAS = "CyberSource_SJC_US";
4439

40+
// By default signature algorithm is set to null and during WSSecSignature build() Signature algorithm will set to "http://www.w3.org/2000/09/xmldsig#rsa-sha1" .
41+
public static final String SIGNATURE_ALGORITHM = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
42+
// By default digest algorithm is set to "http://www.w3.org/2000/09/xmldsig#sha1"
43+
public static final String DIGEST_ALGORITHM = "http://www.w3.org/2001/04/xmlenc#sha256";
44+
4545
// This is loaded by WSS4J but since we use it lets make sure its here
4646
static {
4747
Security.addProvider(new BouncyCastleProvider());
@@ -54,7 +54,6 @@ private SignedAndEncryptedMessageHandler(MerchantConfig merchantConfig, Logger l
5454
for(int pos=0;pos<identities.size();pos++) {
5555
localKeyStoreHandler.addIdentityToKeyStore(identities.get(pos));
5656
}
57-
5857
}
5958

6059
static SignedAndEncryptedMessageHandler getInstance(MerchantConfig merchantConfig, Logger logger)
@@ -114,7 +113,6 @@ private static void readAndStoreCertificateAndPrivateKey(
114113

115114
// our p12 files do not contain an alias as a normal name, its the common name and serial number
116115
String merchantKeyAlias = null;
117-
int certIndex = 0;
118116
try {
119117
Enumeration enumKeyStore = merchantKeyStore.aliases();
120118
while (enumKeyStore.hasMoreElements()) {
@@ -150,73 +148,82 @@ private static void readAndStoreCertificateAndPrivateKey(
150148
throw new SignException(e);
151149
}
152150
}
153-
154-
public Document handleMessageCreation(Document workingDocument, String senderAlias) throws SignException,SignEncryptException{
151+
152+
public Document handleMessageCreation(Document workingDocument, String senderAlias,String password) throws SignEncryptException, SignException{
155153
if (senderAlias == null)
156154
throw new SignEncryptException("SignedAndEncryptedMessageHandler - handleMessageCreation," +
157-
" specified identity is null");
158-
159-
WSSecHeader secHeader = new WSSecHeader();
160-
secHeader.insertSecurityHeader(workingDocument);
161-
162-
//EncryptedKey
163-
WSSecEncryptedKey encrKeyBuilder = new WSSecEncryptedKey();
164-
encrKeyBuilder.setUserInfo(SERVER_ALIAS);
165-
encrKeyBuilder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
155+
" senderAlias is null");
156+
157+
WSSecHeader secHeader = new WSSecHeader();
158+
try {
159+
secHeader.insertSecurityHeader(workingDocument);
160+
} catch (WSSecurityException e) {
161+
logger.log(Logger.LT_EXCEPTION, "Exception while adding docuemnt in soap securiy header for MLE");
162+
throw new SignException(e);
163+
}
164+
165+
WSSecEncrypt encrBuilder = new WSSecEncrypt();
166+
//Set the user name to get the encryption certificate.
167+
//The public key of this certificate is used, thus no password necessary. The user name is a keystore alias usually.
168+
encrBuilder.setUserInfo(SERVER_ALIAS);
166169

167-
try {
168-
encrKeyBuilder.prepare(workingDocument, localKeyStoreHandler);
169-
} catch (WSSecurityException e) {
170-
logger.log(Logger.LT_EXCEPTION, "Key builder failed to create keys for , '" + senderAlias + "'" + " with " + SERVER_ALIAS);
171-
throw new SignEncryptException(e.getMessage(), e);
172-
}
173-
174-
byte[] ek = encrKeyBuilder.getEphemeralKey();
175-
String tokenIdentifier = encrKeyBuilder.getId();
176-
177-
//Create signed document
178-
Document signedDoc = createSignedDoc(workingDocument,senderAlias,secHeader);
170+
/*This is to reference a public key or certificate when signing or encrypting a SOAP message.
171+
*The following valid values for these configuration items are:
172+
*IssuerSerial (default),DirectReference[BST],X509KeyIdentifier,Thumbprint,SKIKeyIdentifier,KeyValue (signature only),EncryptedKeySHA1 (encryption only)
173+
*/
174+
encrBuilder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
179175

180-
WSSecDKEncrypt encrBuilder = new WSSecDKEncrypt();
176+
//This encryption algorithm is used to encrypt the data.
181177
encrBuilder.setSymmetricEncAlgorithm(WSConstants.AES_256);
182-
encrBuilder.setExternalKey(ek, tokenIdentifier);
183-
Document signedEncryptedDoc = null;
178+
179+
//Sets the algorithm to encode the symmetric key. Default is the WSConstants.KEYTRANSPORT_RSAOEP algorithm.
180+
//encrBuilder.setKeyEnc(WSConstants.KEYTRANSPORT_RSAOEP);
184181

185-
try {
186-
signedEncryptedDoc = encrBuilder.build(signedDoc,localKeyStoreHandler, secHeader);
187-
} catch (WSSecurityException e) {
188-
logger.log(Logger.LT_EXCEPTION, "Failed while encrypting signed requeest for , '" + senderAlias + "'" + " with " + SERVER_ALIAS);
189-
throw new SignEncryptException(e.getMessage(), e);
190-
}
182+
183+
//Create signed document
184+
Document signedDoc = createSignedDoc(workingDocument,senderAlias,password,secHeader);
191185

192-
encrKeyBuilder.prependToHeader(secHeader);
193-
encrKeyBuilder.prependBSTElementToHeader(secHeader);
194-
return signedEncryptedDoc;
186+
Document signedEncryptedDoc;
187+
try {
188+
//Builds the SOAP envelope with encrypted Body and adds encrypted key.
189+
// If no external key (symmetricalKey) was set ,generate an encryption
190+
// key (session key) for this Encrypt element. This key will be
191+
// encrypted using the public key of the receiver
192+
signedEncryptedDoc = encrBuilder.build(signedDoc, localKeyStoreHandler, secHeader);
193+
} catch (WSSecurityException e) {
194+
logger.log(Logger.LT_EXCEPTION, "Failed while encrypting signed requeest for , '" + senderAlias + "'" + " with " + SERVER_ALIAS);
195+
throw new SignEncryptException(e.getMessage(), e);
196+
}
197+
encrBuilder.prependToHeader(secHeader);
198+
return signedEncryptedDoc;
195199
}
196-
197-
public Document createSignedDoc(Document workingDocument,String senderAlias, WSSecHeader secHeader) throws SignException {
200+
201+
public Document createSignedDoc(Document workingDocument,String senderAlias, String password,WSSecHeader secHeader) throws SignException {
198202

199203
if(secHeader==null){
204+
try {
200205
secHeader = new WSSecHeader();
201206
secHeader.insertSecurityHeader(workingDocument);
207+
} catch (WSSecurityException e) {
208+
logger.log(Logger.LT_EXCEPTION, "Exception while signing XML document");
209+
throw new SignException(e);
210+
}
202211
}
203-
204212
WSSecSignature sign = new WSSecSignature();
205-
sign.setUserInfo(senderAlias, senderAlias);
206-
sign.setSignatureAlgorithm(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256);
213+
sign.setUserInfo(senderAlias, password);
214+
sign.setDigestAlgo(DIGEST_ALGORITHM);
215+
sign.setSignatureAlgorithm(SIGNATURE_ALGORITHM);
207216
sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
208217
sign.setUseSingleCertificate(true);
209218

210219
//Set which parts of the message to encrypt/sign.
211220
WSEncryptionPart msgBodyPart = new WSEncryptionPart(WSConstants.ELEM_BODY, WSConstants.URI_SOAP11_ENV, "");
212-
sign.setParts(new Vector(Collections.singletonList(msgBodyPart)));
221+
sign.setParts(Collections.singletonList(msgBodyPart));
213222
try {
214223
return sign.build(workingDocument, localKeyStoreHandler, secHeader);
215224
} catch (WSSecurityException e) {
216225
logger.log(Logger.LT_EXCEPTION, "Failed while signing requeest for , '" + senderAlias + "'");
217226
throw new SignException(e.getMessage());
218227
}
219228
}
220-
221-
222229
}

java/src/main/java/com/cybersource/ws/client/Utility.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package com.cybersource.ws.client;
2020

21-
import org.apache.commons.lang.StringEscapeUtils;
21+
import org.apache.commons.lang3.StringEscapeUtils;
2222
import org.w3c.dom.Attr;
2323
import org.w3c.dom.Document;
2424
import org.w3c.dom.Element;
@@ -48,7 +48,7 @@ private Utility() {
4848
/**
4949
* Version number of this release.
5050
*/
51-
public static final String VERSION = "6.2.1";
51+
public static final String VERSION = "6.2.2";
5252

5353
/**
5454
* If in the Request map, a key called "_has_escapes" is present and is set
@@ -428,7 +428,7 @@ public static String mapToString(Map src, boolean mask, int type) {
428428
// themselves.
429429
return (("1".equals(hasEscapes) ||
430430
"true".equalsIgnoreCase(hasEscapes))
431-
? dest.toString() : StringEscapeUtils.escapeXml((dest.toString())));
431+
? dest.toString() : StringEscapeUtils.escapeXml11((dest.toString())));
432432
}
433433

434434

java/src/main/java/com/cybersource/ws/client/XMLClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,15 @@ private static Document soapWrapAndSign(
368368
if ( !mc.getUseSignAndEncrypted() ) {
369369
// sign wrapped Document object
370370
logger.log(Logger.LT_INFO, "Signing request...");
371-
resultDocument = handler.createSignedDoc(wrappedDoc,mc.getMerchantID(),null);
371+
resultDocument = handler.createSignedDoc(wrappedDoc,mc.getMerchantID(),mc.getKeyPassword(),null);
372372
if (logSignedData) {
373373
logger.log(Logger.LT_REQUEST,
374374
Utility.nodeToString(resultDocument, PCI.REQUEST));
375375
}
376376
} else {
377377
// sign and encrypt wrapped Document object
378378
logger.log(Logger.LT_INFO, "Signing and encrypting request...");
379-
resultDocument = handler.handleMessageCreation(wrappedDoc,mc.getMerchantID());
379+
resultDocument = handler.handleMessageCreation(wrappedDoc,mc.getMerchantID(),mc.getKeyPassword());
380380
if (logSignedData) {
381381
logger.log(Logger.LT_REQUEST,XMLUtils.PrettyDocumentToString(resultDocument));
382382
}

java/src/main/resources/cybs.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ targetAPIVersion=<-- API Version Number -->
77
# the following flags can be used to control the endpoint to which requests will be sent.
88
# Set sendToProduction=true to send requests to Cybersource production environment.
99
# Set sendToAkamai=true to send requests through Akamai to Cybersource.
10-
# If serverURL is provided then it takes presedence over the above settings. By default
10+
# If serverURL is provided then it takes precedence over the above settings. By default
1111
# the serverURL config is commented out.
1212
sendToProduction=<-- Set it to true for Production -->
1313
sendToAkamai=<-- Set it to true for Akamai -->

java/src/test/java/com/cybersource/ws/client/ApacheWssjSignatureIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ public void setup() throws Exception{
109109

110110
@Test
111111
public void testSoapWrapAndSign() throws Exception {
112-
Document doc = handler.createSignedDoc(wrappedDoc,config.getMerchantID(),null);
112+
Document doc = handler.createSignedDoc(wrappedDoc,config.getMerchantID(),config.getKeyPassword(),null);
113113
NodeList signatureElement = doc.getElementsByTagName("wsse:Security");
114114
assert (signatureElement.getLength() >= 1);
115115
}
116116

117117
@Test
118118
public void testSoapWrapSignedAndEncrypt() throws Exception {
119-
Document doc = handler.handleMessageCreation(wrappedDoc, config.getMerchantID());
119+
Document doc = handler.handleMessageCreation(wrappedDoc, config.getMerchantID(),config.getKeyPassword());
120120
NodeList signatureElement = doc.getElementsByTagName("xenc:EncryptedKey");
121121
assert (signatureElement.getLength() >= 1);
122122
assertEquals("Id", signatureElement.item(0).getAttributes().item(0).getLocalName());

java/src/test/java/com/cybersource/ws/client/ClientIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void testRunTransaction() throws Exception {
6666
requestMap.put("purchaseTotals_currency", "USD");
6767
requestMap.put("item_0_unitPrice", "12.34");
6868
requestMap.put("item_1_unitPrice", "56.78");
69-
requestMap.put("merchant_id", "your_merchant_id");
69+
//requestMap.put("merchantID", "your_merchant_id");
7070

7171
//Loading the properties file from src/test/resources
7272
Properties merchantProperties = new Properties();

0 commit comments

Comments
 (0)