|
@@ -1,9 +1,8 @@
|
|
|
package com.qmth.boot.core.solar.service;
|
|
|
|
|
|
-import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.boot.core.solar.api.SolarApiClient;
|
|
|
import com.qmth.boot.core.solar.config.SolarProperties;
|
|
|
-import com.qmth.boot.core.solar.crypto.AppLicenseParser;
|
|
|
+import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
|
|
|
import com.qmth.boot.core.solar.model.AppControl;
|
|
|
import com.qmth.boot.core.solar.model.AppInfo;
|
|
|
import com.qmth.boot.core.solar.model.AppLicense;
|
|
@@ -32,9 +31,7 @@ public class SolarService {
|
|
|
public SolarService(SolarProperties solarProperties, SolarApiClient solarApiClient) {
|
|
|
this.solarProperties = solarProperties;
|
|
|
this.solarApiClient = solarApiClient;
|
|
|
- if (solarProperties.isCheckup()) {
|
|
|
- checkup();
|
|
|
- }
|
|
|
+ checkup();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -52,7 +49,7 @@ public class SolarService {
|
|
|
* @return
|
|
|
*/
|
|
|
public AppControl getAppControl() {
|
|
|
- return appInfo.getControl();
|
|
|
+ return appInfo != null ? appInfo.getControl() : null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -81,27 +78,74 @@ public class SolarService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 使用AK信息在线激活
|
|
|
+ *
|
|
|
+ * @param accessKey
|
|
|
+ * @param accessSecret
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public synchronized AppInfo update(String accessKey, String accessSecret) {
|
|
|
+ appInfo = null;
|
|
|
+ license = null;
|
|
|
+ solarProperties.setAccessKey(accessKey);
|
|
|
+ solarProperties.setAccessSecret(accessSecret);
|
|
|
+ solarProperties.setLicense(null);
|
|
|
+ try {
|
|
|
+ appInfo = solarApiClient.getAppInfo();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Solar api invoke error", e);
|
|
|
+ }
|
|
|
+ return appInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用授权文件离线激活,同时需要在有效期内
|
|
|
+ *
|
|
|
+ * @param licenseData
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public synchronized AppInfo update(byte[] licenseData) {
|
|
|
+ appInfo = null;
|
|
|
+ license = null;
|
|
|
+ solarProperties.setAccessKey(null);
|
|
|
+ solarProperties.setAccessSecret(null);
|
|
|
+ AppLicense result = AppLicenseUtil.parseLicense(licenseData);
|
|
|
+ if (result != null && !result.getControl().hasExpired()) {
|
|
|
+ license = result;
|
|
|
+ appInfo = result;
|
|
|
+ }
|
|
|
+ return appInfo;
|
|
|
+ }
|
|
|
+
|
|
|
private void checkup() {
|
|
|
- log.info("Solar checkup starting...");
|
|
|
+ log.info("Solar startup checking...");
|
|
|
if (StringUtils.isNotBlank(solarProperties.getAccessKey()) && StringUtils
|
|
|
.isNotBlank(solarProperties.getAccessSecret())) {
|
|
|
- appInfo = solarApiClient.getAppInfo();
|
|
|
- if (appInfo == null) {
|
|
|
- throw new StatusException("Solar online validate faile!");
|
|
|
+ try {
|
|
|
+ appInfo = solarApiClient.getAppInfo();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Solar api invoke error", e);
|
|
|
}
|
|
|
} else if (StringUtils.isNotBlank(solarProperties.getLicense())) {
|
|
|
- license = AppLicenseParser.parse(solarProperties.getLicense());
|
|
|
- if (license == null) {
|
|
|
- throw new StatusException("Solar license invalid");
|
|
|
- }
|
|
|
- appInfo = license;
|
|
|
- if (getAppControl().hasExpired()) {
|
|
|
- throw new StatusException("Solar license has expired");
|
|
|
+ //启动授权文件默认绑定硬件信息
|
|
|
+ AppLicense license = AppLicenseUtil.parseLicense(solarProperties.getLicense());
|
|
|
+ if (license != null) {
|
|
|
+ if (license.getControl().hasExpired()) {
|
|
|
+ log.error("Solar license has expired");
|
|
|
+ } else {
|
|
|
+ this.license = license;
|
|
|
+ this.appInfo = license;
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
- throw new StatusException("Solar checkup faile, accessKey&accessSecret or license file is required!");
|
|
|
+ log.warn("Solar startup check exit, accessKey&accessSecret and license file not exist!");
|
|
|
+ }
|
|
|
+ if (appInfo != null) {
|
|
|
+ log.info("Solar startup check success, current app name: " + appInfo.getName());
|
|
|
+ } else {
|
|
|
+ log.info("Solar startup check faile, app unexist!");
|
|
|
}
|
|
|
- log.info("Solar checkup success, current app name: " + appInfo.getName());
|
|
|
}
|
|
|
|
|
|
}
|