rsanchez
2014-12-12 fb1bbf788b8c2ec2cc292c66c851c7f0b9b19357
#2140 fix - Added securis client properties file and some issues on API
services
1 files added
4 files modified
changed files
securis/src/main/java/net/curisit/securis/services/ApiResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/exception/SeCurisServiceException.java patch | view | blame | history
securis/src/main/resources/db/initial_data.sql patch | view | blame | history
securis/src/main/resources/securis-client.properties patch | view | blame | history
securis/src/main/webapp/js/licenses.js patch | view | blame | history
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);
securis/src/main/java/net/curisit/securis/services/exception/SeCurisServiceException.java
....@@ -36,6 +36,7 @@
3636 public static int INVALID_LICENSE_REQUEST_DATA = 1100;
3737 public static int LICENSE_NOT_READY_FOR_RENEW = 1101;
3838 public static int LICENSE_DATA_IS_NOT_VALID = 1102;
39
+ public static int LICENSE_IS_EXPIRED = 1103;
3940
4041 public static int INVALID_REQUEST_DATA = 1201;
4142 public static int INVALID_REQUEST_DATA_FORMAT = 1202;
securis/src/main/resources/db/initial_data.sql
....@@ -2,4 +2,4 @@
22
33 #Password: securis
44 insert into user (username, password, roles, first_name, last_name, creation_timestamp) values ('admin', '64f170fd736a2d4658fa87abde12043009d2554636c397032d57d71aea8556e9', 2, 'Administrator', null, now());
5
-insert into user (username, password, roles, first_name, last_name, creation_timestamp) values ('_client', '64f170fd736a2d4658fa87abde12043009d2554636c397032d57d71aea8556e9', 2, 'SeCuris client user', null, now());
5
+insert into user (username, password, roles, first_name, last_name, creation_timestamp) values ('_client', '64f170fd736a2d4658fa87abde12043009d2554636c397032d57d71aea8556e9', 0, 'SeCuris client user', null, now());
securis/src/main/resources/securis-client.properties
....@@ -0,0 +1,5 @@
1
+
2
+license.server.url = http://localhost:8080/securis
3
+app.code = __APP_CODE__
4
+customer.code = __CUSTOMER_CODE__
5
+pack.code = __PACK_CODE__
securis/src/main/webapp/js/licenses.js
....@@ -434,10 +434,7 @@
434434 var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}];
435435 Catalogs.loadRefs(function(refs) {
436436 $scope.refs = refs;
437
- angular.forEach($scope.packs, function(elem) {
438
- elem.organization_code = $scope.getOrganizationCode(elem.organization_id);
439
- elem.license_type_code = $scope.getLicenseTypeCode(elem.license_type_id);
440
- });
437
+ $scope._extendPackListing($scope.packs);
441438 }, refFields);
442439 });
443440
....@@ -452,13 +449,19 @@
452449 $scope.pack = null;
453450
454451 $scope.packs = Packs.getPacksList(function(list) {
455
- console.log('The packs were got: ' + list);
456
- angular.forEach(list, function(elem) {
452
+ $scope._extendPackListing(list);
453
+ });
454
+
455
+ /**
456
+ * Added calculated fields like org_code and lic_type_code to pack listing
457
+ */
458
+ $scope._extendPackListing = function(listing) {
459
+ angular.forEach(listing, function(elem) {
457460 elem.organization_code = $scope.getOrganizationCode(elem.organization_id);
458461 elem.license_type_code = $scope.getLicenseTypeCode(elem.license_type_id);
459462 });
460
- });
461
-
463
+ }
464
+
462465 $scope.save = function() {
463466 Packs.savePackData($scope.pack, $scope.isNew, function() {
464467 if (!$scope.isNew) {
....@@ -466,7 +469,9 @@
466469 } else {
467470 $scope.newPack();
468471 }
469
- $scope.packs = Packs.getPacksList();
472
+ $scope.packs = Packs.getPacksList(function(list) {
473
+ $scope._extendPackListing(list);
474
+ });
470475 });
471476 }
472477
....@@ -479,12 +484,16 @@
479484 if (extra_data) {
480485 Packs[action](pack || $scope.pack, extra_data, function() {
481486 if (!$scope.isNew) $scope.showForm = false;
482
- $scope.packs = Packs.getPacksList();
487
+ $scope.packs = Packs.getPacksList(function(list) {
488
+ $scope._extendPackListing(list);
489
+ });
483490 });
484491 } else {
485492 Packs[action](pack || $scope.pack, function() {
486493 if (!$scope.isNew) $scope.showForm = false;
487
- $scope.packs = Packs.getPacksList();
494
+ $scope.packs = Packs.getPacksList(function(list) {
495
+ $scope._extendPackListing(list);
496
+ });
488497 });
489498 }
490499 }