| | |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.URL; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.text.DateFormat; |
| | |
| | | |
| | | File tempFileFromBase64 = createTempFileFromBase64(license); |
| | | result = licenseManager.install(tempFileFromBase64); |
| | | logger.info(MessageFormat.format("许可证加载成功,许可证有效期:{0} - {1}", format.format(result.getNotBefore()), format.format(result.getNotAfter()))); |
| | | } catch (Exception e) { |
| | | logger.error("许可证加载失败!", e); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public synchronized LicenseContent install(LicenseVerifyParam param) { |
| | | LicenseContent result = null; |
| | | DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | try { |
| | | LicenseParam licenseParam = initLicenseParam(param); |
| | | LicenseManager licenseManager = LicenseManagerHolder.getInstance(licenseParam); |
| | | licenseManager.uninstall(); |
| | | |
| | | File licenseFile = resolveLicenseFile(param.getLicensePath()); |
| | | if (licenseFile == null || !licenseFile.exists()) { |
| | | return null; |
| | | } |
| | | result = licenseManager.install(licenseFile); |
| | | logger.info(MessageFormat.format("许可证加载成功,许可证有效期:{0} - {1}", format.format(result.getNotBefore()), format.format(result.getNotAfter()))); |
| | | } catch (Exception e) { |
| | | logger.error("许可证加载失败!", e); |
| | |
| | | return base64ToTempFile(base64Data, "temp_license_", ".bin"); |
| | | } |
| | | |
| | | private File resolveLicenseFile(String licensePath) { |
| | | try { |
| | | URL url = this.getClass().getClassLoader().getResource(licensePath); |
| | | if (url != null) { |
| | | return new File(url.toURI()); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | return new File(licensePath); |
| | | } |
| | | |
| | | } |