#2140 fix - Added securis client properties file and some issues on API
services
1 files added
4 files modified
| .. | .. |
|---|
| 54 | 54 | @Path("/api") |
|---|
| 55 | 55 | public class ApiResource { |
|---|
| 56 | 56 | |
|---|
| 57 | | - @SuppressWarnings("unused") |
|---|
| 58 | 57 | private static final Logger LOG = LogManager.getLogger(ApiResource.class); |
|---|
| 59 | 58 | |
|---|
| 60 | 59 | @Inject |
|---|
| .. | .. |
|---|
| 189 | 188 | throw new SeCurisServiceException(ErrorCodes.LICENSE_NOT_READY_FOR_RENEW, "The license is still valid, not ready for renew"); |
|---|
| 190 | 189 | } |
|---|
| 191 | 190 | |
|---|
| 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 | + } |
|---|
| 193 | 196 | |
|---|
| 194 | | - return Response.ok(lic).build(); |
|---|
| 197 | + SignedLicenseBean signedLic = createLicense(previousLic, em, true); |
|---|
| 198 | + |
|---|
| 199 | + return Response.ok(signedLic).build(); |
|---|
| 195 | 200 | } |
|---|
| 196 | 201 | |
|---|
| 197 | 202 | /** |
|---|
| .. | .. |
|---|
| 215 | 220 | @Transactional |
|---|
| 216 | 221 | public Response validate(LicenseBean currentLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException { |
|---|
| 217 | 222 | 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 | + |
|---|
| 218 | 228 | EntityManager em = emProvider.get(); |
|---|
| 219 | 229 | try { |
|---|
| 220 | 230 | SignatureHelper.getInstance().validateSignature(currentLic); |
|---|
| .. | .. |
|---|
| 36 | 36 | public static int INVALID_LICENSE_REQUEST_DATA = 1100; |
|---|
| 37 | 37 | public static int LICENSE_NOT_READY_FOR_RENEW = 1101; |
|---|
| 38 | 38 | public static int LICENSE_DATA_IS_NOT_VALID = 1102; |
|---|
| 39 | + public static int LICENSE_IS_EXPIRED = 1103; |
|---|
| 39 | 40 | |
|---|
| 40 | 41 | public static int INVALID_REQUEST_DATA = 1201; |
|---|
| 41 | 42 | public static int INVALID_REQUEST_DATA_FORMAT = 1202; |
|---|
| .. | .. |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | #Password: securis |
|---|
| 4 | 4 | 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()); |
|---|
| .. | .. |
|---|
| 1 | + |
|---|
| 2 | +license.server.url = http://localhost:8080/securis |
|---|
| 3 | +app.code = __APP_CODE__ |
|---|
| 4 | +customer.code = __CUSTOMER_CODE__ |
|---|
| 5 | +pack.code = __PACK_CODE__ |
|---|
| .. | .. |
|---|
| 434 | 434 | var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}]; |
|---|
| 435 | 435 | Catalogs.loadRefs(function(refs) { |
|---|
| 436 | 436 | $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); |
|---|
| 441 | 438 | }, refFields); |
|---|
| 442 | 439 | }); |
|---|
| 443 | 440 | |
|---|
| .. | .. |
|---|
| 452 | 449 | $scope.pack = null; |
|---|
| 453 | 450 | |
|---|
| 454 | 451 | $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) { |
|---|
| 457 | 460 | elem.organization_code = $scope.getOrganizationCode(elem.organization_id); |
|---|
| 458 | 461 | elem.license_type_code = $scope.getLicenseTypeCode(elem.license_type_id); |
|---|
| 459 | 462 | }); |
|---|
| 460 | | - }); |
|---|
| 461 | | - |
|---|
| 463 | + } |
|---|
| 464 | + |
|---|
| 462 | 465 | $scope.save = function() { |
|---|
| 463 | 466 | Packs.savePackData($scope.pack, $scope.isNew, function() { |
|---|
| 464 | 467 | if (!$scope.isNew) { |
|---|
| .. | .. |
|---|
| 466 | 469 | } else { |
|---|
| 467 | 470 | $scope.newPack(); |
|---|
| 468 | 471 | } |
|---|
| 469 | | - $scope.packs = Packs.getPacksList(); |
|---|
| 472 | + $scope.packs = Packs.getPacksList(function(list) { |
|---|
| 473 | + $scope._extendPackListing(list); |
|---|
| 474 | + }); |
|---|
| 470 | 475 | }); |
|---|
| 471 | 476 | } |
|---|
| 472 | 477 | |
|---|
| .. | .. |
|---|
| 479 | 484 | if (extra_data) { |
|---|
| 480 | 485 | Packs[action](pack || $scope.pack, extra_data, function() { |
|---|
| 481 | 486 | if (!$scope.isNew) $scope.showForm = false; |
|---|
| 482 | | - $scope.packs = Packs.getPacksList(); |
|---|
| 487 | + $scope.packs = Packs.getPacksList(function(list) { |
|---|
| 488 | + $scope._extendPackListing(list); |
|---|
| 489 | + }); |
|---|
| 483 | 490 | }); |
|---|
| 484 | 491 | } else { |
|---|
| 485 | 492 | Packs[action](pack || $scope.pack, function() { |
|---|
| 486 | 493 | if (!$scope.isNew) $scope.showForm = false; |
|---|
| 487 | | - $scope.packs = Packs.getPacksList(); |
|---|
| 494 | + $scope.packs = Packs.getPacksList(function(list) { |
|---|
| 495 | + $scope._extendPackListing(list); |
|---|
| 496 | + }); |
|---|
| 488 | 497 | }); |
|---|
| 489 | 498 | } |
|---|
| 490 | 499 | } |
|---|