[New] Allow secondaryLocations to be JsonArray, merge instead of replace on conflict

This commit is contained in:
Robert von Burg 2020-07-09 12:05:56 +02:00
parent 874e409072
commit 2892b27614
1 changed files with 22 additions and 10 deletions

View File

@ -154,7 +154,7 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
Set<String> strolchRoles) { Set<String> strolchRoles) {
String primaryLocation = ""; String primaryLocation = "";
String secondaryLocations = ""; Set<String> secondaryLocations = new HashSet<>();
Set<String> locations = new HashSet<>(); Set<String> locations = new HashSet<>();
for (String ldapGroup : ldapGroups) { for (String ldapGroup : ldapGroups) {
@ -163,19 +163,31 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
JsonElement primaryLocationJ = mappingJ.get(PRIMARY_LOCATION); JsonElement primaryLocationJ = mappingJ.get(PRIMARY_LOCATION);
if (primaryLocationJ != null && !primaryLocationJ.isJsonNull()) { if (primaryLocationJ != null && !primaryLocationJ.isJsonNull()) {
if (!primaryLocation.isEmpty()) if (primaryLocation.isEmpty()) {
logger.warn("Primary location already set by previous LDAP Group config, overriding for LDAP Group " primaryLocation = primaryLocationJ.getAsString();
+ ldapGroup); } else {
primaryLocation = primaryLocationJ.getAsString(); logger.warn("Primary location already set by previous LDAP Group config for LDAP Group " + ldapGroup
+ ", adding to secondary locations.");
secondaryLocations.add(primaryLocationJ.getAsString());
}
} }
JsonElement secondaryLocationsJ = mappingJ.get(SECONDARY_LOCATIONS); JsonElement secondaryLocationsJ = mappingJ.get(SECONDARY_LOCATIONS);
if (secondaryLocationsJ != null && !secondaryLocationsJ.isJsonNull()) { if (secondaryLocationsJ != null && !secondaryLocationsJ.isJsonNull()) {
if (!secondaryLocations.isEmpty()) if (secondaryLocations.isEmpty()) {
if (secondaryLocationsJ.isJsonPrimitive())
secondaryLocations.add(secondaryLocationsJ.getAsString());
else
secondaryLocationsJ.getAsJsonArray().forEach(s -> secondaryLocations.add(s.getAsString()));
} else {
logger.warn( logger.warn(
"Secondary locations already set by previous LDAP Group config, overriding for LDAP Group " "Secondary locations already set by previous LDAP Group config for LDAP Group " + ldapGroup
+ ldapGroup); + ", adding additional");
secondaryLocations = secondaryLocationsJ.getAsString(); if (secondaryLocationsJ.isJsonPrimitive())
secondaryLocations.add(secondaryLocationsJ.getAsString());
else
secondaryLocationsJ.getAsJsonArray().forEach(s -> secondaryLocations.add(s.getAsString()));
}
} }
} }
@ -183,7 +195,7 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
properties.put(REALM, this.realm); properties.put(REALM, this.realm);
properties.put(LOCATION, join(",", locations)); properties.put(LOCATION, join(",", locations));
properties.put(PRIMARY_LOCATION, primaryLocation); properties.put(PRIMARY_LOCATION, primaryLocation);
properties.put(SECONDARY_LOCATIONS, secondaryLocations); properties.put(SECONDARY_LOCATIONS, join(",", secondaryLocations));
return properties; return properties;
} }
} }