Skip to content

Commit

Permalink
Merge branch 'zlamalp/config' into 'main'
Browse files Browse the repository at this point in the history
fix: unified reading of list config properties

See merge request perun/perun-idm/perun-wui!278
  • Loading branch information
zlamalp committed May 3, 2024
2 parents 681e94c + eeab89d commit 3271fcf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ private static String getConfigPropertyString(String name) {

}

/**
* Return List<String> value of property from perun config or empty list. "," is expected as delimiter.
*
* @param name property name
* @return property value or empty list if anything fails
*/
private static ArrayList<String> getConfigPropertyListOfStrings(String name) {
String value = getConfigPropertyString(name);
return Utils.stringToList(value, ",");
}

/**
* Return int value of property from perun config or 0.
*
Expand Down Expand Up @@ -176,7 +187,7 @@ public static HashSet<String> getSupportedLanguages() {

ArrayList<String> languages = new ArrayList<>();
languages.add("en");
languages.addAll(Utils.stringToList(getConfigPropertyString("language.supported"),","));
languages.addAll(getConfigPropertyListOfStrings("language.supported"));
Collections.sort(languages);
return new HashSet<String>(languages);

Expand Down Expand Up @@ -407,7 +418,7 @@ public static String getReCaptchaPublicKey() {
* @return list of VOs short names
*/
public static ArrayList<String> getVosToSkipReCaptchaFor() {
return Utils.stringToList(getConfigPropertyString("reCaptcha.skipVos"),",");
return getConfigPropertyListOfStrings("reCaptcha.skipVos");
}

/**
Expand All @@ -416,7 +427,7 @@ public static ArrayList<String> getVosToSkipReCaptchaFor() {
* @return List of attribute names
*/
public static ArrayList<String> getAttributesForMemberTable() {
return Utils.stringToList(getConfigPropertyString("attributesForMemberTables"),",");
return getConfigPropertyListOfStrings("attributesForMemberTables");
}

/**
Expand All @@ -425,7 +436,7 @@ public static ArrayList<String> getAttributesForMemberTable() {
* @return List of attribute names
*/
public static ArrayList<String> getAttributesForUserTable() {
return Utils.stringToList(getConfigPropertyString("attributesForUserTables"),",");
return getConfigPropertyListOfStrings("attributesForUserTables");
}

/**
Expand All @@ -436,7 +447,7 @@ public static ArrayList<String> getAttributesForUserTable() {
* @return list of supported namespaces
*/
public static ArrayList<String> getPreferredUnixGroupNamesNamespaces() {
return Utils.stringToList(getConfigPropertyString("namespacesForPreferredGroupNames"),",");
return getConfigPropertyListOfStrings("namespacesForPreferredGroupNames");
}

/**
Expand All @@ -445,8 +456,7 @@ public static ArrayList<String> getPreferredUnixGroupNamesNamespaces() {
* @return list of supported namespaces names
*/
public static ArrayList<String> getSupportedPasswordNamespaces() {
String value = getConfigPropertyString("supportedPasswordNamespaces");
return Utils.stringToList(value, ",");
return getConfigPropertyListOfStrings("supportedPasswordNamespaces");
}

/**
Expand Down Expand Up @@ -488,8 +498,7 @@ public static String getMembersGroupName() {
* @return list of all /fed/-like authz paths
*/
public static ArrayList<String> getFedAuthz() {
String value = getConfigPropertyString("fedAuthz");
return Utils.stringToList(value, ",");
return getConfigPropertyListOfStrings("fedAuthz");
}

/**
Expand Down Expand Up @@ -525,13 +534,11 @@ public static String getPerunSpLoginUrl() {
}

public static List<String> getRegistrarEnforcedProxies() {
String value = getConfigPropertyString("registrar.enforceProxy");
return Utils.stringToList(value, ",");
return getConfigPropertyListOfStrings("registrar.enforceProxy");
}

public static List<String> getRegistrarHiddenProxies() {
String value = getConfigPropertyString("registrar.hideProxy");
return Utils.stringToList(value, ",");
return getConfigPropertyListOfStrings("registrar.hideProxy");
}

// --------------------------- WAYF ---------------------------- //
Expand All @@ -552,8 +559,7 @@ public static ArrayList<WayfGroup> getWayfGroups() {
* @return list of all cert hostnames for IC
*/
public static ArrayList<String> getWayfCertHostnames() {
String value = getConfigPropertyString("wayf.cert.hosts");
return Utils.stringToList(value, ",");
return getConfigPropertyListOfStrings("wayf.cert.hosts");
}

/**
Expand Down Expand Up @@ -666,14 +672,7 @@ public static boolean isWayfLinkAnAccountDisabled() {
* @return names of pages to hide
*/
public static List<String> getProfilePagesToHide() {
List<String> attrNames = new ArrayList<>();
String data = getConfigPropertyString("profile.hidePages");
if (data != null) {
String[] values = data.replaceAll("\\s+","").split(",");
attrNames.addAll(Arrays.asList(values));
}

return attrNames;
return getConfigPropertyListOfStrings("profile.hidePages");
}

/**
Expand All @@ -682,14 +681,8 @@ public static List<String> getProfilePagesToHide() {
* @return names of pages to hide
*/
public static List<String> getProfileSettingsPagesToHide() {
List<String> attrNames = new ArrayList<>();
String data = getConfigPropertyString("profile.settings.hidePages");
if (data != null) {
String[] values = data.replaceAll("\\s+","").split(",");
attrNames.addAll(Arrays.asList(values));
}
List<String> attrNames = getConfigPropertyListOfStrings("profile.settings.hidePages");
attrNames = attrNames.stream().map(s -> "settings_" + s).collect(Collectors.toList());

return attrNames;
}

Expand All @@ -700,14 +693,10 @@ public static List<String> getProfileSettingsPagesToHide() {
*/
public static List<PersonalAttribute> getProfilePersonalAttributesToShow() {
List<PersonalAttribute> attributes = new ArrayList<>();
String data = getConfigPropertyString("profile.personal.showAttributes");
if (data != null) {
String[] values = data.split(",");
for (String value : values) {
attributes.add(parsePersonalAttribute(value));
}
List<String> values = getConfigPropertyListOfStrings("profile.personal.showAttributes");
for (String value : values) {
attributes.add(parsePersonalAttribute(value));
}

return attributes;
}

Expand All @@ -731,13 +720,7 @@ public static boolean findSimilarUsersDisabled() {
* @return names of attributes that should be shown
*/
public static List<String> getRegistrarSkipSummaryFor() {
List<String> attributes = new ArrayList<>();
String data = getConfigPropertyString("registrar.skipSummaryFor");
if (data != null) {
String[] values = data.split(",");
attributes.addAll(Arrays.asList(values));
}
return attributes;
return getConfigPropertyListOfStrings("registrar.skipSummaryFor");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ static public <T> ArrayList<T> setToList(Set<T> set) {
}

/**
* Convert string to list
* Convert string to list. Values are trimmed of whitespace.
*
* @param toList string to convert to list
* @param delimiter
Expand All @@ -1394,7 +1394,7 @@ static public ArrayList<String> stringToList(String toList, String delimiter) {
if (toList != null && !toList.isEmpty()) {
String[] names = toList.split(delimiter);
for (int i = 0; i < names.length; i++) {
list.add(names[i]);
list.add(names[i].trim());
}
}
return list;
Expand All @@ -1404,8 +1404,8 @@ static public ArrayList<String> stringToList(String toList, String delimiter) {
* If passed string is DN of certificate(recognized by "/CN=") then returns only CN part with unescaped chars.
* If passed string is not DN of certificate, original string is returned.
*
* @param toConvert Convert DN of certificate to human readable string
* @return CN part of certificate DN in human readable form or original value.
* @param toConvert Convert DN of certificate to human-readable string
* @return CN part of certificate DN in human-readable form or original value.
*/
static public String convertCertCN(String toConvert) {

Expand Down

0 comments on commit 3271fcf

Please sign in to comment.