| .. | .. |
|---|
| 33 | 33 | */ |
|---|
| 34 | 34 | public class LicenseGenerator { |
|---|
| 35 | 35 | |
|---|
| 36 | | - private static final Logger log = LogManager.getLogger(LicenseGenerator.class); |
|---|
| 36 | + private static final Logger LOG = LogManager.getLogger(LicenseGenerator.class); |
|---|
| 37 | 37 | |
|---|
| 38 | 38 | private static LicenseGenerator singleton = new LicenseGenerator(); |
|---|
| 39 | 39 | |
|---|
| .. | .. |
|---|
| 58 | 58 | * @throws SeCurisException |
|---|
| 59 | 59 | */ |
|---|
| 60 | 60 | public LicenseBean generateLicense(RequestBean req, Map<String, Object> metadata, Date expirationDate, String licenseType, String licenseCode) throws SeCurisException { |
|---|
| 61 | | - log.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(), req.getAppCode())); |
|---|
| 61 | + LOG.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(), req.getAppCode())); |
|---|
| 62 | 62 | LicenseBean license = new LicenseBean(req); |
|---|
| 63 | 63 | license.setLicenseType(licenseType); |
|---|
| 64 | 64 | license.setLicenseCode(licenseCode); |
|---|
| .. | .. |
|---|
| 83 | 83 | json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8"); |
|---|
| 84 | 84 | Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); |
|---|
| 85 | 85 | } catch (UnsupportedEncodingException e) { |
|---|
| 86 | | - log.error("Error creating json doc from license: " + license, e); |
|---|
| 86 | + LOG.error("Error creating json doc from license: " + license, e); |
|---|
| 87 | 87 | throw new SeCurisException("Error creating json doc from license: " + license, e); |
|---|
| 88 | 88 | } catch (IOException e) { |
|---|
| 89 | | - log.error("Error creating license file: " + file, e); |
|---|
| 89 | + LOG.error("Error creating license file: " + file, e); |
|---|
| 90 | 90 | throw new SeCurisException("Error creating json doc from license: " + license, e); |
|---|
| 91 | 91 | } |
|---|
| 92 | 92 | |
|---|
| 93 | | - log.info("License saved in {}", file); |
|---|
| 93 | + LOG.info("License saved in {}", file); |
|---|
| 94 | 94 | |
|---|
| 95 | 95 | } |
|---|
| 96 | 96 | |
|---|
| .. | .. |
|---|
| 119 | 119 | licBean.setSignature(Base64.encodeBase64String(signatureData)); |
|---|
| 120 | 120 | return licBean.getSignature(); |
|---|
| 121 | 121 | } catch (NoSuchAlgorithmException e) { |
|---|
| 122 | | - log.error("Error signing license for " + licBean, e); |
|---|
| 122 | + LOG.error("Error signing license for " + licBean, e); |
|---|
| 123 | 123 | } catch (InvalidKeyException e) { |
|---|
| 124 | | - log.error("Error signing license for " + licBean, e); |
|---|
| 124 | + LOG.error("Error signing license for " + licBean, e); |
|---|
| 125 | 125 | } catch (InvalidKeySpecException e) { |
|---|
| 126 | | - log.error("Error signing license for " + licBean, e); |
|---|
| 126 | + LOG.error("Error signing license for " + licBean, e); |
|---|
| 127 | 127 | } catch (IOException e) { |
|---|
| 128 | | - log.error("Error signing license for " + licBean, e); |
|---|
| 128 | + LOG.error("Error signing license for " + licBean, e); |
|---|
| 129 | 129 | } catch (SignatureException e) { |
|---|
| 130 | | - log.error("Error signing license for " + licBean, e); |
|---|
| 130 | + LOG.error("Error signing license for " + licBean, e); |
|---|
| 131 | 131 | } |
|---|
| 132 | 132 | throw new SeCurisException("License could not be generated"); |
|---|
| 133 | 133 | } |
|---|
| .. | .. |
|---|
| 136 | 136 | |
|---|
| 137 | 137 | RequestBean req = ReqGenerator.getInstance().loadRequest(new File("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/license.req")); |
|---|
| 138 | 138 | Map<String, Object> metadata = new TreeMap<>(); |
|---|
| 139 | | - metadata.put("maxUsers", 20); |
|---|
| 140 | | - metadata.put("maxSessionUsers", 2); |
|---|
| 139 | +// CurisData parameters: |
|---|
| 140 | +// metadata.put("maxUsers", 5); |
|---|
| 141 | +// metadata.put("maxSessionUsers", 100); |
|---|
| 142 | + // curisIntegrity |
|---|
| 143 | + metadata.put("maxUsers", 0); |
|---|
| 144 | + metadata.put("maxInstances", 0); |
|---|
| 145 | + metadata.put("timeThreshold", 0); |
|---|
| 146 | + metadata.put("datasetPrefix", "BP"); |
|---|
| 147 | + metadata.put("extendedMode", true); |
|---|
| 141 | 148 | Date expirationDate = new Date(new Date().getTime() + (1000L * 3600 * 24 * 365 * 10)); |
|---|
| 142 | | - LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CD-01", "LIC-CURISTEC-0001"); |
|---|
| 143 | | - LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/YanFei.lic")); |
|---|
| 149 | + LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CI-01", "LIC-CURISTEC-0001"); |
|---|
| 150 | + LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/AxelLicCI.lic")); |
|---|
| 144 | 151 | |
|---|
| 145 | 152 | System.out.print("License expires at: " + expirationDate.getTime()); |
|---|
| 146 | 153 | |
|---|