Roberto Sánchez
2014-02-24 f7be2173201d6ef2d559ef4e8fdfef5534eee29e
src/main/java/net/curisit/securis/LicenseManager.java
....@@ -6,6 +6,7 @@
66 import net.curisit.securis.beans.LicenseBean;
77 import net.curisit.securis.beans.RequestBean;
88 import net.curisit.securis.utils.JsonUtils;
9
+import net.curisit.securis.utils.Params;
910
1011 import org.apache.commons.io.FileUtils;
1112
....@@ -25,23 +26,65 @@
2526 return singleton;
2627 }
2728
28
- public LicenseBean validateLicense(File licFile, String appCode, String customerCode) throws SeCurisException {
29
+ /**
30
+ * Validates the license stored in {@code licFile} and get the corresponding LicenseBean
31
+ * <p>
32
+ * The validation includes:
33
+ * <ul>
34
+ * <li>Signature</li>
35
+ * <li>HW data</li>
36
+ * <li>Logo CRC</li>
37
+ * </ul>
38
+ * </p>
39
+ *
40
+ * @param licFile
41
+ * @param appCode
42
+ * @param customerCode
43
+ * @return
44
+ * @throws SeCurisException
45
+ */
46
+ public LicenseBean validateLicense(File licFile) throws SeCurisException {
2947 LicenseBean licBean;
3048 try {
3149 licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
3250 } catch (IOException e) {
33
- throw new SeCurisException("Error validating license", e);
51
+ throw new SeCurisException("Error getting license data from file: " + licFile, e);
3452 }
3553 SignatureHelper.getInstance().validateSignature(licBean);
36
- validateHW(licBean, appCode, customerCode);
54
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
55
+ LicenseValidator.getInstance().validateLogo(licBean);
3756
3857 return licBean;
3958 }
4059
41
- private void validateHW(RequestBean reqBean, String appCode, String customerCode) throws SeCurisException {
42
- RequestBean currentHW = ReqGenerator.getInstance().createRequest(appCode, customerCode);
43
- if (!currentHW.match(reqBean))
44
- throw new SeCurisException("Current System info mismatch the License System info: " + JsonUtils.toJSON(reqBean));
60
+ /**
61
+ * Creates a new request file with current hardware in the File passed as paramter
62
+ *
63
+ * @param outputRequestFile
64
+ * File where the request data will be saved
65
+ * @return The generated request bean
66
+ * @throws SeCurisException
67
+ */
68
+ public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
69
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
70
+
71
+ ReqGenerator.getInstance().save(req, outputRequestFile);
72
+
73
+ return req;
74
+ }
75
+
76
+ /**
77
+ * Send the current license file to server, which is previously validated, to get a renewed one if it is prepared in server side.
78
+ *
79
+ * @param licenseFile
80
+ * Current and valid License file
81
+ * @return New license bean if server creates a new one, otherwise the same current License bean will be returned
82
+ * @throws SeCurisException
83
+ */
84
+ public LicenseBean sync(File licenseFile) throws SeCurisException {
85
+ LicenseBean lic = validateLicense(licenseFile);
86
+ // TODO: Send the current LicenseBean to server to check if a new one is prepared.
87
+ return lic;
4588 }
4689
4790 }