Roberto Sánchez
2014-02-24 f7be2173201d6ef2d559ef4e8fdfef5534eee29e
src/patch/java/net/curisit/securis/LicenseGenerator.java
....@@ -2,6 +2,10 @@
22
33 import java.io.File;
44 import java.io.IOException;
5
+import java.io.UnsupportedEncodingException;
6
+import java.nio.file.Files;
7
+import java.nio.file.Paths;
8
+import java.nio.file.StandardOpenOption;
59 import java.security.InvalidKeyException;
610 import java.security.NoSuchAlgorithmException;
711 import java.security.NoSuchProviderException;
....@@ -14,6 +18,7 @@
1418
1519 import net.curisit.securis.beans.LicenseBean;
1620 import net.curisit.securis.beans.RequestBean;
21
+import net.curisit.securis.utils.JsonUtils;
1722
1823 import org.apache.commons.net.util.Base64;
1924 import org.slf4j.Logger;
....@@ -62,6 +67,30 @@
6267 }
6368
6469 /**
70
+ * Generate a license file using a {@link LicenseBean}
71
+ *
72
+ * @param license
73
+ * @param file
74
+ * @throws SeCurisException
75
+ */
76
+ public void save(LicenseBean license, File file) throws SeCurisException {
77
+ byte[] json;
78
+ try {
79
+ json = JsonUtils.toJSON(license, true).getBytes("utf-8");
80
+ Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE);
81
+ } catch (UnsupportedEncodingException e) {
82
+ log.error("Error creating json doc from license: " + license, e);
83
+ throw new SeCurisException("Error creating json doc from license: " + license, e);
84
+ } catch (IOException e) {
85
+ log.error("Error creating license file: " + file, e);
86
+ throw new SeCurisException("Error creating json doc from license: " + license, e);
87
+ }
88
+
89
+ log.info("License saved in {}", file);
90
+
91
+ }
92
+
93
+ /**
6594 * TODO: This method should be removed from client code.
6695 *
6796 * @param licBean