Skip to content

Commit

Permalink
fix: license error in community mode
Browse files Browse the repository at this point in the history
  • Loading branch information
a-cordier authored and gaetanmaisse committed May 4, 2023
1 parent 6451b54 commit 6a26fa1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax0.license3j.Feature;
import javax0.license3j.License;
import javax0.license3j.io.LicenseReader;
import org.slf4j.Logger;
Expand Down Expand Up @@ -182,8 +181,10 @@ public void loadLicense() throws Exception {
reader = new LicenseReader(new ByteArrayInputStream(licenseContent));
license = reader.read();

this.dump();
this.printLicenseInfo();
this.verify();
} catch (IllegalArgumentException iae) {
logger.error("License file is not valid", iae);
} catch (IOException ioe) {
logger.error("License file can not be read", ioe);
}
Expand Down Expand Up @@ -216,13 +217,18 @@ private byte[] getLicenseContent() {
private String getLicenseFile() {
String licenseFile = System.getProperty(GRAVITEE_LICENSE_PROPERTY);
if (licenseFile == null || licenseFile.isEmpty()) {
licenseFile = System.getProperty(GRAVITEE_HOME_PROPERTY) + File.separator + "license" + File.separator + "license.key";
licenseFile = System.getProperty(GRAVITEE_HOME_PROPERTY) + File.separator + "license" + File.separator + GRAVITEE_LICENSE_KEY;
}

return licenseFile;
}

private void verify() throws Exception {
if (license == null) {
logger.debug("License will not be verified as it has not been loaded");
return;
}

boolean valid = license.isOK(key);

if (!valid) {
Expand All @@ -235,16 +241,6 @@ private void verify() throws Exception {
stopNode();
}

// Apply additional checks according to the node implementation
//License3JLicense license3JLicense = new License3JLicense(license);

/*
if (!isValid(license3JLicense)) {
logger.error("License does not allow you to use {}. Please contact GraviteeSource to ask for a valid license.", node.name());
stopNode();
}
*/

Date expiration = license.get(LICENSE_EXPIRE_AT).getDate();
long remainingDays = Math.round((expiration.getTime() - System.currentTimeMillis()) / (double) 86400000);

Expand All @@ -253,11 +249,13 @@ private void verify() throws Exception {
}
}

private void dump() {
// Print features
logger.info("License informations: ");
Map<String, Feature> features = license.getFeatures();
features.forEach((name, feature) -> logger.info("\t{}: {}", name, feature.valueString()));
private void printLicenseInfo() {
StringBuilder sb = new StringBuilder();
sb.append("License information: \n");
license
.getFeatures()
.forEach((name, feature) -> sb.append("\t").append(name).append(": ").append(feature.valueString()).append("\n"));
logger.info(sb.toString());
}

private class LicenseChecker extends TimerTask {
Expand All @@ -267,7 +265,7 @@ public void run() {
try {
LicenseService.this.verify();
} catch (Exception e) {
e.printStackTrace();
logger.error("An error occurred while checking license", e);
}
}
}
Expand Down Expand Up @@ -320,8 +318,8 @@ public void run() {
}
Thread.yield();
}
} catch (Throwable e) {
// Log or rethrow the error
} catch (Exception e) {
logger.debug("An error occurred while watching license file", e);
}
}

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
<configuration>
<nodeVersion>12.13.0</nodeVersion>
<prettierJavaVersion>1.6.1</prettierJavaVersion>
<skip>${skip.validation}</skip>
</configuration>
<executions>
<execution>
Expand Down

0 comments on commit 6a26fa1

Please sign in to comment.