From 648553409c755da9e5929e9807d1b4e40762844e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 22 Sep 2023 16:33:30 +0200 Subject: [PATCH] [Minor] Code cleanup --- .../handler/BasicPasswordStrengthHandler.java | 4 +- .../JsonConfigLdapPrivilegeHandler.java | 44 +++++++++---------- .../handler/MailUserChallengeHandler.java | 6 +-- .../handler/PasswordStrengthHandler.java | 9 ++-- .../handler/SimpleLdapPrivilegeHandler.java | 3 +- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/privilege/src/main/java/li/strolch/privilege/handler/BasicPasswordStrengthHandler.java b/privilege/src/main/java/li/strolch/privilege/handler/BasicPasswordStrengthHandler.java index 5a4cf4cf7..2e2bf0a13 100644 --- a/privilege/src/main/java/li/strolch/privilege/handler/BasicPasswordStrengthHandler.java +++ b/privilege/src/main/java/li/strolch/privilege/handler/BasicPasswordStrengthHandler.java @@ -37,8 +37,8 @@ public class BasicPasswordStrengthHandler implements PasswordStrengthHandler { String description; if (this.maxLength < 100) - description = MessageFormat - .format(getString(locale, "Privilege.passwordLengthBetween"), this.minLength, this.maxLength); + description = MessageFormat.format(getString(locale, "Privilege.passwordLengthBetween"), this.minLength, + this.maxLength); else description = MessageFormat.format(getString(locale, "Privilege.passwordLengthAtLeast"), this.minLength); diff --git a/privilege/src/main/java/li/strolch/privilege/handler/JsonConfigLdapPrivilegeHandler.java b/privilege/src/main/java/li/strolch/privilege/handler/JsonConfigLdapPrivilegeHandler.java index 0d3c4b842..5e9eb52fc 100644 --- a/privilege/src/main/java/li/strolch/privilege/handler/JsonConfigLdapPrivilegeHandler.java +++ b/privilege/src/main/java/li/strolch/privilege/handler/JsonConfigLdapPrivilegeHandler.java @@ -42,15 +42,14 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler { DBC.PRE.assertNotEmpty("realm must be set!", realm); this.defaultLocale = parameterMap.containsKey("defaultLocale") ? - Locale.forLanguageTag(parameterMap.get("defaultLocale")) : - Locale.getDefault(); + Locale.forLanguageTag(parameterMap.get("defaultLocale")) : Locale.getDefault(); String configFileS = parameterMap.get("configFile"); DBC.PRE.assertNotEmpty("configFile param must be set!", configFileS); File configFile = new File(configFileS); if (!configFile.exists() || !configFile.isFile() || !configFile.canRead()) - throw new IllegalStateException("configFile does not exist, is not a file, or can not be read at path " - + configFile.getAbsolutePath()); + throw new IllegalStateException("configFile does not exist, is not a file, or can not be read at path " + + configFile.getAbsolutePath()); // parse the configuration file JsonObject configJ; @@ -82,14 +81,14 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler { // validate the configuration for (String name : this.ldapGroupNames) { JsonObject config = ldapGroupConfigs.get(name).getAsJsonObject(); - if (!config.has(LOCATION) || !config.get(LOCATION).isJsonArray() - || config.get(LOCATION).getAsJsonArray().size() == 0) - throw new IllegalStateException("LDAP Group " + name - + " is missing a location attribute, or it is not an array or the array is empty"); - if (!config.has(LOCATION) || !config.get(LOCATION).isJsonArray() - || config.get(LOCATION).getAsJsonArray().size() == 0) - throw new IllegalStateException("LDAP Group " + name - + " is missing a roles attribute, or it is not an array or the array is empty"); + if (!config.has(LOCATION) || !config.get(LOCATION).isJsonArray() || + config.get(LOCATION).getAsJsonArray().isEmpty()) + throw new IllegalStateException("LDAP Group " + name + + " is missing a location attribute, or it is not an array or the array is empty"); + if (!config.has(LOCATION) || !config.get(LOCATION).isJsonArray() || + config.get(LOCATION).getAsJsonArray().isEmpty()) + throw new IllegalStateException("LDAP Group " + name + + " is missing a roles attribute, or it is not an array or the array is empty"); } this.userLdapGroupOverrides = new HashMap<>(); @@ -133,17 +132,16 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler { logger.info("Overriding LDAP group for user " + username + " to " + overrideGroup); } - Set relevantLdapGroups = ldapGroups.stream() - .filter(s -> this.ldapGroupNames.contains(s)) + Set relevantLdapGroups = ldapGroups.stream().filter(s -> this.ldapGroupNames.contains(s)) .collect(toSet()); if (relevantLdapGroups.isEmpty()) - throw new IllegalStateException("User " + username - + " can not login, as none of their LDAP Groups have mappings to Strolch Roles!"); + throw new IllegalStateException("User " + username + + " can not login, as none of their LDAP Groups have mappings to Strolch Roles!"); if (relevantLdapGroups.size() > 1) { logger.warn( - "User " + username + " has multiple relevant LDAP Groups which will lead to undefined behaviour: " - + join(",", relevantLdapGroups)); + "User " + username + " has multiple relevant LDAP Groups which will lead to undefined behaviour: " + + join(",", relevantLdapGroups)); } return relevantLdapGroups; @@ -194,9 +192,8 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler { } else { String location = primaryLocationJ.getAsString(); if (!secondaryLocations.contains(location)) { - logger.warn( - "Primary location already set by previous LDAP Group config for LDAP Group " + ldapGroup - + ", adding to secondary locations."); + logger.warn("Primary location already set by previous LDAP Group config for LDAP Group " + + ldapGroup + ", adding to secondary locations."); secondaryLocations.add(location); } } @@ -210,9 +207,8 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler { else secondaryLocationsJ.getAsJsonArray().forEach(s -> secondaryLocations.add(s.getAsString())); } else { - logger.warn( - "Secondary locations already set by previous LDAP Group config for LDAP Group " + ldapGroup - + ", adding additional"); + logger.warn("Secondary locations already set by previous LDAP Group config for LDAP Group " + + ldapGroup + ", adding additional"); if (secondaryLocationsJ.isJsonPrimitive()) secondaryLocations.add(secondaryLocationsJ.getAsString()); else diff --git a/privilege/src/main/java/li/strolch/privilege/handler/MailUserChallengeHandler.java b/privilege/src/main/java/li/strolch/privilege/handler/MailUserChallengeHandler.java index 2b3aef89e..8fa91bf89 100644 --- a/privilege/src/main/java/li/strolch/privilege/handler/MailUserChallengeHandler.java +++ b/privilege/src/main/java/li/strolch/privilege/handler/MailUserChallengeHandler.java @@ -16,9 +16,9 @@ public class MailUserChallengeHandler extends UserChallengeHandler { String subject = "Mail TAN"; - String text = "Hello " + user.getFirstname() + " " + user.getLastname() + "\n\n" - + "You have requested an action which requires you to respond to a challenge.\n\n" - + "Please use the following code to response to the challenge:\n\n" + challenge; + String text = "Hello " + user.getFirstname() + " " + user.getLastname() + "\n\n" + + "You have requested an action which requires you to respond to a challenge.\n\n" + + "Please use the following code to response to the challenge:\n\n" + challenge; String recipient = user.getEmail(); if (StringHelper.isEmpty(recipient)) { String msg = "User {0} has no property {1}, so can not initiate challenge!"; diff --git a/privilege/src/main/java/li/strolch/privilege/handler/PasswordStrengthHandler.java b/privilege/src/main/java/li/strolch/privilege/handler/PasswordStrengthHandler.java index 5ae4e146b..e5ae925df 100644 --- a/privilege/src/main/java/li/strolch/privilege/handler/PasswordStrengthHandler.java +++ b/privilege/src/main/java/li/strolch/privilege/handler/PasswordStrengthHandler.java @@ -12,8 +12,7 @@ public interface PasswordStrengthHandler { * Initialize the concrete {@link PasswordStrengthHandler}. The passed parameter map contains any configuration the * concrete {@link PasswordStrengthHandler} might need * - * @param parameterMap - * a map containing configuration properties + * @param parameterMap a map containing configuration properties */ void initialize(Map parameterMap); @@ -21,16 +20,16 @@ public interface PasswordStrengthHandler { * Returns a description what a password must contain in order to be regarded as strong for this concrete * implementation * + * @param locale the locale in which to return the description + * * @return a description of a strong password - * @param locale */ String getDescription(Locale locale); /** * Performs the validation of the given password * - * @param password - * the password to validate + * @param password the password to validate * * @return true if the password meets the criteria for a strong password */ diff --git a/privilege/src/main/java/li/strolch/privilege/handler/SimpleLdapPrivilegeHandler.java b/privilege/src/main/java/li/strolch/privilege/handler/SimpleLdapPrivilegeHandler.java index f1b4c93e5..4e335db7a 100644 --- a/privilege/src/main/java/li/strolch/privilege/handler/SimpleLdapPrivilegeHandler.java +++ b/privilege/src/main/java/li/strolch/privilege/handler/SimpleLdapPrivilegeHandler.java @@ -39,8 +39,7 @@ public class SimpleLdapPrivilegeHandler extends BaseLdapPrivilegeHandler { this.realm = parameterMap.getOrDefault(REALM, ""); this.defaultLocale = parameterMap.containsKey("defaultLocale") ? - Locale.forLanguageTag(parameterMap.get("defaultLocale")) : - Locale.getDefault(); + Locale.forLanguageTag(parameterMap.get("defaultLocale")) : Locale.getDefault(); this.adminUsers = parameterMap.get("adminUsers"); this.rolesForLdapGroups = getLdapGroupToRolesMappingFromConfig(parameterMap);