Skip to content

Commit bb0f0f5

Browse files
committed
changed validate method to non-deprecated, add LicenseeSecret workflow to Demo
1 parent 79f48f9 commit bb0f0f5

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/demo/NetLicensingClientDemo.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.labs64.netlicensing.demo;
1414

1515
import java.math.BigDecimal;
16+
import java.util.UUID;
1617

1718
import org.apache.commons.lang3.RandomStringUtils;
1819
import org.apache.commons.lang3.StringUtils;
@@ -35,6 +36,7 @@
3536
import com.labs64.netlicensing.domain.vo.Context;
3637
import com.labs64.netlicensing.domain.vo.Currency;
3738
import com.labs64.netlicensing.domain.vo.LicenseType;
39+
import com.labs64.netlicensing.domain.vo.LicenseeSecretMode;
3840
import com.labs64.netlicensing.domain.vo.Page;
3941
import com.labs64.netlicensing.domain.vo.SecurityMode;
4042
import com.labs64.netlicensing.domain.vo.TokenType;
@@ -58,6 +60,8 @@ public class NetLicensingClientDemo {
5860

5961
private final static String DEMO_NUMBER_PREFIX = "DEMO-";
6062

63+
private static String randomLicenseeSecret = UUID.randomUUID().toString();
64+
6165
public static void main(final String[] args) {
6266

6367
// configure J.U.L. to Slf4j bridge for Jersey
@@ -76,7 +80,6 @@ public static void main(final String[] args) {
7680
final String licenseTemplateNumber = numberWithPrefix("LT", randomNumber);
7781
final String licenseeNumber = numberWithPrefix("L", randomNumber);
7882
final String licenseNumber = numberWithPrefix("LC", randomNumber);
79-
final String licenseeName = numberWithPrefix("Licensee ", RandomStringUtils.randomAlphanumeric(8));
8083

8184
final ConsoleWriter out = new ConsoleWriter();
8285

@@ -109,6 +112,8 @@ public static void main(final String[] args) {
109112

110113
final Product updateProduct = new ProductImpl();
111114
updateProduct.addProperty("Updated property name", "Updated value");
115+
updateProduct.addProperty(Constants.Product.PROP_LICENSEE_SECRET_MODE,
116+
LicenseeSecretMode.PREDEFINED.toString());
112117
product = ProductService.update(context, productNumber, updateProduct);
113118
out.writeObject("Updated product:", product);
114119

@@ -225,6 +230,8 @@ public static void main(final String[] args) {
225230

226231
final Licensee updateLicensee = new LicenseeImpl();
227232
updateLicensee.addProperty("Updated property name", "Updated value");
233+
updateLicensee.addProperty(Constants.Licensee.PROP_LICENSEE_SECRET, randomLicenseeSecret);
234+
228235
licensee = LicenseeService.update(context, licenseeNumber, updateLicensee);
229236
out.writeObject("Updated licensee:", licensee);
230237

@@ -302,13 +309,12 @@ public static void main(final String[] args) {
302309

303310
final ValidationParameters validationParameters = new ValidationParameters();
304311
validationParameters.put(productModuleNumber, "paramKey", "paramValue");
305-
ValidationResult validationResult = LicenseeService.validate(context, licenseeNumber, productNumber,
306-
licenseeName, validationParameters);
312+
validationParameters.setLicenseeSecret(randomLicenseeSecret);
313+
ValidationResult validationResult = LicenseeService.validate(context, licenseeNumber, validationParameters);
307314
out.writeObject("Validation result for created licensee:", validationResult);
308315

309316
context.setSecurityMode(SecurityMode.APIKEY_IDENTIFICATION);
310-
validationResult = LicenseeService.validate(context, licenseeNumber, productNumber, licenseeName,
311-
validationParameters);
317+
validationResult = LicenseeService.validate(context, licenseeNumber, validationParameters);
312318
context.setSecurityMode(SecurityMode.BASIC_AUTHENTICATION);
313319
out.writeObject("Validation repeated with APIKey:", validationResult);
314320

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static final class Product {
7070
public static final String DESCRIPTION = "description";
7171
public static final String LICENSING_INFO = "licensingInfo";
7272
public static final String DISCOUNTS = "discounts";
73+
public static final String PROP_LICENSEE_SECRET_MODE = "licenseeSecretMode";
7374

7475
public static final class Discount {
7576
public static final String TOTAL_PRICE = "totalPrice";
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.labs64.netlicensing.domain.vo;
2+
3+
public enum LicenseeSecretMode {
4+
5+
DISABLED("DISABLED"),
6+
7+
PREDEFINED("PREDEFINED"),
8+
9+
CLIENT("CLIENT");
10+
11+
private final String value;
12+
13+
/**
14+
* Instantiates a new Licensee Secret Mode.
15+
*
16+
* @param licenseeSecretModeValue
17+
* LicenseeSecretMode value
18+
*/
19+
LicenseeSecretMode(final String licenseeSecretModeValue) {
20+
value = licenseeSecretModeValue;
21+
}
22+
23+
public static LicenseeSecretMode parseString(final String value) {
24+
for (final LicenseeSecretMode licenseeSecretMode : LicenseeSecretMode.values()) {
25+
if (licenseeSecretMode.name().equalsIgnoreCase(value)) {
26+
return licenseeSecretMode;
27+
}
28+
}
29+
return LicenseeSecretMode.DISABLED;
30+
}
31+
32+
/*
33+
* (non-Javadoc)
34+
*
35+
* @see java.lang.Enum#toString()
36+
*/
37+
@Override
38+
public String toString() {
39+
return value;
40+
}
41+
}

0 commit comments

Comments
 (0)