Skip to content

Commit

Permalink
[Minor] Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eitch committed Sep 22, 2023
1 parent bcba026 commit 6485534
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public String getDescription(Locale locale) {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ public void initialize(ScheduledExecutorService executorService, Map<String, Str
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;
Expand Down Expand Up @@ -82,14 +81,14 @@ public void initialize(ScheduledExecutorService executorService, Map<String, Str
// 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<>();
Expand Down Expand Up @@ -133,17 +132,16 @@ protected Set<String> getLdapGroups(String username, Attributes attrs) throws Na
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;
Expand Down Expand Up @@ -194,9 +192,8 @@ protected Map<String, String> buildProperties(String username, Attributes attrs,
} 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);
}
}
Expand All @@ -210,9 +207,8 @@ protected Map<String, String> buildProperties(String username, Attributes attrs,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public void sendChallengeToUser(User user, String challenge) {

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!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ 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);

/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public void initialize(ScheduledExecutorService executorService, Map<String, Str
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);
Expand Down

0 comments on commit 6485534

Please sign in to comment.