From fb1bbf788b8c2ec2cc292c66c851c7f0b9b19357 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Fri, 12 Dec 2014 12:01:18 +0000
Subject: [PATCH] #2140 fix - Added securis client properties file and some issues on API services
---
securis/src/main/resources/securis-client.properties | 5 +++++
securis/src/main/resources/db/initial_data.sql | 2 +-
securis/src/main/java/net/curisit/securis/services/ApiResource.java | 16 +++++++++++++---
securis/src/main/webapp/js/licenses.js | 31 ++++++++++++++++++++-----------
securis/src/main/java/net/curisit/securis/services/exception/SeCurisServiceException.java | 1 +
5 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/securis/src/main/java/net/curisit/securis/services/ApiResource.java b/securis/src/main/java/net/curisit/securis/services/ApiResource.java
index 2df1325..d432621 100644
--- a/securis/src/main/java/net/curisit/securis/services/ApiResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/ApiResource.java
@@ -54,7 +54,6 @@
@Path("/api")
public class ApiResource {
- @SuppressWarnings("unused")
private static final Logger LOG = LogManager.getLogger(ApiResource.class);
@Inject
@@ -189,9 +188,15 @@
throw new SeCurisServiceException(ErrorCodes.LICENSE_NOT_READY_FOR_RENEW, "The license is still valid, not ready for renew");
}
- SignedLicenseBean lic = createLicense(previousLic, emProvider.get(), true);
+ EntityManager em = emProvider.get();
+ License lic = License.findLicenseByCode(previousLic.getLicenseCode(), em);
+ if (lic.getStatus() != LicenseStatus.ACTIVE) {
+ throw new SeCurisServiceException(ErrorCodes.LICENSE_NOT_READY_FOR_RENEW, "Only licenses with status 'Active' can be renew");
+ }
- return Response.ok(lic).build();
+ SignedLicenseBean signedLic = createLicense(previousLic, em, true);
+
+ return Response.ok(signedLic).build();
}
/**
@@ -215,6 +220,11 @@
@Transactional
public Response validate(LicenseBean currentLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException {
LOG.info("Validate license: {}", currentLic);
+
+ if (currentLic.getExpirationDate().before(new Date())) {
+ throw new SeCurisServiceException(ErrorCodes.LICENSE_IS_EXPIRED, "The license is expired");
+ }
+
EntityManager em = emProvider.get();
try {
SignatureHelper.getInstance().validateSignature(currentLic);
diff --git a/securis/src/main/java/net/curisit/securis/services/exception/SeCurisServiceException.java b/securis/src/main/java/net/curisit/securis/services/exception/SeCurisServiceException.java
index 3e38141..40846c2 100644
--- a/securis/src/main/java/net/curisit/securis/services/exception/SeCurisServiceException.java
+++ b/securis/src/main/java/net/curisit/securis/services/exception/SeCurisServiceException.java
@@ -36,6 +36,7 @@
public static int INVALID_LICENSE_REQUEST_DATA = 1100;
public static int LICENSE_NOT_READY_FOR_RENEW = 1101;
public static int LICENSE_DATA_IS_NOT_VALID = 1102;
+ public static int LICENSE_IS_EXPIRED = 1103;
public static int INVALID_REQUEST_DATA = 1201;
public static int INVALID_REQUEST_DATA_FORMAT = 1202;
diff --git a/securis/src/main/resources/db/initial_data.sql b/securis/src/main/resources/db/initial_data.sql
index 20cb761..e0e47a6 100644
--- a/securis/src/main/resources/db/initial_data.sql
+++ b/securis/src/main/resources/db/initial_data.sql
@@ -2,4 +2,4 @@
#Password: securis
insert into user (username, password, roles, first_name, last_name, creation_timestamp) values ('admin', '64f170fd736a2d4658fa87abde12043009d2554636c397032d57d71aea8556e9', 2, 'Administrator', null, now());
-insert into user (username, password, roles, first_name, last_name, creation_timestamp) values ('_client', '64f170fd736a2d4658fa87abde12043009d2554636c397032d57d71aea8556e9', 2, 'SeCuris client user', null, now());
\ No newline at end of file
+insert into user (username, password, roles, first_name, last_name, creation_timestamp) values ('_client', '64f170fd736a2d4658fa87abde12043009d2554636c397032d57d71aea8556e9', 0, 'SeCuris client user', null, now());
\ No newline at end of file
diff --git a/securis/src/main/resources/securis-client.properties b/securis/src/main/resources/securis-client.properties
new file mode 100644
index 0000000..1fc0ebd
--- /dev/null
+++ b/securis/src/main/resources/securis-client.properties
@@ -0,0 +1,5 @@
+
+license.server.url = http://localhost:8080/securis
+app.code = __APP_CODE__
+customer.code = __CUSTOMER_CODE__
+pack.code = __PACK_CODE__
diff --git a/securis/src/main/webapp/js/licenses.js b/securis/src/main/webapp/js/licenses.js
index 62bcb36..facb915 100644
--- a/securis/src/main/webapp/js/licenses.js
+++ b/securis/src/main/webapp/js/licenses.js
@@ -434,10 +434,7 @@
var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}];
Catalogs.loadRefs(function(refs) {
$scope.refs = refs;
- angular.forEach($scope.packs, function(elem) {
- elem.organization_code = $scope.getOrganizationCode(elem.organization_id);
- elem.license_type_code = $scope.getLicenseTypeCode(elem.license_type_id);
- });
+ $scope._extendPackListing($scope.packs);
}, refFields);
});
@@ -452,13 +449,19 @@
$scope.pack = null;
$scope.packs = Packs.getPacksList(function(list) {
- console.log('The packs were got: ' + list);
- angular.forEach(list, function(elem) {
+ $scope._extendPackListing(list);
+ });
+
+ /**
+ * Added calculated fields like org_code and lic_type_code to pack listing
+ */
+ $scope._extendPackListing = function(listing) {
+ angular.forEach(listing, function(elem) {
elem.organization_code = $scope.getOrganizationCode(elem.organization_id);
elem.license_type_code = $scope.getLicenseTypeCode(elem.license_type_id);
});
- });
-
+ }
+
$scope.save = function() {
Packs.savePackData($scope.pack, $scope.isNew, function() {
if (!$scope.isNew) {
@@ -466,7 +469,9 @@
} else {
$scope.newPack();
}
- $scope.packs = Packs.getPacksList();
+ $scope.packs = Packs.getPacksList(function(list) {
+ $scope._extendPackListing(list);
+ });
});
}
@@ -479,12 +484,16 @@
if (extra_data) {
Packs[action](pack || $scope.pack, extra_data, function() {
if (!$scope.isNew) $scope.showForm = false;
- $scope.packs = Packs.getPacksList();
+ $scope.packs = Packs.getPacksList(function(list) {
+ $scope._extendPackListing(list);
+ });
});
} else {
Packs[action](pack || $scope.pack, function() {
if (!$scope.isNew) $scope.showForm = false;
- $scope.packs = Packs.getPacksList();
+ $scope.packs = Packs.getPacksList(function(list) {
+ $scope._extendPackListing(list);
+ });
});
}
}
--
Gitblit v1.3.2