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/LicenseManager.java |  146 +++++++++++++++++++++++++-----------------------
 1 files changed, 77 insertions(+), 69 deletions(-)

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);

--
Gitblit v1.3.2