| .. | .. |
|---|
| 11 | 11 | import java.security.Signature; |
|---|
| 12 | 12 | import java.security.SignatureException; |
|---|
| 13 | 13 | import java.security.spec.InvalidKeySpecException; |
|---|
| 14 | | -import java.text.MessageFormat; |
|---|
| 15 | 14 | import java.util.Date; |
|---|
| 16 | 15 | import java.util.Map; |
|---|
| 17 | 16 | import java.util.TreeMap; |
|---|
| .. | .. |
|---|
| 57 | 56 | * @return |
|---|
| 58 | 57 | * @throws SeCurisException |
|---|
| 59 | 58 | */ |
|---|
| 60 | | - public LicenseBean generateLicense(RequestBean req, Map<String, Object> metadata, Date expirationDate, String licenseType, String licenseCode) |
|---|
| 59 | + public LicenseBean generateLicense(RequestBean req, Map<String, Object> metadata, Date expirationDate, String licenseCode, String appName) |
|---|
| 61 | 60 | throws SeCurisException { |
|---|
| 62 | | - LOG.info(MessageFormat.format("Generating license: MAC: {0}, Customer code: {1}, AppCode: {2}", req.getMacAddresses(), req.getCustomerCode(), |
|---|
| 63 | | - req.getAppCode())); |
|---|
| 61 | + LOG.debug("Generating license: MAC: {}, Customer code: {}, AppName: {}", req.getMacAddresses(), req.getCustomerCode(), appName); |
|---|
| 64 | 62 | LicenseBean license = new LicenseBean(req); |
|---|
| 65 | | - license.setLicenseType(licenseType); |
|---|
| 66 | | - license.setLicenseCode(licenseCode); |
|---|
| 63 | + license.setAppName(appName); |
|---|
| 67 | 64 | license.setExpirationDate(expirationDate); |
|---|
| 68 | 65 | license.setMetadata(metadata); |
|---|
| 69 | 66 | sign(license); |
|---|
| .. | .. |
|---|
| 82 | 79 | SignedLicenseBean signedLic = new SignedLicenseBean(license); |
|---|
| 83 | 80 | byte[] json; |
|---|
| 84 | 81 | try { |
|---|
| 85 | | - json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8"); |
|---|
| 82 | + json = JsonUtils.toPrettyJSON(signedLic).getBytes("utf-8"); |
|---|
| 86 | 83 | Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); |
|---|
| 87 | 84 | } catch (UnsupportedEncodingException e) { |
|---|
| 88 | 85 | LOG.error("Error creating json doc from license: " + license, e); |
|---|
| .. | .. |
|---|
| 97 | 94 | } |
|---|
| 98 | 95 | |
|---|
| 99 | 96 | /** |
|---|
| 100 | | - * TODO: This method should be removed from client code. |
|---|
| 101 | 97 | * |
|---|
| 102 | 98 | * @param licBean |
|---|
| 103 | 99 | * @return |
|---|
| .. | .. |
|---|
| 113 | 109 | Signature signature; |
|---|
| 114 | 110 | try { |
|---|
| 115 | 111 | signature = Signature.getInstance(SignatureHelper.SIGNATURE_GENERATION_ALGORITHM); |
|---|
| 116 | | - signature.initSign(sh.generatePrivateKey(new File(System.getProperty("user.home") + File.separator + ".SeCuris" + File.separator + "keys" + File.separator + "securis_private_key.pkcs8"))); |
|---|
| 112 | + signature.initSign(sh.generatePrivateKey(new File(System.getProperty("user.home") + File.separator + ".SeCuris" + File.separator + "keys" |
|---|
| 113 | + + File.separator + "securis_private_key.pkcs8"))); |
|---|
| 117 | 114 | |
|---|
| 118 | 115 | sh.prepareSignature(signature, licBean); |
|---|
| 119 | 116 | |
|---|
| .. | .. |
|---|
| 147 | 144 | metadata.put("timeThreshold", 0); |
|---|
| 148 | 145 | metadata.put("datasetPrefix", "BP"); |
|---|
| 149 | 146 | metadata.put("extendedMode", true); |
|---|
| 150 | | - |
|---|
| 147 | + |
|---|
| 151 | 148 | Date expirationDate = new Date(new Date().getTime() + (1000L * 3600 * 24 * 365 * 10)); |
|---|
| 152 | 149 | LicenseBean lic = LicenseGenerator.getInstance().generateLicense(req, metadata, expirationDate, "CI-01", "LIC-CURISTEC-0001"); |
|---|
| 153 | 150 | LicenseGenerator.getInstance().save(lic, new File("/Users/cproberto/Desktop/AxelLicCI.lic")); |
|---|
| .. | .. |
|---|
| 156 | 153 | |
|---|
| 157 | 154 | } |
|---|
| 158 | 155 | } |
|---|
| 159 | | - |
|---|