From d58c85d0b65e43f8c0ced84ee816d0adaf16dd20 Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Fri, 19 Sep 2014 16:21:32 +0000
Subject: [PATCH] #396 feature - Added license renew service (in beta)
---
securis/src/main/java/net/curisit/securis/services/LicenseResource.java | 78 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 76 insertions(+), 2 deletions(-)
diff --git a/securis/src/main/java/net/curisit/securis/services/LicenseResource.java b/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
index ba65000..bf3ecdc 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
@@ -303,7 +303,10 @@
Map<String, Object> metadata = null;
try {
String metadataJson = IOUtils.toString(dummyMetadata.toURI());
- metadata = new TreeMap<>((Map<String, Object>)JsonUtils.json2map(metadataJson).get(req.getAppCode()));
+ metadata = (Map<String, Object>)JsonUtils.json2map(metadataJson).get(req.getAppCode());
+ if (metadata == null)
+ throw new SeCurisException("App code in request is unknown: " + req.getAppCode());
+ metadata = new TreeMap<>(metadata);
} catch (IOException e) {
LOG.error("Error reading dummy metadata file", e);
throw new SeCurisException("Error reading dummy metadata file");
@@ -311,6 +314,7 @@
return metadata;
}
+
private License getLicenseData(RequestBean req) throws SeCurisException {
// TODO: The dummy expiration date is temporal, this info should be read from DB
License lic = new License();
@@ -353,6 +357,15 @@
return Response.ok(lic).build();
}
+ /**
+ * Returns a License file in JSON format from an uploaded Request file
+ * @param mpfdi
+ * @param bsc
+ * @return
+ * @throws IOException
+ * @throws SeCurisServiceException
+ * @throws SeCurisException
+ */
@POST
@Path("/request")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@@ -374,10 +387,71 @@
return createFromRequest(req, bsc);
}
-
+ /**
+ * Create a new License file based in a previous one
+ *
+ * @param request
+ * @param bsc
+ * @return
+ * @throws IOException
+ * @throws SeCurisServiceException
+ * @throws SeCurisException
+ */
+ @POST
+ @Path("/renew")
+ @Consumes(MediaType.APPLICATION_JSON)
+ //TODO: Enable this: @Securable
+ @Produces({
+ MediaType.APPLICATION_JSON
+ })
+ @Transactional
+ public Response renewFromPreviousLicense(LicenseBean previousLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException {
+ LOG.info("Request to get license: {}", previousLic);
+ Map<String, Object> metadata = getLicenseMetadata(previousLic);
+ License licDB = getLicenseData(previousLic);
+ Date expirationDate = licDB.getExpirationDate();
+ String licenseTypeCode = licDB.getPack().getLicenseType().getCode();
+ String licenseCode = licDB.getCode();
+ LicenseBean lic = licenseGenerator.generateLicense(previousLic, metadata, expirationDate, licenseTypeCode, licenseCode);
+ return Response.ok(lic).build();
+ }
+
+ /**
+ * Returns a new License file in JSON format based in a previous license
+ * @param mpfdi
+ * @param bsc
+ * @return
+ * @throws IOException
+ * @throws SeCurisServiceException
+ * @throws SeCurisException
+ */
+ @POST
+ @Path("/renew")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Securable
+ @Produces({
+ MediaType.APPLICATION_JSON
+ })
+ @Transactional
+ @SuppressWarnings("unchecked")
+ public Response renewFromLicenseFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException {
+ LicenseBean lic = new LicenseBean();
+ // TODO: Add more license parameters
+ lic.setAppCode(mpfdi.getFormDataPart("appCode", String.class, null));
+ lic.setArch(mpfdi.getFormDataPart("arch", String.class, null));
+ lic.setCrcLogo(mpfdi.getFormDataPart("crcLogo", String.class, null));
+ lic.setCustomerCode(mpfdi.getFormDataPart("customerCode", String.class, null));
+ lic.setMacAddresses(mpfdi.getFormDataPart("macAddresses", List.class, null));
+ lic.setOsName(mpfdi.getFormDataPart("osName", String.class, null));
+ return createFromRequest(lic, bsc);
+ }
+
+
+
+
@PUT
@POST
@Path("/{licId}")
--
Gitblit v1.3.2