From 146a0fb8b0e90f9196e569152f649baf60d6cc8f Mon Sep 17 00:00:00 2001
From: Joaquín Reñé <jrene@curisit.net>
Date: Tue, 07 Oct 2025 14:52:57 +0000
Subject: [PATCH] #4410 - Comments on classes
---
securis/src/main/java/net/curisit/securis/LicenseGenerator.java | 68 +++++++++++++++++++---------------
1 files changed, 38 insertions(+), 30 deletions(-)
diff --git a/securis/src/main/java/net/curisit/securis/LicenseGenerator.java b/securis/src/main/java/net/curisit/securis/LicenseGenerator.java
index 558599a..419ba29 100644
--- a/securis/src/main/java/net/curisit/securis/LicenseGenerator.java
+++ b/securis/src/main/java/net/curisit/securis/LicenseGenerator.java
@@ -1,3 +1,6 @@
+/*
+ * Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
+ */
package net.curisit.securis;
import java.io.File;
@@ -24,23 +27,35 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import jakarta.inject.Singleton;
+
/**
- * License generator and signer
- *
- * @author roberto <roberto.sanchez@curisit.net>
- */
-@javax.inject.Singleton
+* LicenseGenerator
+* <p>
+* Factory for building and signing {@link LicenseBean} instances. Uses a process-wide
+* singleton and expects a PKCS#8 private key at:
+* <code>~/.SeCuris/keys/securis_private_key.pkcs8</code>.
+*
+* @author JRA
+* Last reviewed by JRA on Oct 5, 2025.
+*/
+@Singleton
public class LicenseGenerator {
private static final Logger LOG = LogManager.getLogger(LicenseGenerator.class);
private static LicenseGenerator singleton = new LicenseGenerator();
+ /**
+ * getInstance<p>
+ * Singleton accessor.
+ */
public static LicenseGenerator getInstance() {
return singleton;
}
/**
+ * generateLicense<p>
* Generate a license bean with the specified data
*
* @param req
@@ -66,12 +81,14 @@
}
/**
- * Generate a license file using a {@link LicenseBean}
- *
- * @param license
- * @param file
- * @throws SeCurisException
- */
+ * save
+ * <p>
+ * Persist a pretty-printed JSON representation of the signed license to disk.
+ *
+ * @param license source license
+ * @param file target file path
+ * @throws SeCurisException if serialization or IO fails
+ */
public void save(LicenseBean license, File file) throws SeCurisException {
SignedLicenseBean signedLic = new SignedLicenseBean(license);
byte[] json;
@@ -91,15 +108,14 @@
}
/**
- *
- * @param licBean
- * @return
- * @throws NoSuchAlgorithmException
- * @throws IOException
- * @throws InvalidKeySpecException
- * @throws InvalidKeyException
- * @throws SignatureException
- */
+ * sign
+ * <p>
+ * Compute a Base64 signature for the given license and set it into the bean.
+ *
+ * @param licBean license to sign (in-place)
+ * @return Base64 signature string
+ * @throws SeCurisException if the signature process fails
+ */
public String sign(LicenseBean licBean) throws SeCurisException {
SignatureHelper sh = SignatureHelper.getInstance();
@@ -114,16 +130,8 @@
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);
+ } catch (NoSuchAlgorithmException | InvalidKeyException | InvalidKeySpecException | IOException | SignatureException e) {
+ LOG.error("Error signing license for {}", licBean, e);
}
throw new SeCurisException("License could not be generated");
}
--
Gitblit v1.3.2