From 99e64ffd78b36efaee558a991d4d2ad5abb7ceed Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Fri, 25 Sep 2015 14:45:32 +0000
Subject: [PATCH] #2756 fix - Updated token for client API
---
src/main/java/net/curisit/securis/LicenseValidator.java | 111 ++++++++++++++++++++++++++++++-------------------------
1 files changed, 60 insertions(+), 51 deletions(-)
diff --git a/src/main/java/net/curisit/securis/LicenseValidator.java b/src/main/java/net/curisit/securis/LicenseValidator.java
index 0a31755..130a20c 100644
--- a/src/main/java/net/curisit/securis/LicenseValidator.java
+++ b/src/main/java/net/curisit/securis/LicenseValidator.java
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.util.UUID;
import net.curisit.securis.beans.RequestBean;
import net.curisit.securis.utils.JsonUtils;
@@ -14,64 +15,72 @@
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 licTypeCode, String customerCode, String packCode) throws SeCurisException {
- RequestBean currentHW = ReqGenerator.getInstance().createRequest(licTypeCode, customerCode, packCode);
- if (!currentHW.match(reqBean)) {
- throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: \n"
- + JsonUtils.toPrettyJSON(reqBean, RequestBean.class) + "\n Expected: \n" + JsonUtils.toPrettyJSON(currentHW));
- }
- }
+ public void validateHW(RequestBean reqBean, String licTypeCode, String customerCode, String packCode) throws SeCurisException {
+ RequestBean currentHW = ReqGenerator.getInstance().createRequest(licTypeCode, customerCode, packCode);
+ if (!currentHW.match(reqBean)) {
+ throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: \n" + JsonUtils.toPrettyJSON(reqBean, RequestBean.class)
+ + "\n Expected: \n" + JsonUtils.toPrettyJSON(currentHW));
+ }
+ }
- public void validateHW(RequestBean reqBean, String appCode, String activationCode) throws SeCurisException {
- RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, activationCode);
- if (!currentHW.match(reqBean)) {
- throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: \n"
- + JsonUtils.toPrettyJSON(reqBean, RequestBean.class) + "\n Expected: \n" + JsonUtils.toPrettyJSON(currentHW));
- }
- }
+ public void validateHW(RequestBean reqBean, String appCode, String activationCode) throws SeCurisException {
+ RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, activationCode);
+ if (!currentHW.match(reqBean)) {
+ throw new SeCurisException("Current System info mismatch the License System info:\n Licensed: \n" + JsonUtils.toPrettyJSON(reqBean, RequestBean.class)
+ + "\n Expected: \n" + JsonUtils.toPrettyJSON(currentHW));
+ }
+ }
+ public static boolean isValidActivationCode(String activationCode) {
+ try {
+ UUID.fromString(activationCode);
+ return true;
+ } catch (Exception ex) {
+ return false;
+ }
+ }
}
--
Gitblit v1.3.2