From a99c9ec291c889667a61240c46005ffa2164e40e Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Wed, 29 Jun 2016 10:31:58 +0000
Subject: [PATCH] #0 fix - Fixed CLI to use activation code
---
src/main/java/net/curisit/securis/LicenseManager.java | 469 ++++++++++++++++++-----------------
pom.xml | 2
src/main/java/net/curisit/securis/License.java | 295 +++++++++++----------
3 files changed, 399 insertions(+), 367 deletions(-)
diff --git a/pom.xml b/pom.xml
index 30c7fea..1b3c3a9 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.1.2</version>
+ <version>1.2.0</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 08e7781..277be93 100644
--- a/src/main/java/net/curisit/securis/License.java
+++ b/src/main/java/net/curisit/securis/License.java
@@ -3,9 +3,6 @@
import java.io.File;
import java.net.URISyntaxException;
-import net.curisit.securis.beans.SignedLicenseBean;
-import net.curisit.securis.utils.Params;
-
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
@@ -15,6 +12,9 @@
import org.apache.commons.cli.PosixParser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+
+import net.curisit.securis.beans.SignedLicenseBean;
+import net.curisit.securis.utils.Params;
/**
* Main class when SeCuris client is used from command line.
@@ -41,166 +41,177 @@
*/
public class License {
- private static final Logger LOG = LogManager.getLogger(License.class);
+ 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);
+ String activationCode = cmd.getOptionValue("ac");
+ if (activationCode != null) {
+ String appcode = cmd.getOptionValue("appcode");
+ if (appcode == null) {
+ appcode = Params.get(Params.KEYS.APPLICATION_CODE);
+ if (appcode == null || appcode.startsWith("_")) {
+ checkMandatoryParameter(null, "appcode");
+ }
+ }
+ LicenseManager.getInstance().createRequestFile(file, activationCode, appcode);
+ } else {
+ 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')) {
- // TODO: Change CLI to get name and email in license request
- SignedLicenseBean lic = LicenseManager.getInstance().requestLicense(null, null);
- 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('c')) {
+ // TODO: Change CLI to get name and email in license request
+ SignedLicenseBean lic = LicenseManager.getInstance().requestLicense(null, null);
+ 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')) {
- LicenseManager.getInstance().testServer();
- LOG.info("Server is OK, url: {}", Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL));
+ 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);
- }
+ System.exit(0);
+ }
- 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());
- }
- SignedLicenseBean newLic = LicenseManager.getInstance().renew(file);
- File oldLicFile = new File(file.getAbsoluteFile() + ".old");
- file.renameTo(oldLicFile);
- 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);
- }
+ 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());
+ }
+ SignedLicenseBean newLic = LicenseManager.getInstance().renew(file);
+ File oldLicFile = new File(file.getAbsoluteFile() + ".old");
+ file.renameTo(oldLicFile);
+ 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);
+ }
- } 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() {
- if (Params.get(Params.KEYS.APPLICATION_CODE) == null) {
+ /**
+ * Checks that config file exists and contains mandatory parameters
+ */
+ private static void checkConfigFile() {
+ if (Params.get(Params.KEYS.APPLICATION_CODE) == null) {
- if (Params.get(Params.KEYS.LIC_TYPE_CODE) == null) {
- LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.LIC_TYPE_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);
- }
- } // else: The license will be got using activationCode
- }
+ if (Params.get(Params.KEYS.LIC_TYPE_CODE) == null) {
+ LOG.error("Manadatory parameter {} is not set in config file", Params.KEYS.LIC_TYPE_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);
+ }
+ } // else: The license will be got using activationCode
+ }
- 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("app_code").withLongOpt("appcode").withDescription("Set the app code, ignoring the config value.").hasArg(true).create('a'));
+ options.addOption(OptionBuilder.withArgName("activation_code").withLongOpt("ac").withDescription("Set the activation code.").hasArg(true).create('o'));
+ 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(OptionBuilder.withLongOpt("gen_request")
+ .withDescription("Generate request file. If --rfile parameter is missing then It is generated in current directory.").hasArg(false).create('g'));
+ 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 29f79dd..df475eb 100644
--- a/src/main/java/net/curisit/securis/LicenseManager.java
+++ b/src/main/java/net/curisit/securis/LicenseManager.java
@@ -10,6 +10,10 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.io.FileUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
import net.curisit.securis.ConnectionManager.Command;
import net.curisit.securis.beans.LicenseBean;
import net.curisit.securis.beans.RequestBean;
@@ -19,10 +23,6 @@
import net.curisit.securis.utils.Params;
import net.curisit.securis.utils.SignatureHelper;
-import org.apache.commons.io.FileUtils;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
/**
* Manage all licenses tasks, just like validation, renew, requesting, ...
*
@@ -30,257 +30,278 @@
*/
public class LicenseManager {
- private static final Logger LOG = LogManager.getLogger(LicenseManager.class);
+ private static final Logger LOG = LogManager.getLogger(LicenseManager.class);
- private static LicenseManager singleton = new LicenseManager();
+ private static LicenseManager singleton = new LicenseManager();
- public static final String PING_MESSAGE = "SeCuris API OK";
- public static final String HEADER_LICENSE_NAME_OR_REFERENCE = "X-SECURIS-LIC-NAMEREF";
- public static final String HEADER_LICENSE_EMAIL = "X-SECURIS-LIC-EMAIL";
+ public static final String PING_MESSAGE = "SeCuris API OK";
+ public static final String HEADER_LICENSE_NAME_OR_REFERENCE = "X-SECURIS-LIC-NAMEREF";
+ public static final String HEADER_LICENSE_EMAIL = "X-SECURIS-LIC-EMAIL";
- private LicenseManager() {
- }
+ private LicenseManager() {
+ }
- public static LicenseManager getInstance() {
- return singleton;
- }
+ public static LicenseManager getInstance() {
+ return singleton;
+ }
- /**
- * 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;
- }
+ /**
+ * 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>
- * <li>Signature</li>
- * <li>HW data</li>
- * <li>Logo CRC</li>
- * </ul>
- * </p>
- *
- * @param licFile
- * @return The license bean stored in file
- * @throws SeCurisException
- */
- public LicenseBean validateLicense(File licFile) throws SeCurisException {
+ /**
+ * Validates the license stored in {@code licFile} and get the corresponding
+ * LicenseBean
+ * <p>
+ * The validation includes:
+ * <ul>
+ * <li>Signature</li>
+ * <li>HW data</li>
+ * <li>Logo CRC</li>
+ * </ul>
+ * </p>
+ *
+ * @param licFile
+ * @return The license bean stored in file
+ * @throws SeCurisException
+ */
+ public LicenseBean validateLicense(File licFile) throws SeCurisException {
- return validateLicense(licFile, false);
- }
+ return validateLicense(licFile, false);
+ }
- /**
- * Validates the license stored in {@code licFile} and get the corresponding
- * LicenseBean. The License date is not validated
- * <p>
- * The validation includes:
- * <ul>
- * <li>Signature</li>
- * <li>HW data</li>
- * <li>Logo CRC</li>
- * </ul>
- * </p>
- *
- * @param licFile
- * @return The license bean stored in file
- * @throws SeCurisException
- */
- public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException {
- LicenseBean licBean = load(licFile);
- SignatureHelper.getInstance().validateSignature(licBean);
- if (licBean.getActivationCode() != null) {
- LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), licBean.getActivationCode());
- } else {
- LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
- Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
- }
- LicenseValidator.getInstance().validateLogo(licBean);
+ /**
+ * Validates the license stored in {@code licFile} and get the corresponding
+ * LicenseBean. The License date is not validated
+ * <p>
+ * The validation includes:
+ * <ul>
+ * <li>Signature</li>
+ * <li>HW data</li>
+ * <li>Logo CRC</li>
+ * </ul>
+ * </p>
+ *
+ * @param licFile
+ * @return The license bean stored in file
+ * @throws SeCurisException
+ */
+ public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException {
+ LicenseBean licBean = load(licFile);
+ SignatureHelper.getInstance().validateSignature(licBean);
+ if (licBean.getActivationCode() != null) {
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), licBean.getActivationCode());
+ } else {
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
+ Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
+ }
+ LicenseValidator.getInstance().validateLogo(licBean);
- if (!excludeDateValidation) {
- if (new Date().after(licBean.getExpirationDate())) {
- throw new ExpiredLicenseException();
- }
- }
+ if (!excludeDateValidation) {
+ if (new Date().after(licBean.getExpirationDate())) {
+ throw new ExpiredLicenseException();
+ }
+ }
- return licBean;
- }
+ return licBean;
+ }
- /**
- * Request to server for a valid license
- *
- * @return The license bean returned by the server
- * @throws SeCurisException
- */
- public SignedLicenseBean requestLicense(String nameOrReference, String email) throws SeCurisException {
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
- Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
+ /**
+ * Request to server for a valid license
+ *
+ * @return The license bean returned by the server
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean requestLicense(String nameOrReference, String email) throws SeCurisException {
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
+ Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
- SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
- return lic;
- }
+ SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
+ return lic;
+ }
- /**
- * Request to server for a valid license
- *
- * @return The license bean returned by the server
- * @throws SeCurisException
- */
- public SignedLicenseBean requestLicense(String nameOrReference, String email, String activationCode) throws SeCurisException {
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
+ /**
+ * Request to server for a valid license
+ *
+ * @return The license bean returned by the server
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean requestLicense(String nameOrReference, String email, String activationCode) throws SeCurisException {
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
- SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
- return lic;
- }
+ SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
+ return lic;
+ }
- /**
- * Request to server for a valid license
- *
- * @return The license bean returned by the server
- * @throws SeCurisException
- */
- public SignedLicenseBean requestLicense(String activationCode) throws SeCurisException {
- return requestLicense(null, null, activationCode);
- }
+ /**
+ * Request to server for a valid license
+ *
+ * @return The license bean returned by the server
+ * @throws SeCurisException
+ */
+ public SignedLicenseBean requestLicense(String activationCode) throws SeCurisException {
+ return requestLicense(null, null, activationCode);
+ }
- /**
- * Generate a license file using a {@link LicenseBean}
- *
- * @param license
- * @param file
- * @throws SeCurisException
- */
- public void save(LicenseBean license, File file) throws SeCurisException {
- SignedLicenseBean signedLic = new SignedLicenseBean(license);
- save(signedLic, file);
- }
+ /**
+ * Generate a license file using a {@link LicenseBean}
+ *
+ * @param license
+ * @param file
+ * @throws SeCurisException
+ */
+ public void save(LicenseBean license, File file) throws SeCurisException {
+ SignedLicenseBean signedLic = new SignedLicenseBean(license);
+ save(signedLic, file);
+ }
- /**
- * Generate a license file using a {@link LicenseBean}
- *
- * @param license
- * @param file
- * @throws SeCurisException
- */
- public void save(SignedLicenseBean signedLic, File file) throws SeCurisException {
- byte[] json;
- try {
- json = JsonUtils.toPrettyJSON(signedLic).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 license: " + signedLic, e);
- throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
- } catch (IOException e) {
- LOG.error("Error creating license file: " + file, e);
- throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
- }
+ /**
+ * Generate a license file using a {@link LicenseBean}
+ *
+ * @param license
+ * @param file
+ * @throws SeCurisException
+ */
+ public void save(SignedLicenseBean signedLic, File file) throws SeCurisException {
+ byte[] json;
+ try {
+ json = JsonUtils.toPrettyJSON(signedLic).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 license: " + signedLic, e);
+ throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
+ } catch (IOException e) {
+ LOG.error("Error creating license file: " + file, e);
+ throw new SeCurisException("Error creating json doc from license: " + signedLic, e);
+ }
- LOG.debug("License saved in {}", file);
+ LOG.debug("License saved in {}", file);
- }
+ }
- private SignedLicenseBean requestLicenseToServer(RequestBean req, String nameOrReference, String email) throws SeCurisException {
- Map<String, String> headers = new HashMap<String, String>();
- headers.put(HEADER_LICENSE_NAME_OR_REFERENCE, nameOrReference);
- headers.put(HEADER_LICENSE_EMAIL, email);
- SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req, headers);
+ private SignedLicenseBean requestLicenseToServer(RequestBean req, String nameOrReference, String email) throws SeCurisException {
+ Map<String, String> headers = new HashMap<String, String>();
+ headers.put(HEADER_LICENSE_NAME_OR_REFERENCE, nameOrReference);
+ headers.put(HEADER_LICENSE_EMAIL, email);
+ SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req, headers);
- return lic;
- }
+ return lic;
+ }
- /**
- * 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.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
- Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
+ /**
+ * 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.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
+ Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
- ReqGenerator.getInstance().save(req, outputRequestFile);
+ ReqGenerator.getInstance().save(req, outputRequestFile);
- return req;
- }
+ return 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, String activationCode) throws SeCurisException {
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
+ /**
+ * 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, String activationCode) throws SeCurisException {
+ return createRequestFile(outputRequestFile, activationCode, null);
+ }
- 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
+ *
+ * @param activationCode
+ * Activation code provided be SeCurisadministrator
+ * @param appCode
+ * Application code to use, ignoring the code set in config file
+ * @return The generated request bean
+ * @throws SeCurisException
+ */
+ public RequestBean createRequestFile(File outputRequestFile, String activationCode, String appCode) throws SeCurisException {
+ if (appCode == null) {
+ Params.get(Params.KEYS.APPLICATION_CODE);
+ }
+ RequestBean req = ReqGenerator.getInstance().createRequest(appCode, activationCode);
- 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, true);
+ return req;
+ }
- SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic);
+ /**
+ * 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, true);
- return newLic;
- }
+ SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic);
- /**
- * Check on SeCuris server if current license is still valid in server DB.
- *
- * @param licenseFile
- * @throws SeCurisException
- */
- public void assertLicenseIsValid(File licenseFile) throws SeCurisException, IOException {
- LicenseBean lic = validateLicense(licenseFile);
- // We need to snd the signed version to validate signature on server
- ConnectionManager.getInstance().executePost(Command.VALIDATE, LicenseBean.class, new SignedLicenseBean(lic));
- }
+ return newLic;
+ }
- public void testServer() throws SeCurisException {
- StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class);
- if (!PING_MESSAGE.equals(status.getMessage())) {
- throw new SeCurisException("SeCuris Server is not running in given URL");
- }
- }
+ /**
+ * Check on SeCuris server if current license is still valid in server DB.
+ *
+ * @param licenseFile
+ * @throws SeCurisException
+ */
+ public void assertLicenseIsValid(File licenseFile) throws SeCurisException, IOException {
+ LicenseBean lic = validateLicense(licenseFile);
+ // We need to snd the signed version to validate signature on server
+ ConnectionManager.getInstance().executePost(Command.VALIDATE, LicenseBean.class, new SignedLicenseBean(lic));
+ }
- public static void main(String[] args) throws SeCurisException {
- System.out.println("APPLICATION_CODE: " + Params.get(Params.KEYS.APPLICATION_CODE));
- System.out.println("LICENSE_SERVER_URL: " + Params.get(Params.KEYS.LICENSE_SERVER_URL));
- LicenseManager lm = LicenseManager.getInstance();
- // LicenseBean lic =
- // lm.requestLicense("aaf88d6c-6622-492a-93ec-10f3d1dc7120");
- LicenseBean lic = lm.requestLicense("Rob", "rsanchez@curisit.net");
- System.out.println(lic.getLicenseCode() + " " + lic.getExpirationDate());
- // LicenseBean lic = lm.
- }
+ public void testServer() throws SeCurisException {
+ StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class);
+ if (!PING_MESSAGE.equals(status.getMessage())) {
+ throw new SeCurisException("SeCuris Server is not running in given URL");
+ }
+ }
+
+ public static void main(String[] args) throws SeCurisException {
+ System.out.println("APPLICATION_CODE: " + Params.get(Params.KEYS.APPLICATION_CODE));
+ System.out.println("LICENSE_SERVER_URL: " + Params.get(Params.KEYS.LICENSE_SERVER_URL));
+ LicenseManager lm = LicenseManager.getInstance();
+ // LicenseBean lic =
+ // lm.requestLicense("aaf88d6c-6622-492a-93ec-10f3d1dc7120");
+ LicenseBean lic = lm.requestLicense("Rob", "rsanchez@curisit.net");
+ System.out.println(lic.getLicenseCode() + " " + lic.getExpirationDate());
+ // LicenseBean lic = lm.
+ }
}
--
Gitblit v1.3.2