Skip to content

Commit d3954ba

Browse files
authored
Merge pull request #105 from CyberSource/future
Future
2 parents 6a976a3 + e6c6eb0 commit d3954ba

File tree

25 files changed

+340
-219
lines changed

25 files changed

+340
-219
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CyberSource Simple Order API for Java
22

3-
[![Build Status](https://travis-ci.org/CyberSource/cybersource-sdk-java.png?branch=master)](https://travis-ci.org/CyberSource/cybersource-sdk-java)
3+
[![Build Status](https://travis-ci.org/CyberSource/cybersource-sdk-java.png?branch=future)](https://travis-ci.org/CyberSource/cybersource-sdk-java)
44

55
## Package Managers
66

@@ -10,7 +10,7 @@ To install the `cybersource-sdk-java` from central repository, add dependency to
1010
<dependency>
1111
<groupId>com.cybersource</groupId>
1212
<artifactId>cybersource-sdk-java</artifactId>
13-
<version>6.2.5</version>
13+
<version>6.2.6</version>
1414
</dependency>
1515
```
1616
Run `mvn install` to install dependency
@@ -19,7 +19,7 @@ Run `mvn install` to install dependency
1919
Add the dependency to your build.gradle
2020
```java
2121
dependencies {
22-
compile 'com.cybersource:cybersource-sdk-java:6.2.5'
22+
compile 'com.cybersource:cybersource-sdk-java:6.2.6'
2323
}
2424
```
2525
## Requirements
@@ -58,9 +58,10 @@ You do not need to download and build the source to use the SDK but if you want
5858
- `sendToProduction` is initially set to false. Set it to true only when you are ready to send live transactions.
5959
- Set `sendToAkamai` config parameter with toggle value "true/false" to turn on/off routing requests through Akamai to Cybersource. By default, it is set to true.
6060
- `serverURL` config parameter will take precedence over `sendToProduction` and `sendToAkamai` config parameters. By default the `serverURL` configuration is commented out.
61-
- if `enablejdkcert` parameter is set to true, certificates will be read from the JKS file specified at keysDirectory location. The JKS file should be of the same name as specified in keyFilename.
61+
- If `enableJdkcert` parameter is set to true, certificates will be read from the JKS file specified at keysDirectory location. The JKS file should be of the same name as specified in keyFilename.
6262
- To know how to convert p12 to JKS refer the JKS creation section of this document.
63-
- `enableCacerts` property is considered only if `enablejdkcert` is set to true. If `enableCacerts` is set to true, certificates will be read from the cacerts folder under the JDK.
63+
- If 'enableCacert' property parameter is set to true, certificates will be read from the cacerts file specified at keysDirectory location.If keysDirectory path is not set,certificate will be loaded from Java Installation cacerts file. The cacerts file should be of the same name as specified in keyFilename.
64+
- If `certificateCacheEnabled` parameter is set to false (default is true), the p12 certificate of a merchant will be reloaded from filesystem every time a transaction is made
6465
- `allowRetry` config parameter will only work for HttpClient. Set `allowRetry` config parameter to "true" to enable retry mechanism and set merchant specific values for the retry.
6566
- Set integer values for config parameter `numberOfRetries` *and* `retryInterval`. Retry Interval is time delay for next retry in seconds.
6667
- Number of retry parameter should be set between 1 to 5. Any other value will throw an Error Message.
@@ -136,7 +137,8 @@ keytool -list -v -keystore <Your_keystore_name>`
136137
- It should have two entries.
137138
- The first entry should contain a chain of two certificates - `CyberSourceCertAuth` and <Merchant_ID> with alias name <Merchant_ID>
138139
- Second entry should be for `CyberSource_SJC_US` certificate with alias name as CyberSource_SJC_US
139-
140+
141+
140142
## Message Level Encryption
141143
CyberSource supports Message Level Encryption (MLE) for Simple Order API. Message level encryption conforms to the SOAP Security 1.0 specification published by the OASIS standards group.
142144

@@ -181,6 +183,12 @@ Retry Pattern allows to retry sending a failed request and it will only work wit
181183

182184
## Changes
183185

186+
Version Cybersource-sdk-java 6.2.6 (MAY,2018)
187+
_______________________________
188+
1) Added certificateCacheEnabled optional feature. certificateCacheEnabled parameter is set to false (default is true), the p12 certificate of a merchant will be reloaded from filesystem every time a transaction is made.If the certificateCacheEnabled is true then only at the first time certificate of a merchant will loaded from filesystem.
189+
2) Intreduced a new feature to check merchant .p12 certificate file validity at run time. If it is replaced at runtime then SDK will reload the new certificate into the cache.
190+
3) Changed clientLibrary version to 6.2.6;
191+
184192
Version Cybersource-sdk-java 6.2.5 (OCT,2017)
185193
_______________________________
186194
1) Merchant cert to be read from JAVA key store. Flag is added to enable reading cert from Java keystore.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ private static void setVersionInformation(Map<String, String> request) {
212212
* @throws SignException if signing fails.
213213
* @throws SAXException
214214
* @throws SignEncryptException
215+
* @throws ConfigException
215216
*/
216217
private static Document soapWrapAndSign(
217218
Map request, MerchantConfig mc, DocumentBuilder builder,
218219
LoggerWrapper logger)
219220
throws
220-
IOException, SignException, SAXException, SignEncryptException {
221+
IOException, SignException, SAXException, SignEncryptException, ConfigException {
221222
boolean logSignedData = mc.getLogSignedData();
222223
if (!logSignedData) {
223224
logger.log(

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package com.cybersource.ws.client;
1111

12+
import java.io.File;
1213
import java.security.PrivateKey;
1314
import java.security.cert.CertificateEncodingException;
1415
import java.security.cert.X509Certificate;
@@ -35,9 +36,13 @@ public class Identity {
3536
private PrivateKey privateKey;
3637

3738
private MerchantConfig merchantConfig;
39+
40+
private long lastModifiedDate;
3841

3942
private static final String SERVER_ALIAS = "CyberSource_SJC_US";
4043

44+
private Logger logger = null;
45+
4146
/**
4247
* Creates an Identity instance.this type of the instance can
4348
* only be used to store server certificate identity.
@@ -46,10 +51,13 @@ public class Identity {
4651
* @param x509Certificate
4752
* @throws SignException
4853
*/
49-
public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate) throws SignException {
54+
public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate,Logger logger) throws SignException {
5055
this.merchantConfig = merchantConfig;
5156
this.x509Cert=x509Certificate;
52-
if(merchantConfig.isJdkCertEnabled()){
57+
if(this.logger == null){
58+
this.logger=logger;
59+
}
60+
if(merchantConfig.isJdkCertEnabled() || merchantConfig.isCacertEnabled()){
5361
setupJdkServerCerts();
5462
}
5563
else{
@@ -89,13 +97,42 @@ else if (subjectDNrray.length == 2 && subjectDNrray[1].contains(SERVER_ALIAS)) {
8997
* @param privateKey
9098
* @throws SignException
9199
*/
92-
public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, PrivateKey privateKey) throws SignException {
100+
public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, PrivateKey privateKey,Logger logger) throws SignException {
93101
this.merchantConfig = merchantConfig;
94102
this.x509Cert = x509Certificate;
95103
this.privateKey = privateKey;
104+
if(this.logger == null){
105+
this.logger=logger;
106+
}
107+
try {
108+
this.lastModifiedDate=merchantConfig.getKeyFile().lastModified();
109+
} catch (ConfigException e) {
110+
111+
logger.log(Logger.LT_EXCEPTION,
112+
"Identity object ,cannot instantiate with key file lastModifiedDate. "
113+
+ e.getMessage());
114+
throw new SignException("Exception While initializing the merchant identity constructor with keyfile last modified date"+e.getMessage());
115+
}
96116
setUpMerchant();
97117
}
98118

119+
/**
120+
* If merchant uploads a new key then isValid method will return false and certificate reload will happen.
121+
* else isValid method will return true and certificate reload will not occur.
122+
*/
123+
124+
public boolean isValid(File keyFile) {
125+
126+
boolean changeKeyFileStatus=(this.lastModifiedDate == keyFile.lastModified());
127+
128+
if (!changeKeyFileStatus) {
129+
130+
logger.log(Logger.LT_INFO, "Key file changed");
131+
logger.log(Logger.LT_INFO, "Timestamp of current key file:"+keyFile.lastModified());
132+
}
133+
return changeKeyFileStatus;
134+
}
135+
99136
private void setUpMerchant() throws SignException {
100137
if (serialNumber == null && x509Cert != null) {
101138
String subjectDN = x509Cert.getSubjectDN().getName();
@@ -234,5 +271,4 @@ public String toString() {
234271
+ serialNumber + ",expiration=" + expireStr+ " }";
235272
}
236273

237-
238274
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class MerchantConfig {
6666
private String cacertPassword;
6767
private String customHttpClass;
6868
private boolean customHttpClassEnabled;
69+
private boolean certificateCacheEnabled;
6970

7071
public String getcustomHttpClass() {
7172
return customHttpClass;
@@ -83,8 +84,7 @@ public boolean isCustomHttpClassEnabled() {
8384
private int numberOfRetries = 0;
8485
private long retryInterval = 0;
8586
private boolean allowRetry=true;
86-
87-
87+
8888
// getter methods
8989
public boolean getUseSignAndEncrypted() { return useSignAndEncrypted; }
9090

@@ -183,6 +183,10 @@ public String getProxyPassword() {
183183
return proxyPassword != null ? proxyPassword : "";
184184
}
185185

186+
public boolean isCertificateCacheEnabled() {
187+
return certificateCacheEnabled;
188+
}
189+
186190
/**
187191
* Returns the effective server URL to which the request will be sent.
188192
* If a serverURL is specified, then that is what is returned.
@@ -271,6 +275,7 @@ public MerchantConfig(Properties _props, String _merchantID)
271275
enableCacert=getBooleanProperty(merchantID, "enableCacert", false);
272276
cacertPassword=getProperty(merchantID,"cacertPassword","changeit");
273277
customHttpClassEnabled=getBooleanProperty(merchantID,"customHttpClassEnabled",false);
278+
certificateCacheEnabled=getBooleanProperty(merchantID,"certificateCacheEnabled",true);
274279
// compute and store effective namespace URI
275280

276281
if (namespaceURI == null && targetAPIVersion == null) {
@@ -324,6 +329,14 @@ public MerchantConfig(Properties _props, String _merchantID)
324329
throw new ConfigException("Invalid value of numberOfRetries and/or retryInterval");
325330
}
326331
}
332+
if(isCacertEnabled()){
333+
if(StringUtils.isBlank(keysDirectory)){
334+
keysDirectory = System.getProperty("java.home") + "/lib/security".replace('/', File.separatorChar);
335+
}
336+
if(StringUtils.isBlank(keyFilename)){
337+
keyFilename = "cacerts";
338+
}
339+
}
327340
}
328341

329342
/**
@@ -495,6 +508,7 @@ public String getLogString() {
495508
}
496509
}
497510
appendPair(sb, "useSignAndEncrypted", useSignAndEncrypted);
511+
appendPair(sb, "certificateCacheEnabled", certificateCacheEnabled);
498512
return (sb.toString());
499513
}
500514

@@ -580,4 +594,5 @@ public boolean isJdkCertEnabled() {
580594
public String getCacertPassword(){
581595
return cacertPassword;
582596
}
597+
583598
}

0 commit comments

Comments
 (0)