From 8d5386be38db25a2a41c3bf6c876adee21ca26cc Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Fri, 19 Sep 2014 08:26:02 +0000
Subject: [PATCH] #396 fix - Fixed more SonarQube issues

---
 securis/src/patch/java/net/curisit/securis/LicenseGenerator.java |  208 ++++++++++++++++++++++++++--------------------------
 1 files changed, 104 insertions(+), 104 deletions(-)

diff --git a/securis/src/patch/java/net/curisit/securis/LicenseGenerator.java b/securis/src/patch/java/net/curisit/securis/LicenseGenerator.java
index a9d3414..7137146 100644
--- a/securis/src/patch/java/net/curisit/securis/LicenseGenerator.java
+++ b/securis/src/patch/java/net/curisit/securis/LicenseGenerator.java
@@ -33,124 +33,124 @@
  */
 public class LicenseGenerator {
 
-	private static final Logger LOG = LogManager.getLogger(LicenseGenerator.class);
+    private static final Logger LOG = LogManager.getLogger(LicenseGenerator.class);
 
-	private static LicenseGenerator singleton = new LicenseGenerator();
+    private static LicenseGenerator singleton = new LicenseGenerator();
 
-	private LicenseGenerator() {
-	}
+    private LicenseGenerator() {}
 
-	public static LicenseGenerator getInstance() {
-		return singleton;
-	}
+    public static LicenseGenerator getInstance() {
+        return singleton;
+    }
 
-	/**
-	 * Generate a license bean with the specified data
-	 * 
-	 * @param hw
-	 * @param customerCode
-	 *            - e.g: "BP"
-	 * @param maxInstances
-	 * @param maxUsers
-	 * @param maxTimeThreshold
-	 *            Max time between synchronizations expressed in days
-	 * @return
-	 * @throws SeCurisException
-	 */
-	public LicenseBean generateLicense(RequestBean req, Map<String, Object> metadata, Date expirationDate, String licenseType, String licenseCode) throws SeCurisException {
-		LOG.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(), req.getAppCode()));
-		LicenseBean license = new LicenseBean(req);
-		license.setLicenseType(licenseType);
-		license.setLicenseCode(licenseCode);
-		license.setExpirationDate(expirationDate);
-		license.setMetadata(metadata);
-		sign(license);
+    /**
+     * Generate a license bean with the specified data
+     * 
+     * @param hw
+     * @param customerCode
+     *            - e.g: "BP"
+     * @param maxInstances
+     * @param maxUsers
+     * @param maxTimeThreshold
+     *            Max time between synchronizations expressed in days
+     * @return
+     * @throws SeCurisException
+     */
+    public LicenseBean generateLicense(RequestBean req, Map<String, Object> metadata, Date expirationDate, String licenseType, String licenseCode)
+            throws SeCurisException {
+        LOG.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(),
+                req.getAppCode()));
+        LicenseBean license = new LicenseBean(req);
+        license.setLicenseType(licenseType);
+        license.setLicenseCode(licenseCode);
+        license.setExpirationDate(expirationDate);
+        license.setMetadata(metadata);
+        sign(license);
 
-		return license;
-	}
+        return license;
+    }
 
-	/**
-	 * 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);
-		byte[] json;
-		try {
-			json = JsonUtils.toJSON(signedLic, 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 license: " + license, e);
-			throw new SeCurisException("Error creating json doc from license: " + license, e);
-		} catch (IOException e) {
-			LOG.error("Error creating license file: " + file, e);
-			throw new SeCurisException("Error creating json doc from license: " + license, e);
-		}
+    /**
+     * 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);
+        byte[] json;
+        try {
+            json = JsonUtils.toJSON(signedLic, 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 license: " + license, e);
+            throw new SeCurisException("Error creating json doc from license: " + license, e);
+        } catch (IOException e) {
+            LOG.error("Error creating license file: " + file, e);
+            throw new SeCurisException("Error creating json doc from license: " + license, e);
+        }
 
-		LOG.info("License saved in {}", file);
+        LOG.info("License saved in {}", file);
 
-	}
+    }
 
-	/**
-	 * TODO: This method should be removed from client code.
-	 * 
-	 * @param licBean
-	 * @return
-	 * @throws NoSuchAlgorithmException
-	 * @throws IOException
-	 * @throws InvalidKeySpecException
-	 * @throws InvalidKeyException
-	 * @throws SignatureException
-	 */
-	public String sign(LicenseBean licBean) throws SeCurisException {
-		SignatureHelper sh = SignatureHelper.getInstance();
+    /**
+     * TODO: This method should be removed from client code.
+     * 
+     * @param licBean
+     * @return
+     * @throws NoSuchAlgorithmException
+     * @throws IOException
+     * @throws InvalidKeySpecException
+     * @throws InvalidKeyException
+     * @throws SignatureException
+     */
+    public String sign(LicenseBean licBean) throws SeCurisException {
+        SignatureHelper sh = SignatureHelper.getInstance();
 
-		Signature signature;
-		try {
-			signature = Signature.getInstance(SignatureHelper.SIGNATURE_GENERATION_ALGORITHM);
-			signature.initSign(sh.generatePrivateKey(new File("/Users/cproberto/Documents/wsPython/doky/tests/securis_private_key.pkcs8")));
+        Signature signature;
+        try {
+            signature = Signature.getInstance(SignatureHelper.SIGNATURE_GENERATION_ALGORITHM);
+            signature.initSign(sh.generatePrivateKey(new File("/Users/cproberto/Documents/wsPython/doky/tests/securis_private_key.pkcs8")));
 
-			sh.prepareSignature(signature, licBean);
+            sh.prepareSignature(signature, licBean);
 
-			byte[] signatureData = signature.sign();
-			licBean.setSignature(Base64.encodeBase64String(signatureData));
-			return licBean.getSignature();
-		} catch (NoSuchAlgorithmException e) {
-			LOG.error("Error signing license for " + licBean, e);
-		} catch (InvalidKeyException e) {
-			LOG.error("Error signing license for " + licBean, e);
-		} catch (InvalidKeySpecException e) {
-			LOG.error("Error signing license for " + licBean, e);
-		} catch (IOException e) {
-			LOG.error("Error signing license for " + licBean, e);
-		} catch (SignatureException e) {
-			LOG.error("Error signing license for " + licBean, e);
-		}
-		throw new SeCurisException("License could not be generated");
-	}
+            byte[] signatureData = signature.sign();
+            licBean.setSignature(Base64.encodeBase64String(signatureData));
+            return licBean.getSignature();
+        } catch (NoSuchAlgorithmException e) {
+            LOG.error("Error signing license for " + licBean, e);
+        } catch (InvalidKeyException e) {
+            LOG.error("Error signing license for " + licBean, e);
+        } catch (InvalidKeySpecException e) {
+            LOG.error("Error signing license for " + licBean, e);
+        } catch (IOException e) {
+            LOG.error("Error signing license for " + licBean, e);
+        } catch (SignatureException e) {
+            LOG.error("Error signing license for " + licBean, e);
+        }
+        throw new SeCurisException("License could not be generated");
+    }
 
-	public static void main(String[] args) throws SeCurisException {
+    public static void main(String[] args) throws SeCurisException {
 
-		RequestBean req = ReqGenerator.getInstance().loadRequest(new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.req"));
-		Map<String, Object> metadata = new TreeMap<>();
-//		CurisData parameters:
-//		metadata.put("maxUsers", 5);
-//		metadata.put("maxSessionUsers", 100);
-		// curisIntegrity
-		metadata.put("maxUsers", 0);
-		metadata.put("maxInstances", 0);
-		metadata.put("timeThreshold", 0);
-		metadata.put("datasetPrefix", "BP");
-		metadata.put("extendedMode", true);
-		Date expirationDate = new Date(new Date().getTime() + (1000L * 3600 * 24 * 365 * 10));
-		LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CI-01", "LIC-CURISTEC-0001");
-		LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/AxelLicCI.lic"));
+        RequestBean req = ReqGenerator.getInstance().loadRequest(new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.req"));
+        Map<String, Object> metadata = new TreeMap<>();
+        // CurisData parameters:
+        // metadata.put("maxUsers", 5);
+        // metadata.put("maxSessionUsers", 100);
+        // curisIntegrity
+        metadata.put("maxUsers", 0);
+        metadata.put("maxInstances", 0);
+        metadata.put("timeThreshold", 0);
+        metadata.put("datasetPrefix", "BP");
+        metadata.put("extendedMode", true);
+        Date expirationDate = new Date(new Date().getTime() + (1000L * 3600 * 24 * 365 * 10));
+        LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CI-01", "LIC-CURISTEC-0001");
+        LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/AxelLicCI.lic"));
 
-		System.out.print("License expires at: " + expirationDate.getTime());
- 
+        System.out.print("License expires at: " + expirationDate.getTime());
 
-	}
+    }
 }

--
Gitblit v1.3.2