diff --git a/gravitee-node-license/pom.xml b/gravitee-node-license/pom.xml
index 09728905e..398ab1ec7 100644
--- a/gravitee-node-license/pom.xml
+++ b/gravitee-node-license/pom.xml
@@ -69,6 +69,10 @@
+
+ ch.qos.logback
+ logback-classic
+
org.slf4j
jcl-over-slf4j
diff --git a/gravitee-node-license/src/main/java/io/gravitee/node/license/NodeLicenseServiceImpl.java b/gravitee-node-license/src/main/java/io/gravitee/node/license/NodeLicenseServiceImpl.java
index f5bd86e2c..723c4af85 100644
--- a/gravitee-node-license/src/main/java/io/gravitee/node/license/NodeLicenseServiceImpl.java
+++ b/gravitee-node-license/src/main/java/io/gravitee/node/license/NodeLicenseServiceImpl.java
@@ -23,10 +23,13 @@
import io.gravitee.node.api.license.LicenseModelService;
import io.gravitee.node.api.license.NodeLicenseService;
import io.gravitee.node.api.license.model.LicenseModel;
+import io.gravitee.node.api.license.model.LicensePack;
+import io.gravitee.node.api.license.model.LicenseTier;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
@@ -34,6 +37,7 @@
* @author GraviteeSource Team
*/
@Component
+@Slf4j
public class NodeLicenseServiceImpl implements NodeLicenseService {
private static final String LICENSE_TIER_KEY = "tier";
@@ -89,8 +93,14 @@ private String readTier() {
private Set readPacks() {
Set licensePacks = new HashSet<>(readList(LICENSE_PACKS_KEY));
if (tier != null) {
- Set tierPacks = licenseModelService.getLicenseModel().getTiers().get(tier).getPacks();
- licensePacks.addAll(tierPacks);
+ // Allow to declare a non existing tier. Useful when the license uses a tier that has been created for a newer version of gravitee-node
+ LicenseTier licenseTier = licenseModelService.getLicenseModel().getTiers().get(tier);
+ if (licenseTier != null) {
+ Set tierPacks = licenseTier.getPacks();
+ licensePacks.addAll(tierPacks);
+ } else if (log.isDebugEnabled()) {
+ log.debug("Unknown tier: {}", tier);
+ }
}
return licensePacks;
}
@@ -101,7 +111,13 @@ private Set readFeatures() {
licenseFeatures.addAll(readList(LICENSE_FEATURES_KEY));
licenseFeatures.addAll(getLegacyFeatures());
for (String pack : getPacks()) {
- licenseFeatures.addAll(licenseModel.getPacks().get(pack).getFeatures());
+ // Allow to declare a non existing pack. Useful when the license uses a pack that has been created for a newer version of gravitee-node
+ LicensePack licensePack = licenseModel.getPacks().get(pack);
+ if (licensePack != null) {
+ licenseFeatures.addAll(licensePack.getFeatures());
+ } else if (log.isDebugEnabled()) {
+ log.debug("Unknown pack: {}", pack);
+ }
}
return licenseFeatures;
}
diff --git a/gravitee-node-license/src/test/java/io/gravitee/node/license/NodeLicenseServiceTest.java b/gravitee-node-license/src/test/java/io/gravitee/node/license/NodeLicenseServiceTest.java
index 13b683c5b..f803dc628 100644
--- a/gravitee-node-license/src/test/java/io/gravitee/node/license/NodeLicenseServiceTest.java
+++ b/gravitee-node-license/src/test/java/io/gravitee/node/license/NodeLicenseServiceTest.java
@@ -70,7 +70,6 @@ void setUp() {
@Test
void shouldReturnTier() {
when(tier.getString()).thenReturn("planet");
- when(license.feature("tier")).thenReturn(Optional.of(tier));
service.refresh();
assertThat(service.getTier()).isEqualTo("planet");
}
@@ -198,4 +197,51 @@ void shouldHaveLegacyFeatureEnabled() {
service.refresh();
assertThat(service.isFeatureEnabled("apim-api-designer")).isTrue();
}
+
+ @Test
+ void shouldNotFailIfUnknownTier() {
+ when(tier.getString()).thenReturn("unknown");
+ when(packs.getString()).thenReturn("enterprise-legacy-upgrade");
+ service.refresh();
+ assertThat(service.getTier()).isEqualTo("unknown");
+ assertThat(service.getPacks()).containsExactly("enterprise-legacy-upgrade");
+ assertThat(service.getFeatures()).containsExactlyInAnyOrder("apim-policy-xslt", "apim-policy-ws-security-authentication");
+ }
+
+ @Test
+ void shouldNotFailIfUnknownPack() {
+ when(tier.getString()).thenReturn("planet");
+ when(packs.getString()).thenReturn("unknown");
+ service.refresh();
+ assertThat(service.getTier()).isEqualTo("planet");
+ assertThat(service.getPacks())
+ .containsExactlyInAnyOrder("enterprise-features", "enterprise-legacy-upgrade", "enterprise-identity-provider", "unknown");
+ assertThat(service.getFeatures())
+ .containsExactlyInAnyOrder(
+ "apim-api-designer",
+ "apim-dcr-registration",
+ "apim-custom-roles",
+ "apim-audit-trail",
+ "apim-sharding-tags",
+ "apim-openid-connect-sso",
+ "apim-debug-mode",
+ "gravitee-risk-assessment",
+ "risk-assessment",
+ "apim-bridge-gateway",
+ "apim-policy-xslt",
+ "apim-policy-ws-security-authentication",
+ "am-idp-salesforce",
+ "am-idp-saml",
+ "am-idp-ldap",
+ "am-idp-kerberos",
+ "am-idp-azure-ad",
+ "am-idp-gateway-handler-saml",
+ "am-gateway-handler-saml-idp",
+ "am-idp-http-flow",
+ "http-flow-am-idp",
+ "am-idp-france-connect",
+ "am-idp-cas",
+ "cas-am-idp"
+ );
+ }
}
diff --git a/gravitee-node-license/src/test/resources/logback-test.xml b/gravitee-node-license/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..7600d1d28
--- /dev/null
+++ b/gravitee-node-license/src/test/resources/logback-test.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+