rsanchez
2014-12-12 fb1bbf788b8c2ec2cc292c66c851c7f0b9b19357
securis/src/main/java/net/curisit/securis/services/ApiResource.java
....@@ -54,7 +54,6 @@
5454 @Path("/api")
5555 public class ApiResource {
5656
57
- @SuppressWarnings("unused")
5857 private static final Logger LOG = LogManager.getLogger(ApiResource.class);
5958
6059 @Inject
....@@ -189,9 +188,15 @@
189188 throw new SeCurisServiceException(ErrorCodes.LICENSE_NOT_READY_FOR_RENEW, "The license is still valid, not ready for renew");
190189 }
191190
192
- SignedLicenseBean lic = createLicense(previousLic, emProvider.get(), true);
191
+ EntityManager em = emProvider.get();
192
+ License lic = License.findLicenseByCode(previousLic.getLicenseCode(), em);
193
+ if (lic.getStatus() != LicenseStatus.ACTIVE) {
194
+ throw new SeCurisServiceException(ErrorCodes.LICENSE_NOT_READY_FOR_RENEW, "Only licenses with status 'Active' can be renew");
195
+ }
193196
194
- return Response.ok(lic).build();
197
+ SignedLicenseBean signedLic = createLicense(previousLic, em, true);
198
+
199
+ return Response.ok(signedLic).build();
195200 }
196201
197202 /**
....@@ -215,6 +220,11 @@
215220 @Transactional
216221 public Response validate(LicenseBean currentLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException {
217222 LOG.info("Validate license: {}", currentLic);
223
+
224
+ if (currentLic.getExpirationDate().before(new Date())) {
225
+ throw new SeCurisServiceException(ErrorCodes.LICENSE_IS_EXPIRED, "The license is expired");
226
+ }
227
+
218228 EntityManager em = emProvider.get();
219229 try {
220230 SignatureHelper.getInstance().validateSignature(currentLic);