rsanchez
2015-09-22 7d8713e88c7872b195f7e4d02ac4812536ae196b
src/main/java/net/curisit/securis/LicenseManager.java
....@@ -38,7 +38,8 @@
3838 public static final String HEADER_LICENSE_NAME_OR_REFERENCE = "X-SECURIS-LIC-NAMEREF";
3939 public static final String HEADER_LICENSE_EMAIL = "X-SECURIS-LIC-EMAIL";
4040
41
- private LicenseManager() {}
41
+ private LicenseManager() {
42
+ }
4243
4344 public static LicenseManager getInstance() {
4445 return singleton;
....@@ -62,7 +63,8 @@
6263 }
6364
6465 /**
65
- * Validates the license stored in {@code licFile} and get the corresponding LicenseBean
66
+ * Validates the license stored in {@code licFile} and get the corresponding
67
+ * LicenseBean
6668 * <p>
6769 * The validation includes:
6870 * <ul>
....@@ -82,7 +84,8 @@
8284 }
8385
8486 /**
85
- * Validates the license stored in {@code licFile} and get the corresponding LicenseBean. The License date is not validated
87
+ * Validates the license stored in {@code licFile} and get the corresponding
88
+ * LicenseBean. The License date is not validated
8689 * <p>
8790 * The validation includes:
8891 * <ul>
....@@ -99,7 +102,12 @@
99102 public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException {
100103 LicenseBean licBean = load(licFile);
101104 SignatureHelper.getInstance().validateSignature(licBean);
102
- LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
105
+ if (licBean.getActivationCode() != null) {
106
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), licBean.getActivationCode());
107
+ } else {
108
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
109
+ Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
110
+ }
103111 LicenseValidator.getInstance().validateLogo(licBean);
104112
105113 if (!excludeDateValidation) {
....@@ -118,7 +126,21 @@
118126 * @throws SeCurisException
119127 */
120128 public SignedLicenseBean requestLicense(String nameOrReference, String email) throws SeCurisException {
121
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
129
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
130
+ Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
131
+
132
+ SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
133
+ return lic;
134
+ }
135
+
136
+ /**
137
+ * Request to server for a valid license
138
+ *
139
+ * @return The license bean returned by the server
140
+ * @throws SeCurisException
141
+ */
142
+ public SignedLicenseBean requestLicense(String nameOrReference, String email, String activationCode) throws SeCurisException {
143
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
122144
123145 SignedLicenseBean lic = requestLicenseToServer(req, nameOrReference, email);
124146 return lic;
....@@ -170,7 +192,8 @@
170192 }
171193
172194 /**
173
- * Creates a new request file with current hardware in the File passed as parameter
195
+ * Creates a new request file with current hardware in the File passed as
196
+ * parameter
174197 *
175198 * @param outputRequestFile
176199 * File where the request data will be saved
....@@ -178,7 +201,8 @@
178201 * @throws SeCurisException
179202 */
180203 public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
181
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)), Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
204
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.LIC_TYPE_CODE, Params.get(Params.KEYS.APPLICATION_CODE)),
205
+ Params.get(Params.KEYS.CUSTOMER_CODE), Params.get(Params.KEYS.PACK_CODE));
182206
183207 ReqGenerator.getInstance().save(req, outputRequestFile);
184208
....@@ -186,11 +210,30 @@
186210 }
187211
188212 /**
189
- * Send the current license file to server, which is previously validated, to get a renewed one if it is prepared in server side.
213
+ * Creates a new request file with current hardware in the File passed as
214
+ * parameter
215
+ *
216
+ * @param outputRequestFile
217
+ * File where the request data will be saved
218
+ * @return The generated request bean
219
+ * @throws SeCurisException
220
+ */
221
+ public RequestBean createRequestFile(File outputRequestFile, String activationCode) throws SeCurisException {
222
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), activationCode);
223
+
224
+ ReqGenerator.getInstance().save(req, outputRequestFile);
225
+
226
+ return req;
227
+ }
228
+
229
+ /**
230
+ * Send the current license file to server, which is previously validated,
231
+ * to get a renewed one if it is prepared in server side.
190232 *
191233 * @param licenseFile
192234 * Current and valid License file
193
- * @return New license bean if server creates a new one, otherwise the same current License bean will be returned
235
+ * @return New license bean if server creates a new one, otherwise the same
236
+ * current License bean will be returned
194237 * @throws SeCurisException
195238 */
196239 public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
....@@ -220,18 +263,4 @@
220263 }
221264 }
222265
223
- public static void main(String[] args) throws SeCurisException {
224
- String filename = "/Users/rob/.doxr/doxr.lic";
225
-
226
- if (filename == null)
227
- filename = "./license.req";
228
- File file = new File(filename);
229
- LicenseManager.getInstance().validateLicense(file);
230
- LOG.info("Validation Ok");
231
- String r = "{\"licenseTypeCode\":\"DX01\",\"packCode\":\"DEVDX01\",\"arch\":\"x86_64\",\"osName\":\"darwin\",\"customerCode\":\"CIT\",\"macAddresses\":[\"60:c5:47:03:cf:c8\",\"b2:00:12:b6:88:e0\"]}";
232
- RequestBean rb = JsonUtils.json2object(r, RequestBean.class);
233
- System.out.println(rb);
234
- LOG.info("Request file {} generated OK", file.getAbsolutePath());
235
-
236
- }
237266 }