From 09bb2b3b9300e332f8b743481fbb412df8cd2a89 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Wed, 22 Oct 2014 16:07:15 +0000
Subject: [PATCH] #2021 feature - Added changes on client to use PackID and other changes related with license file fields
---
src/main/java/net/curisit/securis/LicenseValidator.java | 87 ++--
src/main/java/net/curisit/securis/beans/LicenseBean.java | 149 +++---
src/main/java/net/curisit/securis/beans/SignedLicenseBean.java | 31
src/main/java/net/curisit/securis/utils/Params.java | 309 +++++++-------
src/main/java/net/curisit/securis/LicenseManager.java | 146 +++---
src/main/java/net/curisit/securis/ReqGenerator.java | 123 ++--
src/main/java/net/curisit/securis/beans/RequestBean.java | 182 ++++----
pom.xml | 2
src/main/java/net/curisit/securis/License.java | 224 +++++-----
9 files changed, 650 insertions(+), 603 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2d5ec65..225d7c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.curisit</groupId>
<artifactId>securis-client</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
diff --git a/src/main/java/net/curisit/securis/License.java b/src/main/java/net/curisit/securis/License.java
index d22c4cd..d92061c 100644
--- a/src/main/java/net/curisit/securis/License.java
+++ b/src/main/java/net/curisit/securis/License.java
@@ -15,7 +15,6 @@
import org.apache.commons.cli.PosixParser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.codehaus.jackson.map.DeserializerFactory.Config;
/**
* Main class when SeCuris client is used from command line.
@@ -44,70 +43,70 @@
private static final Logger LOG = LogManager.getLogger(License.class);
- /**
- * Aplication entry point when it used as CLI
- *
- * @param args
- * @throws URISyntaxException
- */
- public static void main(String[] args) throws URISyntaxException {
+ /**
+ * Aplication entry point when it used as CLI
+ *
+ * @param args
+ * @throws URISyntaxException
+ */
+ public static void main(String[] args) throws URISyntaxException {
- LOG.debug("SeCuris client tool init ");
+ LOG.debug("SeCuris client tool init ");
- checkConfigFile();
- CommandLine cmd = getCommandLine(args);
+ checkConfigFile();
+ CommandLine cmd = getCommandLine(args);
- try {
- if (cmd.hasOption('g')) {
- String filename = cmd.getOptionValue("rfile");
- if (filename == null)
- filename = "./license.req";
- File file = new File(filename);
- LicenseManager.getInstance().createRequestFile(file);
- LOG.info("Request file {} generated OK", file.getAbsolutePath());
- System.exit(0);
- }
+ try {
+ if (cmd.hasOption('g')) {
+ String filename = cmd.getOptionValue("rfile");
+ if (filename == null)
+ filename = "./license.req";
+ File file = new File(filename);
+ LicenseManager.getInstance().createRequestFile(file);
+ LOG.info("Request file {} generated OK", file.getAbsolutePath());
+ System.exit(0);
+ }
- if (cmd.hasOption('l')) {
- String filename = cmd.getOptionValue("validate");
- if (filename == null)
- filename = "./license.lic";
- File file = new File(filename);
- if (!file.exists()) {
- throw new SeCurisException("The license file doesn't exist: " + file.getAbsolutePath());
- }
- try {
- LicenseManager.getInstance().validateLicense(file);
- LOG.info("License file {} is valid", file.getAbsolutePath());
- } catch (SeCurisException e) {
- LOG.info("License file {} is NOT valid", file.getAbsolutePath());
- LOG.info("Reason: {}", e.toString());
- }
+ if (cmd.hasOption('l')) {
+ String filename = cmd.getOptionValue("validate");
+ if (filename == null)
+ filename = "./license.lic";
+ File file = new File(filename);
+ if (!file.exists()) {
+ throw new SeCurisException("The license file doesn't exist: " + file.getAbsolutePath());
+ }
+ try {
+ LicenseManager.getInstance().validateLicense(file);
+ LOG.info("License file {} is valid", file.getAbsolutePath());
+ } catch (SeCurisException e) {
+ LOG.info("License file {} is NOT valid", file.getAbsolutePath());
+ LOG.info("Reason: {}", e.toString());
+ }
- System.exit(0);
- }
+ System.exit(0);
+ }
- if (cmd.hasOption('c')) {
- SignedLicenseBean lic = LicenseManager.getInstance().requestLicense();
- String filename = cmd.getOptionValue("c");
+ if (cmd.hasOption('c')) {
+ SignedLicenseBean lic = LicenseManager.getInstance().requestLicense();
+ String filename = cmd.getOptionValue("c");
if (filename == null)
filename = "./license.lic";
File file = new File(filename);
LicenseManager.getInstance().save(lic, file);
LOG.info("License file sucessfully saved in file: {}", file.getAbsolutePath());
System.exit(0);
- }
+ }
- if (cmd.hasOption('t')) {
+ if (cmd.hasOption('t')) {
LicenseManager.getInstance().testServer();
LOG.info("Server is OK, url: {}", Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL));
System.exit(0);
- }
+ }
- if (cmd.hasOption('r')) {
- String licFilename = cmd.getOptionValue("renew");
- checkMandatoryParameter(licFilename, "renew");
+ if (cmd.hasOption('r')) {
+ String licFilename = cmd.getOptionValue("renew");
+ checkMandatoryParameter(licFilename, "renew");
File file = new File(licFilename);
if (!file.exists()) {
throw new SeCurisException("The license file doesn't exist: " + file.getAbsolutePath());
@@ -118,77 +117,84 @@
LOG.info("Old license file has been renamed to: {}", oldLicFile.getAbsolutePath());
LicenseManager.getInstance().save(newLic, file);
LOG.info("New license file saved as: {}", file.getAbsolutePath());
- System.exit(0);
- }
+ System.exit(0);
+ }
- } catch (SeCurisException e) {
- LOG.error("The command generated an error: {}", e.toString());
- }
- }
+ } catch (SeCurisException e) {
+ LOG.error("The command generated an error: {}", e.toString());
+ }
+ }
- private static void checkMandatoryParameter(String value, String param) {
- if (value == null) {
- LOG.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
- System.exit(-5);
- }
- }
+ private static void checkMandatoryParameter(String value, String param) {
+ if (value == null) {
+ LOG.error("Parameter {} is mandatory. Use --help to get information about parameters", param);
+ System.exit(-5);
+ }
+ }
- /**
- * Checks that config file exists and contains mandatory parameters
- */
- private static void checkConfigFile() {
- String appCode = Params.get(Params.KEYS.APPLICATION_CODE);
- if (appCode == null) {
- LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
- System.exit(-3);
- }
- String customerCode = Params.get(Params.KEYS.CUSTOMER_CODE);
- if (customerCode == null) {
- LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
- System.exit(-4);
- }
- }
+ /**
+ * Checks that config file exists and contains mandatory parameters
+ */
+ private static void checkConfigFile() {
+ if (Params.get(Params.KEYS.APPLICATION_CODE) == null) {
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
+ System.exit(-3);
+ }
+ if (Params.get(Params.KEYS.CUSTOMER_CODE) == null) {
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
+ System.exit(-4);
+ }
+ if (Params.get(Params.KEYS.PACK_CODE) == null) {
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.PACK_CODE);
+ System.exit(-6);
+ }
+ }
- private static CommandLine getCommandLine(String[] args) {
- Options ops = prepareOptionCLI();
- if (args.length == 0) {
- printHelp(ops);
- }
- CommandLineParser parser = new PosixParser();
- CommandLine cmd = null;
- try {
- cmd = parser.parse(ops, args);
- } catch (ParseException e) {
- printHelp(ops);
- }
+ private static CommandLine getCommandLine(String[] args) {
+ Options ops = prepareOptionCLI();
+ if (args.length == 0) {
+ printHelp(ops);
+ }
+ CommandLineParser parser = new PosixParser();
+ CommandLine cmd = null;
+ try {
+ cmd = parser.parse(ops, args);
+ } catch (ParseException e) {
+ printHelp(ops);
+ }
- if (cmd.hasOption('h')) {
- printHelp(ops);
- }
+ if (cmd.hasOption('h')) {
+ printHelp(ops);
+ }
- return cmd;
- }
+ return cmd;
+ }
- private static void printHelp(Options ops) {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp("securis-client", ops, true);
- System.exit(-1);
- }
+ private static void printHelp(Options ops) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("securis-client", ops, true);
+ System.exit(-1);
+ }
- @SuppressWarnings("static-access")
- private static Options prepareOptionCLI() {
- Options options = new Options();
+ @SuppressWarnings("static-access")
+ private static Options prepareOptionCLI() {
+ Options options = new Options();
- options.addOption("h", "help", false, "Show help.");
- options.addOption(OptionBuilder.withArgName("req_file").withLongOpt("rfile").withDescription("Set request file for its generation or for license requesting.").hasArg(true).create('r'));
- // options.addOption(OptionBuilder.withArgName("url_license_server").withLongOpt("server").withDescription("License server url.").hasArg(true).create('s'));
- options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("validate").withDescription("Validate lic file.").hasArg(true).create('l'));
+ options.addOption("h", "help", false, "Show help.");
+ options.addOption(OptionBuilder.withArgName("req_file").withLongOpt("rfile")
+ .withDescription("Set request file for its generation or for license requesting.").hasArg(true).create('r'));
+ // options.addOption(OptionBuilder.withArgName("url_license_server").withLongOpt("server").withDescription("License server url.").hasArg(true).create('s'));
+ options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("validate").withDescription("Validate lic file.").hasArg(true)
+ .create('l'));
- options.addOption("g", "gen_request", false, "Generate request file. If --rfile parameter is missing then It is generated in current directory.");
- options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("create").withDescription("Request a license file to server.").hasArg(true).hasOptionalArg().create('c'));
- options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. ");
- options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("renew").withDescription("Synchronize/renew the current license file.").hasArg(true).create('r'));
+ options.addOption("g", "gen_request", false,
+ "Generate request file. If --rfile parameter is missing then It is generated in current directory.");
+ options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("create").withDescription("Request a license file to server.")
+ .hasArg(true).hasOptionalArg().create('c'));
+ options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. ");
+ options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("renew").withDescription("Synchronize/renew the current license file.")
+ .hasArg(true).create('r'));
- return options;
- }
+ return options;
+ }
}
diff --git a/src/main/java/net/curisit/securis/LicenseManager.java b/src/main/java/net/curisit/securis/LicenseManager.java
index d05a2d2..1298d81 100644
--- a/src/main/java/net/curisit/securis/LicenseManager.java
+++ b/src/main/java/net/curisit/securis/LicenseManager.java
@@ -28,38 +28,39 @@
*/
public class LicenseManager {
- private static final Logger LOG = LogManager.getLogger(License.class);
+ private static final Logger LOG = LogManager.getLogger(License.class);
- private static LicenseManager singleton = new LicenseManager();
+ private static LicenseManager singleton = new LicenseManager();
- public static final String PING_MESSAGE = "SeCuris API OK";
-
- private LicenseManager() {
- }
+ public static final String PING_MESSAGE = "SeCuris API OK";
- public static LicenseManager getInstance() {
- return singleton;
- }
+ private LicenseManager() {
+ }
- /**
- * Loads a license from file
- *
- * @param licFile
- * @return The license bean
- * @throws SeCurisException
- */
- public LicenseBean load(File licFile) throws SeCurisException {
- LicenseBean licBean;
- try {
- licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
- } catch (IOException e) {
- throw new SeCurisException("Error getting license data from file: " + licFile, e);
- }
- return licBean;
- }
+ public static LicenseManager getInstance() {
+ return singleton;
+ }
/**
- * Validates the license stored in {@code licFile} and get the corresponding LicenseBean
+ * Loads a license from file
+ *
+ * @param licFile
+ * @return The license bean
+ * @throws SeCurisException
+ */
+ public LicenseBean load(File licFile) throws SeCurisException {
+ LicenseBean licBean;
+ try {
+ licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
+ } catch (IOException e) {
+ throw new SeCurisException("Error getting license data from file: " + licFile, e);
+ }
+ return licBean;
+ }
+
+ /**
+ * Validates the license stored in {@code licFile} and get the corresponding
+ * LicenseBean
* <p>
* The validation includes:
* <ul>
@@ -79,7 +80,8 @@
}
/**
- * Validates the license stored in {@code licFile} and get the corresponding LicenseBean. The License date is not validated
+ * Validates the license stored in {@code licFile} and get the corresponding
+ * LicenseBean. The License date is not validated
* <p>
* The validation includes:
* <ul>
@@ -96,7 +98,8 @@
public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException {
LicenseBean licBean = load(licFile);
SignatureHelper.getInstance().validateSignature(licBean);
- LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
+ Params.get(Params.KEYS.PACK_CODE));
LicenseValidator.getInstance().validateLogo(licBean);
if (!excludeDateValidation) {
@@ -108,18 +111,19 @@
return licBean;
}
- /**
- * Request to server for a valid license
- *
- * @return The license bean returned by the server
- * @throws SeCurisException
- */
- public SignedLicenseBean requestLicense() throws SeCurisException {
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
+ /**
+ * Request to server for a valid license
+ *
+ * @return The license bean returned by the server
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean requestLicense() throws SeCurisException {
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
+ Params.get(Params.KEYS.PACK_CODE));
- SignedLicenseBean lic = requestLicenseToServer(req);
- return lic;
- }
+ SignedLicenseBean lic = requestLicenseToServer(req);
+ return lic;
+ }
/**
* Generate a license file using a {@link LicenseBean}
@@ -157,43 +161,47 @@
}
- private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException {
- SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req);
-
- return lic;
- }
+ private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException {
+ SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req);
- /**
- * Creates a new request file with current hardware in the File passed as parameter
- *
- * @param outputRequestFile
- * File where the request data will be saved
- * @return The generated request bean
- * @throws SeCurisException
- */
- public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
+ return lic;
+ }
- ReqGenerator.getInstance().save(req, outputRequestFile);
+ /**
+ * Creates a new request file with current hardware in the File passed as
+ * parameter
+ *
+ * @param outputRequestFile
+ * File where the request data will be saved
+ * @return The generated request bean
+ * @throws SeCurisException
+ */
+ public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
+ Params.get(Params.KEYS.PACK_CODE));
- return req;
- }
+ ReqGenerator.getInstance().save(req, outputRequestFile);
- /**
- * Send the current license file to server, which is previously validated, to get a renewed one if it is prepared in server side.
- *
- * @param licenseFile
- * Current and valid License file
- * @return New license bean if server creates a new one, otherwise the same current License bean will be returned
- * @throws SeCurisException
- */
- public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
- LicenseBean lic = validateLicense(licenseFile);
+ return req;
+ }
+
+ /**
+ * Send the current license file to server, which is previously validated,
+ * to get a renewed one if it is prepared in server side.
+ *
+ * @param licenseFile
+ * Current and valid License file
+ * @return New license bean if server creates a new one, otherwise the same
+ * current License bean will be returned
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
+ LicenseBean lic = validateLicense(licenseFile);
SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic);
- return newLic;
- }
+ return newLic;
+ }
public void testServer() throws SeCurisException {
StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class);
diff --git a/src/main/java/net/curisit/securis/LicenseValidator.java b/src/main/java/net/curisit/securis/LicenseValidator.java
index a8d9d7b..ad4bd29 100644
--- a/src/main/java/net/curisit/securis/LicenseValidator.java
+++ b/src/main/java/net/curisit/securis/LicenseValidator.java
@@ -14,55 +14,56 @@
public class LicenseValidator {
- private static final Logger LOG = LogManager.getLogger(LicenseValidator.class);
+ private static final Logger LOG = LogManager.getLogger(LicenseValidator.class);
- private static LicenseValidator singleton = new LicenseValidator();
- protected static byte[] LOGO_SECRET;
+ private static LicenseValidator singleton = new LicenseValidator();
+ protected static byte[] LOGO_SECRET;
- static {
- try {
- LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8");
- } catch (UnsupportedEncodingException e) {
- LOG.error("Unexpected error getting LOGO secret", e);
- }
- }
+ static {
+ try {
+ LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8");
+ } catch (UnsupportedEncodingException e) {
+ LOG.error("Unexpected error getting LOGO secret", e);
+ }
+ }
- private LicenseValidator() {
- }
+ private LicenseValidator() {
+ }
- public static LicenseValidator getInstance() {
- return singleton;
- }
+ public static LicenseValidator getInstance() {
+ return singleton;
+ }
- /**
- * @return CRC string for customer logo
- */
- public String getCrcLogo() {
- InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png");
- try {
- String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
- return shaLogo;
- } catch (IOException e) {
- LOG.warn("Customer logo was not found in images/logo_customer.png");
- return null;
- }
- }
+ /**
+ * @return CRC string for customer logo
+ */
+ public String getCrcLogo() {
+ InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png");
+ try {
+ String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
+ return shaLogo;
+ } catch (IOException e) {
+ LOG.warn("Customer logo was not found in images/logo_customer.png");
+ return null;
+ }
+ }
- public void validateLogo(RequestBean reqBean) throws SeCurisException {
- if (reqBean.getCrcLogo() == null) {
- LOG.info("Customer logo is not included in license file and won't be validated");
- } else {
- String currentCRC = getCrcLogo();
- if (!currentCRC.equals(reqBean.getCrcLogo()))
- throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean));
- }
- }
+ public void validateLogo(RequestBean reqBean) throws SeCurisException {
+ if (reqBean.getCrcLogo() == null) {
+ LOG.info("Customer logo is not included in license file and won't be validated");
+ } else {
+ String currentCRC = getCrcLogo();
+ if (!currentCRC.equals(reqBean.getCrcLogo()))
+ throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean));
+ }
+ }
- public void validateHW(RequestBean reqBean, String appCode, String customerCode) throws SeCurisException {
- RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode);
- if (!currentHW.match(reqBean)) {
- throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: " + JsonUtils.toJSON(reqBean, true) + "\n Expected: " + JsonUtils.toJSON(currentHW, true));
- }
- }
+ public void validateHW(RequestBean reqBean, String appCode, String customerCode, String packCode) throws SeCurisException {
+ RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode, packCode);
+ if (!currentHW.match(reqBean)) {
+ throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: " + JsonUtils.toJSON(reqBean, true)
+ + "\n Expected: " + JsonUtils.toJSON(currentHW, true));
+ }
+ }
}
diff --git a/src/main/java/net/curisit/securis/ReqGenerator.java b/src/main/java/net/curisit/securis/ReqGenerator.java
index 38716bc..d486a63 100644
--- a/src/main/java/net/curisit/securis/ReqGenerator.java
+++ b/src/main/java/net/curisit/securis/ReqGenerator.java
@@ -19,76 +19,77 @@
public class ReqGenerator {
- private static final Logger LOG = LogManager.getLogger(ReqGenerator.class);
+ private static final Logger LOG = LogManager.getLogger(ReqGenerator.class);
- private static ReqGenerator singleton = new ReqGenerator();
+ private static ReqGenerator singleton = new ReqGenerator();
- private ReqGenerator() {
- }
+ private ReqGenerator() {
+ }
- public static ReqGenerator getInstance() {
- return singleton;
- }
+ public static ReqGenerator getInstance() {
+ return singleton;
+ }
- public RequestBean createRequest(String appCode, String customerCode) throws SeCurisException {
- RequestBean req = new RequestBean();
+ public RequestBean createRequest(String licTypeCode, String customerCode, String packCode) throws SeCurisException {
+ RequestBean req = new RequestBean();
- req.setAppCode(appCode);
- req.setCustomerCode(customerCode);
- req.setArch(HWInfo.getArch());
- req.setCrcLogo(getCrcLogo());
- req.setMacAddresses(HWInfo.getMACAddress());
- req.setOsName(HWInfo.getOsName());
+ req.setLicenseTypeCode(licTypeCode);
+ req.setCustomerCode(customerCode);
+ req.setPackCode(packCode);
+ req.setArch(HWInfo.getArch());
+ req.setCrcLogo(getCrcLogo());
+ req.setMacAddresses(HWInfo.getMACAddress());
+ req.setOsName(HWInfo.getOsName());
- return req;
- }
+ return req;
+ }
- public RequestBean loadRequest(File requestFile) throws SeCurisException {
- try {
- String json = new String(Files.readAllBytes(Paths.get(requestFile.toURI())), "utf-8");
- RequestBean req = JsonUtils.json2object(json, RequestBean.class);
- return req;
- } catch (IOException e) {
- LOG.error("Request file {} was not found or is not accesible");
- throw new SeCurisException("ERROR accesing request file: " + requestFile.getAbsolutePath(), e);
- }
- }
+ public RequestBean loadRequest(File requestFile) throws SeCurisException {
+ try {
+ String json = new String(Files.readAllBytes(Paths.get(requestFile.toURI())), "utf-8");
+ RequestBean req = JsonUtils.json2object(json, RequestBean.class);
+ return req;
+ } catch (IOException e) {
+ LOG.error("Request file {} was not found or is not accesible");
+ throw new SeCurisException("ERROR accesing request file: " + requestFile.getAbsolutePath(), e);
+ }
+ }
- /**
- * Generate a request file using a {@link RequestBean}
- *
- * @param req
- * @param file
- * @throws SeCurisException
- */
- public void save(RequestBean req, File file) throws SeCurisException {
- byte[] json;
- try {
- json = JsonUtils.toJSON(req, true).getBytes("utf-8");
- Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
- } catch (UnsupportedEncodingException e) {
- LOG.error("Error creating json doc from request: " + req, e);
- throw new SeCurisException("Error creating json doc from request: " + req, e);
- } catch (IOException e) {
- LOG.error("Error creating request file: " + file, e);
- throw new SeCurisException("Error creating request file: " + file, e);
- }
+ /**
+ * Generate a request file using a {@link RequestBean}
+ *
+ * @param req
+ * @param file
+ * @throws SeCurisException
+ */
+ public void save(RequestBean req, File file) throws SeCurisException {
+ byte[] json;
+ try {
+ json = JsonUtils.toJSON(req, true).getBytes("utf-8");
+ Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
+ } catch (UnsupportedEncodingException e) {
+ LOG.error("Error creating json doc from request: " + req, e);
+ throw new SeCurisException("Error creating json doc from request: " + req, e);
+ } catch (IOException e) {
+ LOG.error("Error creating request file: " + file, e);
+ throw new SeCurisException("Error creating request file: " + file, e);
+ }
- LOG.debug("License saved in {}", file);
+ LOG.debug("License saved in {}", file);
- }
+ }
- private String getCrcLogo() {
- String logResource = "images/logo_customer.png";
- InputStream is = getClass().getClassLoader().getResourceAsStream(logResource);
- if (is == null)
- return null;
- try {
- String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LicenseValidator.LOGO_SECRET);
- return shaLogo;
- } catch (IOException e) {
- LOG.error("Customer logo was not found in classpath in " + logResource, e);
- return null;
- }
- }
+ private String getCrcLogo() {
+ String logResource = "images/logo_customer.png";
+ InputStream is = getClass().getClassLoader().getResourceAsStream(logResource);
+ if (is == null)
+ return null;
+ try {
+ String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LicenseValidator.LOGO_SECRET);
+ return shaLogo;
+ } catch (IOException e) {
+ LOG.error("Customer logo was not found in classpath in " + logResource, e);
+ return null;
+ }
+ }
}
diff --git a/src/main/java/net/curisit/securis/beans/LicenseBean.java b/src/main/java/net/curisit/securis/beans/LicenseBean.java
index 4fbdbcd..6fad59c 100644
--- a/src/main/java/net/curisit/securis/beans/LicenseBean.java
+++ b/src/main/java/net/curisit/securis/beans/LicenseBean.java
@@ -10,94 +10,97 @@
import org.codehaus.jackson.annotate.JsonPropertyOrder;
@JsonAutoDetect
-@JsonPropertyOrder(
- { "licenseCode", "licenseType", "expirationDate", "appCode", "arch", "osName", "customerCode", "macAddresses", "crcLogo", "metadata" })
+@JsonPropertyOrder({
+ "appName", "licenseCode", "licenseTypeCode", "expirationDate", "arch", "osName", "customerCode", "macAddresses", "crcLogo", "metadata"
+})
public class LicenseBean extends RequestBean {
- private Date expirationDate;
- /**
- * Signature is stored in Base64 code
- */
- private String signature;
- private String licenseType;
- private String licenseCode;
+ private Date expirationDate;
+ /**
+ * Signature is stored in Base64 code
+ */
+ private String signature;
+ private String licenseCode;
+ private String appName;
- private Map<String, Object> metadata;
+ private Map<String, Object> metadata;
- public LicenseBean() {
- }
+ public LicenseBean() {
+ }
- public LicenseBean(RequestBean req) {
- super.setAppCode(req.getAppCode());
- super.setArch(req.getArch());
- super.setCrcLogo(req.getCrcLogo());
- super.setCustomerCode(req.getCustomerCode());
- super.setMacAddresses(req.getMacAddresses());
- super.setOsName(req.getOsName());
- }
+ public LicenseBean(RequestBean req) {
+ super.setPackCode(req.getPackCode());
+ super.setLicenseTypeCode(req.getLicenseTypeCode());
+ super.setCustomerCode(req.getCustomerCode());
+ super.setArch(req.getArch());
+ super.setCrcLogo(req.getCrcLogo());
+ super.setMacAddresses(req.getMacAddresses());
+ super.setOsName(req.getOsName());
+ }
- public Map<String, Object> getMetadata() {
- return metadata;
- }
+ public Map<String, Object> getMetadata() {
+ return metadata;
+ }
- public void setMetadata(Map<String, Object> metadata) {
- this.metadata = new TreeMap<>(metadata);
- }
+ public void setMetadata(Map<String, Object> metadata) {
+ this.metadata = new TreeMap<>(metadata);
+ }
- @JsonIgnore
- public String getSignature() {
- return signature;
- }
+ @JsonIgnore
+ public String getSignature() {
+ return signature;
+ }
- @JsonProperty("signature")
- public void setSignature(String signature) {
- this.signature = signature;
- }
+ @JsonProperty("signature")
+ public void setSignature(String signature) {
+ this.signature = signature;
+ }
- public Date getExpirationDate() {
- return expirationDate;
- }
+ public Date getExpirationDate() {
+ return expirationDate;
+ }
- public void setExpirationDate(Date expirationDate) {
- this.expirationDate = expirationDate;
- }
+ public void setExpirationDate(Date expirationDate) {
+ this.expirationDate = expirationDate;
+ }
- @Override
- public int hashCode() {
- int code = 0;
- code += expirationDate != null ? expirationDate.hashCode() : 0;
- code += signature != null ? signature.hashCode() : 0;
- code += metadata != null ? metadata.hashCode() : 0;
-
- return code;
- };
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof LicenseBean))
- return false;
- LicenseBean rb = (LicenseBean) obj;
- boolean result = true;
- result = result && ((expirationDate == null && rb.expirationDate == null) || (expirationDate != null && expirationDate.equals(rb.expirationDate)));
- result = result && ((signature == null && rb.signature == null) || (signature != null && signature.equals(rb.signature)));
- result = result && ((metadata == null && rb.metadata == null) || (metadata != null && metadata.equals(rb.metadata)));
+ @Override
+ public int hashCode() {
+ int code = 0;
+ code += expirationDate != null ? expirationDate.hashCode() : 0;
+ code += signature != null ? signature.hashCode() : 0;
+ code += metadata != null ? metadata.hashCode() : 0;
- return result && super.equals(obj);
- }
+ return code;
+ };
- public String getLicenseCode() {
- return licenseCode;
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof LicenseBean))
+ return false;
+ LicenseBean rb = (LicenseBean) obj;
+ boolean result = true;
+ result = result
+ && ((expirationDate == null && rb.expirationDate == null) || (expirationDate != null && expirationDate.equals(rb.expirationDate)));
+ result = result && ((signature == null && rb.signature == null) || (signature != null && signature.equals(rb.signature)));
+ result = result && ((metadata == null && rb.metadata == null) || (metadata != null && metadata.equals(rb.metadata)));
- public void setLicenseCode(String licenseCode) {
- this.licenseCode = licenseCode;
- }
+ return result && super.equals(obj);
+ }
- public String getLicenseType() {
- return licenseType;
- }
+ public String getLicenseCode() {
+ return licenseCode;
+ }
- public void setLicenseType(String licenseType) {
- this.licenseType = licenseType;
- }
+ public void setLicenseCode(String licenseCode) {
+ this.licenseCode = licenseCode;
+ }
+
+ public String getAppName() {
+ return appName;
+ }
+
+ public void setAppName(String appName) {
+ this.appName = appName;
+ }
}
diff --git a/src/main/java/net/curisit/securis/beans/RequestBean.java b/src/main/java/net/curisit/securis/beans/RequestBean.java
index 79ae171..2a79911 100644
--- a/src/main/java/net/curisit/securis/beans/RequestBean.java
+++ b/src/main/java/net/curisit/securis/beans/RequestBean.java
@@ -8,107 +8,119 @@
@JsonAutoDetect
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class RequestBean {
- private String customerCode;
- private String crcLogo;
- private String appCode;
- private List<String> macAddresses;
- private String osName;
- private String arch;
+ private String customerCode;
+ private String crcLogo;
+ private String licenseTypeCode;
+ private String packCode;
+ private List<String> macAddresses;
+ private String osName;
+ private String arch;
- public String getCustomerCode() {
- return customerCode;
- }
+ public String getCustomerCode() {
+ return customerCode;
+ }
- public void setCustomerCode(String customerCode) {
- this.customerCode = customerCode;
- }
+ public void setCustomerCode(String customerCode) {
+ this.customerCode = customerCode;
+ }
- public String getCrcLogo() {
- return crcLogo;
- }
+ public String getCrcLogo() {
+ return crcLogo;
+ }
- public void setCrcLogo(String crcLogo) {
- this.crcLogo = crcLogo;
- }
+ public void setCrcLogo(String crcLogo) {
+ this.crcLogo = crcLogo;
+ }
- public String getAppCode() {
- return appCode;
- }
+ public List<String> getMacAddresses() {
+ return macAddresses;
+ }
- public void setAppCode(String appCode) {
- this.appCode = appCode;
- }
+ public void setMacAddresses(List<String> macAddresses) {
+ this.macAddresses = macAddresses;
+ }
- public List<String> getMacAddresses() {
- return macAddresses;
- }
+ public String getOsName() {
+ return osName;
+ }
- public void setMacAddresses(List<String> macAddresses) {
- this.macAddresses = macAddresses;
- }
+ public void setOsName(String osName) {
+ this.osName = osName;
+ }
- public String getOsName() {
- return osName;
- }
+ public String getArch() {
+ return arch;
+ }
- public void setOsName(String osName) {
- this.osName = osName;
- }
+ public void setArch(String arch) {
+ this.arch = arch;
+ }
- public String getArch() {
- return arch;
- }
+ public boolean match(RequestBean rb) {
- public void setArch(String arch) {
- this.arch = arch;
- }
+ boolean result = licenseTypeCode != null && licenseTypeCode.equals(rb.licenseTypeCode);
+ result = result && (packCode != null && packCode.equals(rb.packCode));
+ result = result && (arch != null && arch.equals(rb.arch));
+ // CRC Logo validation is optional, only if request file contains it
+ result = result && (crcLogo == null || crcLogo.equals(rb.crcLogo));
+ result = result && (customerCode != null && customerCode.equals(rb.customerCode));
+ result = result && (osName != null && osName.equals(rb.osName));
+ result = result && (macAddresses != null && rb.macAddresses != null) && anyMacIsIncluded(rb.getMacAddresses());
- public boolean match(RequestBean rb) {
+ return result;
+ }
- boolean result = appCode != null && appCode.equals(rb.appCode);
- result = result && (arch != null && arch.equals(rb.arch));
- // CRC Logo validation is optional, only if request file contains it
- result = result && (crcLogo == null || crcLogo.equals(rb.crcLogo));
- result = result && (customerCode != null && customerCode.equals(rb.customerCode));
- result = result && (osName != null && osName.equals(rb.osName));
- result = result && (macAddresses != null && rb.macAddresses != null) && anyMacIsIncluded(rb.getMacAddresses());
+ private boolean anyMacIsIncluded(List<String> macList) {
+ for (String mac : macList) {
+ if (macAddresses.contains(mac))
+ return true;
+ }
+ return false;
+ }
- return result;
- }
+ @Override
+ public int hashCode() {
+ int code = 0;
+ code += licenseTypeCode != null ? licenseTypeCode.hashCode() : 0;
+ code += arch != null ? arch.hashCode() : 0;
+ code += crcLogo != null ? crcLogo.hashCode() : 0;
+ code += packCode != null ? packCode.hashCode() : 0;
+ code += customerCode != null ? customerCode.hashCode() : 0;
+ code += osName != null ? osName.hashCode() : 0;
+ code += macAddresses != null ? macAddresses.hashCode() : 0;
- private boolean anyMacIsIncluded(List<String> macList) {
- for (String mac : macList) {
- if (macAddresses.contains(mac))
- return true;
- }
- return false;
- }
+ return code;
+ };
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof RequestBean))
+ return false;
+ RequestBean rb = (RequestBean) obj;
+ boolean result = (rb.licenseTypeCode == null && licenseTypeCode == null)
+ || (licenseTypeCode != null && licenseTypeCode.equals(rb.licenseTypeCode));
+ result = result && ((rb.packCode == null && packCode == null) || (packCode != null && packCode.equals(rb.arch)));
+ result = result && ((rb.arch == null && arch == null) || (arch != null && arch.equals(rb.arch)));
+ result = result && ((rb.crcLogo == null && crcLogo == null) || (crcLogo != null && crcLogo.equals(rb.crcLogo)));
+ result = result && ((rb.customerCode == null && customerCode == null) || (customerCode != null && customerCode.equals(rb.customerCode)));
+ result = result && ((rb.osName == null && osName == null) || (osName != null && osName.equals(rb.osName)));
+ result = result && ((rb.macAddresses == null && macAddresses == null) || (macAddresses != null && macAddresses.equals(rb.macAddresses)));
+ return result;
+ }
- @Override
- public int hashCode() {
- int code = 0;
- code += appCode != null ? appCode.hashCode() : 0;
- code += arch != null ? arch.hashCode() : 0;
- code += crcLogo != null ? crcLogo.hashCode() : 0;
- code += customerCode != null ? customerCode.hashCode() : 0;
- code += osName != null ? osName.hashCode() : 0;
- code += macAddresses != null ? macAddresses.hashCode() : 0;
-
- return code;
- };
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof RequestBean))
- return false;
- RequestBean rb = (RequestBean) obj;
- boolean result = (rb.appCode == null && appCode == null) || (appCode != null && appCode.equals(rb.appCode));
- result = result && ((rb.arch == null && arch == null) || (arch != null && arch.equals(rb.arch)));
- result = result && ((rb.crcLogo == null && crcLogo == null) || (crcLogo != null && crcLogo.equals(rb.crcLogo)));
- result = result && ((rb.customerCode == null && customerCode == null) || (customerCode != null && customerCode.equals(rb.customerCode)));
- result = result && ((rb.osName == null && osName == null) || (osName != null && osName.equals(rb.osName)));
- result = result && ((rb.macAddresses == null && macAddresses == null) || (macAddresses != null && macAddresses.equals(rb.macAddresses)));
- return result;
- }
+ public String getPackCode() {
+ return packCode;
+ }
+
+ public void setPackCode(String packCode) {
+ this.packCode = packCode;
+ }
+
+ public String getLicenseTypeCode() {
+ return licenseTypeCode;
+ }
+
+ public void setLicenseTypeCode(String licenseTypeCode) {
+ this.licenseTypeCode = licenseTypeCode;
+ }
}
diff --git a/src/main/java/net/curisit/securis/beans/SignedLicenseBean.java b/src/main/java/net/curisit/securis/beans/SignedLicenseBean.java
index bcfcf83..94e127e 100644
--- a/src/main/java/net/curisit/securis/beans/SignedLicenseBean.java
+++ b/src/main/java/net/curisit/securis/beans/SignedLicenseBean.java
@@ -6,21 +6,22 @@
@JsonAutoDetect
public class SignedLicenseBean extends LicenseBean {
- @JsonProperty("signature")
- public String getCurrentSignature() {
- return super.getSignature();
- }
-
- public SignedLicenseBean() {
- }
+ @JsonProperty("signature")
+ public String getCurrentSignature() {
+ return super.getSignature();
+ }
- public SignedLicenseBean(LicenseBean lb) {
- super(lb);
- setSignature(lb.getSignature());
- setExpirationDate(lb.getExpirationDate());
- setLicenseCode(lb.getLicenseCode());
- setLicenseType(lb.getLicenseType());
- setMetadata(lb.getMetadata());
- }
+ public SignedLicenseBean() {
+ }
+
+ public SignedLicenseBean(LicenseBean lb) {
+ super(lb);
+ setSignature(lb.getSignature());
+ setExpirationDate(lb.getExpirationDate());
+ setPackCode(lb.getPackCode());
+ setLicenseCode(lb.getLicenseCode());
+ setAppName(lb.getAppName());
+ setMetadata(lb.getMetadata());
+ }
}
diff --git a/src/main/java/net/curisit/securis/utils/Params.java b/src/main/java/net/curisit/securis/utils/Params.java
index 14d1b37..ce20eac 100644
--- a/src/main/java/net/curisit/securis/utils/Params.java
+++ b/src/main/java/net/curisit/securis/utils/Params.java
@@ -17,182 +17,197 @@
*/
public class Params {
- private static final Logger LOG = LogManager.getLogger(Params.class);
+ private static final Logger LOG = LogManager.getLogger(Params.class);
- /**
- * Key used to store config file resource location. In a web application, can be set as initial parameter in a servlet loaded on startup
- */
+ /**
+ * Key used to store config file resource location. In a web application,
+ * can be set as initial parameter in a servlet loaded on startup
+ */
public static final String DEFAUT_SERVER_URL = "https://securis.curistec.com/api";
- public static final String KEY_CONFIG_FILE = "/securis-client.properties";
+ public static final String KEY_CONFIG_FILE = "/securis-server.properties";
- private static Properties params = null;
+ private static Properties params = null;
- static {
- try {
- loadParameters(KEY_CONFIG_FILE);
- } catch (IOException e) {
- LOG.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
- System.exit(-2);
- }
- }
+ static {
+ try {
+ loadParameters(KEY_CONFIG_FILE);
+ } catch (IOException e) {
+ LOG.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
+ System.exit(-2);
+ }
+ }
- /**
- * Loads application global parameters from a classpath resource
- *
- * @param resource
- * : Resource location in classpath, i.e: "/resource/cp-securis.conf"
- * @throws IOException
- */
- public static void loadParameters(String resource) throws IOException {
+ /**
+ * Loads application global parameters from a classpath resource
+ *
+ * @param resource
+ * : Resource location in classpath, i.e:
+ * "/resource/cp-securis.conf"
+ * @throws IOException
+ */
+ public static void loadParameters(String resource) throws IOException {
- LOG.debug("Loading params from " + resource);
- InputStream fileis = Params.class.getResourceAsStream(resource);
+ LOG.debug("Loading params from " + resource);
+ InputStream fileis = Params.class.getResourceAsStream(resource);
- params = new Properties();
- try {
+ params = new Properties();
+ try {
- params.load(fileis);
- LOG.debug("Params loaded OK from {}", resource);
- } catch (IOException e) {
- LOG.error("Error loading config file: " + e);
- params = null;
- throw e;
- }
+ params.load(fileis);
+ LOG.debug("Params loaded OK from {}", resource);
+ } catch (IOException e) {
+ LOG.error("Error loading config file: " + e);
+ params = null;
+ throw e;
+ }
- }
+ }
- public static String getByDomain(String domain, String paramname) {
- return getByDomain(domain, paramname, null);
- }
+ public static String getByDomain(String domain, String paramname) {
+ return getByDomain(domain, paramname, null);
+ }
- public static String getByPrefix(String prefix, String paramname) {
- return get(prefix + "." + paramname, get(paramname));
- }
+ public static String getByPrefix(String prefix, String paramname) {
+ return get(prefix + "." + paramname, get(paramname));
+ }
- public static String getByPrefix(String prefix, String paramname, String defaultVal) {
- return get(prefix + "." + paramname, get(paramname, defaultVal));
- }
+ public static String getByPrefix(String prefix, String paramname, String defaultVal) {
+ return get(prefix + "." + paramname, get(paramname, defaultVal));
+ }
- public static String getByDomain(String domain, String paramname, String defaultval) {
- return get(paramname + "." + domain, defaultval);
- }
+ public static String getByDomain(String domain, String paramname, String defaultval) {
+ return get(paramname + "." + domain, defaultval);
+ }
- public static int getIntByDomain(String domain, String paramname) {
- return getInt(paramname + "." + domain, getInt(paramname));
- }
+ public static int getIntByDomain(String domain, String paramname) {
+ return getInt(paramname + "." + domain, getInt(paramname));
+ }
- public static int getIntByDomain(String domain, String paramname, int defaultval) {
- return getInt(paramname + "." + domain, defaultval);
- }
+ public static int getIntByDomain(String domain, String paramname, int defaultval) {
+ return getInt(paramname + "." + domain, defaultval);
+ }
- /**
- * Gets a List with all values of properties that begins with <code>prefix</code> It reads sequentially. For example:
- *
- * <pre>
- * securis.sort.comparator.0: net.cp.securis.comparators.ComparePttidVsPtn
- * securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency
- * securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming
- * securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration
- * securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms
- * </pre>
- *
- * That config (for prefix: "securis.sort.comparator" ) will return a List<String> with values:
- *
- * <pre>
- * "net.cp.securis.comparators.ComparePttidVsPtn",
- * "net.cp.securis.comparators.CompareFrequency",
- * "net.cp.securis.comparators.CompareOutgoingVsIncomming",
- * "net.cp.securis.comparators.CompareDuration",
- * "net.cp.securis.comparators.CompareCallVsSms"
- * </pre>
- *
- * Note: If there is a gap between suffixes process will stop, that is, only will be returned properties found before gap.
- *
- * @param prefix
- * @return
- */
- public static List<String> getListByPrefix(String prefix) {
- List<String> list = new ArrayList<String>();
+ /**
+ * Gets a List with all values of properties that begins with
+ * <code>prefix</code> It reads sequentially. For example:
+ *
+ * <pre>
+ * securis.sort.comparator.0: net.cp.securis.comparators.ComparePttidVsPtn
+ * securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency
+ * securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming
+ * securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration
+ * securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms
+ * </pre>
+ *
+ * That config (for prefix: "securis.sort.comparator" ) will return a
+ * List<String> with values:
+ *
+ * <pre>
+ * "net.cp.securis.comparators.ComparePttidVsPtn",
+ * "net.cp.securis.comparators.CompareFrequency",
+ * "net.cp.securis.comparators.CompareOutgoingVsIncomming",
+ * "net.cp.securis.comparators.CompareDuration",
+ * "net.cp.securis.comparators.CompareCallVsSms"
+ * </pre>
+ *
+ * Note: If there is a gap between suffixes process will stop, that is, only
+ * will be returned properties found before gap.
+ *
+ * @param prefix
+ * @return
+ */
+ public static List<String> getListByPrefix(String prefix) {
+ List<String> list = new ArrayList<String>();
- String tpl = prefix + ".{0}";
+ String tpl = prefix + ".{0}";
- int i = 0;
- String value = get(MessageFormat.format(tpl, i++));
- while (value != null) {
- list.add(value);
- value = get(MessageFormat.format(tpl, i++));
- }
+ int i = 0;
+ String value = get(MessageFormat.format(tpl, i++));
+ while (value != null) {
+ list.add(value);
+ value = get(MessageFormat.format(tpl, i++));
+ }
- return list;
- }
+ return list;
+ }
- /**
- * Gets param value in config file or environment variables
- *
- * @param paramname
- * Global parameter's name
- * @return Value of paramname or null if paramname is not found neither in config file nor in environment variables
- */
- public static String get(String paramname) {
+ /**
+ * Gets param value in config file or environment variables
+ *
+ * @param paramname
+ * Global parameter's name
+ * @return Value of paramname or null if paramname is not found neither in
+ * config file nor in environment variables
+ */
+ public static String get(String paramname) {
- assert (params != null) : "Parameters have not been loaded. Call method loadParameters(resource) before use Params.";
+ assert (params != null) : "Parameters have not been loaded. Call method loadParameters(resource) before use Params.";
- String value = params.getProperty(paramname);
- if (value == null)
- value = System.getenv(paramname);
- return value;
- }
+ String value = params.getProperty(paramname);
+ if (value == null)
+ value = System.getenv(paramname);
+ return value;
+ }
- /**
- * Gets param value from config file or environment variables
- *
- * @param paramname
- * Global parameter's name
- * @param defaultval
- * @return Value of paramname or defaultval if paramname is not found
- */
- public static String get(String paramname, String defaultval) {
- String value = get(paramname);
- return (value == null ? defaultval : value);
- }
+ /**
+ * Gets param value from config file or environment variables
+ *
+ * @param paramname
+ * Global parameter's name
+ * @param defaultval
+ * @return Value of paramname or defaultval if paramname is not found
+ */
+ public static String get(String paramname, String defaultval) {
+ String value = get(paramname);
+ return (value == null ? defaultval : value);
+ }
- /**
- * Gets param value in config file or environment variables
- *
- * @param paramname
- * Global parameter's name
- * @return Integer value of paramname or -1 if paramname is not found neither in config file nor in environment variables
- */
- public static int getInt(String paramname) {
- String value = get(paramname);
- return (value == null ? -1 : Integer.parseInt(value));
- }
+ /**
+ * Gets param value in config file or environment variables
+ *
+ * @param paramname
+ * Global parameter's name
+ * @return Integer value of paramname or -1 if paramname is not found
+ * neither in config file nor in environment variables
+ */
+ public static int getInt(String paramname) {
+ String value = get(paramname);
+ return (value == null ? -1 : Integer.parseInt(value));
+ }
- /**
- * Gets param value from config file or environment variables
- *
- * @param paramname
- * Global parameter's name
- * @param defaultval
- * @return Integer value of paramname or defaultval if paramname is not found
- */
- public static int getInt(String paramname, int defaultval) {
- String value = get(paramname);
- return (value == null ? defaultval : Integer.parseInt(value));
- }
+ /**
+ * Gets param value from config file or environment variables
+ *
+ * @param paramname
+ * Global parameter's name
+ * @param defaultval
+ * @return Integer value of paramname or defaultval if paramname is not
+ * found
+ */
+ public static int getInt(String paramname, int defaultval) {
+ String value = get(paramname);
+ return (value == null ? defaultval : Integer.parseInt(value));
+ }
- public static class KEYS {
+ public static class KEYS {
- /**
- * Public key file, Usually in "PEM" format
- */
- public static final String PUBLIC_KEY_FILE = "public.key.file";
+ /**
+ * Public key file, Usually in "PEM" format
+ */
+ public static final String PUBLIC_KEY_FILE = "public.key.file";
- public static final String APPLICATION_CODE = "app.code";
+ public static final String APPLICATION_CODE = "app.code";
- public static final String CUSTOMER_CODE = "customer.code";
+ public static final String CUSTOMER_CODE = "customer.code";
- public static final String LICENSE_SERVER_URL = "license.server.url";
- }
+ public static final String PACK_CODE = "pack.code";
+
+ public static final String LICENSE_SERVER_URL = "license.server.url";
+
+ public static final String MAILGUN_DOMAIN = "mailgun.domain";
+ public static final String MAILGUN_API_KEY = "mailgun.api.key";
+ public static final String EMAIL_FROM_ADDRESS = "email.from.address";
+ public static final String EMAIL_LIC_DEFAULT_SUBJECT = "email.lic.default.subject";
+ }
}
--
Gitblit v1.3.2