| .. | .. |
|---|
| 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); |
|---|