KEYCLOAK-6078

Account2 is listed as disabled feature in product even though it's not included at all
This commit is contained in:
stianst 2017-12-21 10:33:49 +01:00 committed by Stian Thorgersen
parent c7ce279aef
commit e4185496fd

View file

@ -36,6 +36,17 @@ public class Profile {
AUTHORIZATION, IMPERSONATION, SCRIPTS, DOCKER, ACCOUNT2, TOKEN_EXCHANGE AUTHORIZATION, IMPERSONATION, SCRIPTS, DOCKER, ACCOUNT2, TOKEN_EXCHANGE
} }
private enum ProductValue {
KEYCLOAK(),
RHSSO(Feature.ACCOUNT2);
private List<Feature> excluded;
ProductValue(Feature... excluded) {
this.excluded = Arrays.asList(excluded);
}
}
private enum ProfileValue { private enum ProfileValue {
PRODUCT(Feature.AUTHORIZATION, Feature.SCRIPTS, Feature.DOCKER, Feature.ACCOUNT2, Feature.TOKEN_EXCHANGE), PRODUCT(Feature.AUTHORIZATION, Feature.SCRIPTS, Feature.DOCKER, Feature.ACCOUNT2, Feature.TOKEN_EXCHANGE),
PREVIEW(Feature.ACCOUNT2), PREVIEW(Feature.ACCOUNT2),
@ -43,10 +54,6 @@ public class Profile {
private List<Feature> disabled; private List<Feature> disabled;
ProfileValue() {
this.disabled = Collections.emptyList();
}
ProfileValue(Feature... disabled) { ProfileValue(Feature... disabled) {
this.disabled = Arrays.asList(disabled); this.disabled = Arrays.asList(disabled);
} }
@ -54,11 +61,15 @@ public class Profile {
private static final Profile CURRENT = new Profile(); private static final Profile CURRENT = new Profile();
private final ProductValue product;
private final ProfileValue profile; private final ProfileValue profile;
private final Set<Feature> disabledFeatures = new HashSet<>(); private final Set<Feature> disabledFeatures = new HashSet<>();
private Profile() { private Profile() {
product = "rh-sso".equals(Version.NAME) ? ProductValue.RHSSO : ProductValue.KEYCLOAK;
try { try {
Properties props = new Properties(); Properties props = new Properties();
@ -87,6 +98,7 @@ public class Profile {
} }
disabledFeatures.addAll(profile.disabled); disabledFeatures.addAll(profile.disabled);
disabledFeatures.removeAll(product.excluded);
for (String k : props.stringPropertyNames()) { for (String k : props.stringPropertyNames()) {
if (k.startsWith("feature.")) { if (k.startsWith("feature.")) {
@ -112,6 +124,9 @@ public class Profile {
} }
public static boolean isFeatureEnabled(Feature feature) { public static boolean isFeatureEnabled(Feature feature) {
if (CURRENT.product.excluded.contains(feature)) {
return false;
}
return !CURRENT.disabledFeatures.contains(feature); return !CURRENT.disabledFeatures.contains(feature);
} }