[Minor] Code cleanup

This commit is contained in:
Robert von Burg 2023-09-22 16:33:30 +02:00
parent bcba0264e4
commit 648553409c
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
5 changed files with 30 additions and 36 deletions

View File

@ -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);

View File

@ -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<String> relevantLdapGroups = ldapGroups.stream()
.filter(s -> this.ldapGroupNames.contains(s))
Set<String> 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

View File

@ -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!";

View File

@ -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<String, String> 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
*/

View File

@ -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);