rsanchez
2017-04-18 523edc2956a42bda7d33884fcbbb6018addda4b0
securis/src/main/java/net/curisit/securis/services/ApiResource.java
....@@ -34,6 +34,7 @@
3434 import net.curisit.securis.db.LicenseHistory;
3535 import net.curisit.securis.db.LicenseStatus;
3636 import net.curisit.securis.db.Pack;
37
+import net.curisit.securis.db.PackStatus;
3738 import net.curisit.securis.db.User;
3839 import net.curisit.securis.db.User.Rol;
3940 import net.curisit.securis.ioc.EnsureTransaction;
....@@ -197,7 +198,9 @@
197198
198199 /**
199200 * License validation on server side, in this case we validate that the
200
- * current licenses has not been cancelled.
201
+ * current licenses has not been cancelled and they are still in valid
202
+ * period. If the pack has reached the end valid period, the license is no
203
+ * longer valid.
201204 *
202205 * @param currentLic
203206 * @param bsc
....@@ -219,12 +222,22 @@
219222 throw new SeCurisServiceException(ErrorCodes.LICENSE_IS_EXPIRED, "The license is expired");
220223 }
221224
225
+ License existingLic = licenseHelper.getActiveLicenseFromDB(currentLic, em);
226
+
227
+ Pack pack = existingLic.getPack();
228
+ if (pack.getEndValidDate().before(new Date())) {
229
+ throw new SeCurisServiceException(ErrorCodes.LICENSE_PACK_IS_NOT_VALID, "The pack end valid date has been reached");
230
+ }
231
+ if (pack.getStatus() != PackStatus.ACTIVE) {
232
+ LOG.error("The Pack {} status is not active, is: {}", pack.getCode(), pack.getStatus());
233
+ throw new SeCurisServiceException(ErrorCodes.LICENSE_PACK_IS_NOT_VALID, "The pack status is not Active");
234
+ }
235
+
222236 try {
223237 SignatureHelper.getInstance().validateSignature(currentLic);
224238 } catch (SeCurisException ex) {
225239 throw new SeCurisServiceException(ErrorCodes.LICENSE_DATA_IS_NOT_VALID, "The license signature is not valid");
226240 }
227
- licenseHelper.assertLicenseStatusIsActive(currentLic, em);
228241
229242 return Response.ok(currentLic).build();
230243 }
....@@ -353,6 +366,10 @@
353366 } else {
354367 pack = lic.getPack();
355368 }
369
+ if (pack.getStatus() != PackStatus.ACTIVE) {
370
+ LOG.error("The Pack {} status is not active, is: {}", pack.getCode(), pack.getStatus());
371
+ throw new SeCurisServiceException(ErrorCodes.LICENSE_DATA_IS_NOT_VALID, "The pack status is not Active");
372
+ }
356373 SignedLicenseBean signedLicense;
357374 try {
358375 String licCode;