From e767d38a97828997ed3080d1332a3a2f2bcf8491 Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Wed, 18 Jun 2014 12:06:24 +0000
Subject: [PATCH] #593 fix - Added further information when license is not valid due to HW validation

---
 src/main/java/net/curisit/securis/LicenseValidator.java |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/main/java/net/curisit/securis/LicenseValidator.java b/src/main/java/net/curisit/securis/LicenseValidator.java
index 23c9ea7..66744d6 100644
--- a/src/main/java/net/curisit/securis/LicenseValidator.java
+++ b/src/main/java/net/curisit/securis/LicenseValidator.java
@@ -9,8 +9,12 @@
 import net.curisit.securis.utils.LicUtils;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 public class LicenseValidator {
+
+	private static final Logger log = LogManager.getLogger(LicenseValidator.class);
 
 	public static LicenseValidator singleton = new LicenseValidator();
 	private byte[] LOGO_SECRET;
@@ -28,7 +32,7 @@
 	}
 
 	/**
-	 * @return true if logo is correct
+	 * @return CRC string for customer logo
 	 */
 	public String getCrcLogo() {
 		InputStream is = getClass().getClassLoader().getResourceAsStream("images/logo_customer.png");
@@ -36,21 +40,25 @@
 			String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
 			return shaLogo;
 		} catch (IOException e) {
-			e.printStackTrace();
+			log.warn("Customer logo was not found in images/logo_customer.png");
 			return null;
 		}
 	}
 
 	public void validateLogo(RequestBean reqBean) throws SeCurisException {
-		String currentCRC = getCrcLogo();
-		if (!currentCRC.equals(reqBean.getCrcLogo()))
-			throw new SeCurisException("License logo validation failed for request data: " + JsonUtils.toJSON(reqBean));
+		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: " + JsonUtils.toJSON(reqBean));
+			throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: " + JsonUtils.toJSON(reqBean, true) + "\n Expected: " + JsonUtils.toJSON(currentHW, true));
 	}
 
 }

--
Gitblit v1.3.2