rsanchez
2014-10-22 09bb2b3b9300e332f8b743481fbb412df8cd2a89
src/main/java/net/curisit/securis/LicenseManager.java
....@@ -28,38 +28,39 @@
2828 */
2929 public class LicenseManager {
3030
31
- private static final Logger LOG = LogManager.getLogger(License.class);
31
+ private static final Logger LOG = LogManager.getLogger(License.class);
3232
33
- private static LicenseManager singleton = new LicenseManager();
33
+ private static LicenseManager singleton = new LicenseManager();
3434
35
- public static final String PING_MESSAGE = "SeCuris API OK";
36
-
37
- private LicenseManager() {
38
- }
35
+ public static final String PING_MESSAGE = "SeCuris API OK";
3936
40
- public static LicenseManager getInstance() {
41
- return singleton;
42
- }
37
+ private LicenseManager() {
38
+ }
4339
44
- /**
45
- * Loads a license from file
46
- *
47
- * @param licFile
48
- * @return The license bean
49
- * @throws SeCurisException
50
- */
51
- public LicenseBean load(File licFile) throws SeCurisException {
52
- LicenseBean licBean;
53
- try {
54
- licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
55
- } catch (IOException e) {
56
- throw new SeCurisException("Error getting license data from file: " + licFile, e);
57
- }
58
- return licBean;
59
- }
40
+ public static LicenseManager getInstance() {
41
+ return singleton;
42
+ }
6043
6144 /**
62
- * Validates the license stored in {@code licFile} and get the corresponding LicenseBean
45
+ * Loads a license from file
46
+ *
47
+ * @param licFile
48
+ * @return The license bean
49
+ * @throws SeCurisException
50
+ */
51
+ public LicenseBean load(File licFile) throws SeCurisException {
52
+ LicenseBean licBean;
53
+ try {
54
+ licBean = JsonUtils.json2object(FileUtils.readFileToString(licFile), LicenseBean.class);
55
+ } catch (IOException e) {
56
+ throw new SeCurisException("Error getting license data from file: " + licFile, e);
57
+ }
58
+ return licBean;
59
+ }
60
+
61
+ /**
62
+ * Validates the license stored in {@code licFile} and get the corresponding
63
+ * LicenseBean
6364 * <p>
6465 * The validation includes:
6566 * <ul>
....@@ -79,7 +80,8 @@
7980 }
8081
8182 /**
82
- * Validates the license stored in {@code licFile} and get the corresponding LicenseBean. The License date is not validated
83
+ * Validates the license stored in {@code licFile} and get the corresponding
84
+ * LicenseBean. The License date is not validated
8385 * <p>
8486 * The validation includes:
8587 * <ul>
....@@ -96,7 +98,8 @@
9698 public LicenseBean validateLicense(File licFile, boolean excludeDateValidation) throws SeCurisException {
9799 LicenseBean licBean = load(licFile);
98100 SignatureHelper.getInstance().validateSignature(licBean);
99
- LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
101
+ LicenseValidator.getInstance().validateHW(licBean, Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
102
+ Params.get(Params.KEYS.PACK_CODE));
100103 LicenseValidator.getInstance().validateLogo(licBean);
101104
102105 if (!excludeDateValidation) {
....@@ -108,18 +111,19 @@
108111 return licBean;
109112 }
110113
111
- /**
112
- * Request to server for a valid license
113
- *
114
- * @return The license bean returned by the server
115
- * @throws SeCurisException
116
- */
117
- public SignedLicenseBean requestLicense() throws SeCurisException {
118
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
114
+ /**
115
+ * Request to server for a valid license
116
+ *
117
+ * @return The license bean returned by the server
118
+ * @throws SeCurisException
119
+ */
120
+ public SignedLicenseBean requestLicense() throws SeCurisException {
121
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
122
+ Params.get(Params.KEYS.PACK_CODE));
119123
120
- SignedLicenseBean lic = requestLicenseToServer(req);
121
- return lic;
122
- }
124
+ SignedLicenseBean lic = requestLicenseToServer(req);
125
+ return lic;
126
+ }
123127
124128 /**
125129 * Generate a license file using a {@link LicenseBean}
....@@ -157,43 +161,47 @@
157161
158162 }
159163
160
- private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException {
161
- SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req);
162
-
163
- return lic;
164
- }
164
+ private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException {
165
+ SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req);
165166
166
- /**
167
- * Creates a new request file with current hardware in the File passed as parameter
168
- *
169
- * @param outputRequestFile
170
- * File where the request data will be saved
171
- * @return The generated request bean
172
- * @throws SeCurisException
173
- */
174
- public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
175
- RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE));
167
+ return lic;
168
+ }
176169
177
- ReqGenerator.getInstance().save(req, outputRequestFile);
170
+ /**
171
+ * Creates a new request file with current hardware in the File passed as
172
+ * parameter
173
+ *
174
+ * @param outputRequestFile
175
+ * File where the request data will be saved
176
+ * @return The generated request bean
177
+ * @throws SeCurisException
178
+ */
179
+ public RequestBean createRequestFile(File outputRequestFile) throws SeCurisException {
180
+ RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE),
181
+ Params.get(Params.KEYS.PACK_CODE));
178182
179
- return req;
180
- }
183
+ ReqGenerator.getInstance().save(req, outputRequestFile);
181184
182
- /**
183
- * Send the current license file to server, which is previously validated, to get a renewed one if it is prepared in server side.
184
- *
185
- * @param licenseFile
186
- * Current and valid License file
187
- * @return New license bean if server creates a new one, otherwise the same current License bean will be returned
188
- * @throws SeCurisException
189
- */
190
- public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
191
- LicenseBean lic = validateLicense(licenseFile);
185
+ return req;
186
+ }
187
+
188
+ /**
189
+ * Send the current license file to server, which is previously validated,
190
+ * to get a renewed one if it is prepared in server side.
191
+ *
192
+ * @param licenseFile
193
+ * Current and valid License file
194
+ * @return New license bean if server creates a new one, otherwise the same
195
+ * current License bean will be returned
196
+ * @throws SeCurisException
197
+ */
198
+ public SignedLicenseBean renew(File licenseFile) throws SeCurisException {
199
+ LicenseBean lic = validateLicense(licenseFile);
192200
193201 SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic);
194202
195
- return newLic;
196
- }
203
+ return newLic;
204
+ }
197205
198206 public void testServer() throws SeCurisException {
199207 StatusBean status = ConnectionManager.getInstance().executeGet(Command.TEST, StatusBean.class);