[Minor] Code cleanup
This commit is contained in:
parent
bcba0264e4
commit
648553409c
|
@ -37,8 +37,8 @@ public class BasicPasswordStrengthHandler implements PasswordStrengthHandler {
|
||||||
String description;
|
String description;
|
||||||
|
|
||||||
if (this.maxLength < 100)
|
if (this.maxLength < 100)
|
||||||
description = MessageFormat
|
description = MessageFormat.format(getString(locale, "Privilege.passwordLengthBetween"), this.minLength,
|
||||||
.format(getString(locale, "Privilege.passwordLengthBetween"), this.minLength, this.maxLength);
|
this.maxLength);
|
||||||
else
|
else
|
||||||
description = MessageFormat.format(getString(locale, "Privilege.passwordLengthAtLeast"), this.minLength);
|
description = MessageFormat.format(getString(locale, "Privilege.passwordLengthAtLeast"), this.minLength);
|
||||||
|
|
||||||
|
|
|
@ -42,15 +42,14 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
|
||||||
DBC.PRE.assertNotEmpty("realm must be set!", realm);
|
DBC.PRE.assertNotEmpty("realm must be set!", realm);
|
||||||
|
|
||||||
this.defaultLocale = parameterMap.containsKey("defaultLocale") ?
|
this.defaultLocale = parameterMap.containsKey("defaultLocale") ?
|
||||||
Locale.forLanguageTag(parameterMap.get("defaultLocale")) :
|
Locale.forLanguageTag(parameterMap.get("defaultLocale")) : Locale.getDefault();
|
||||||
Locale.getDefault();
|
|
||||||
|
|
||||||
String configFileS = parameterMap.get("configFile");
|
String configFileS = parameterMap.get("configFile");
|
||||||
DBC.PRE.assertNotEmpty("configFile param must be set!", configFileS);
|
DBC.PRE.assertNotEmpty("configFile param must be set!", configFileS);
|
||||||
File configFile = new File(configFileS);
|
File configFile = new File(configFileS);
|
||||||
if (!configFile.exists() || !configFile.isFile() || !configFile.canRead())
|
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 "
|
throw new IllegalStateException("configFile does not exist, is not a file, or can not be read at path " +
|
||||||
+ configFile.getAbsolutePath());
|
configFile.getAbsolutePath());
|
||||||
|
|
||||||
// parse the configuration file
|
// parse the configuration file
|
||||||
JsonObject configJ;
|
JsonObject configJ;
|
||||||
|
@ -82,14 +81,14 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
|
||||||
// validate the configuration
|
// validate the configuration
|
||||||
for (String name : this.ldapGroupNames) {
|
for (String name : this.ldapGroupNames) {
|
||||||
JsonObject config = ldapGroupConfigs.get(name).getAsJsonObject();
|
JsonObject config = ldapGroupConfigs.get(name).getAsJsonObject();
|
||||||
if (!config.has(LOCATION) || !config.get(LOCATION).isJsonArray()
|
if (!config.has(LOCATION) || !config.get(LOCATION).isJsonArray() ||
|
||||||
|| config.get(LOCATION).getAsJsonArray().size() == 0)
|
config.get(LOCATION).getAsJsonArray().isEmpty())
|
||||||
throw new IllegalStateException("LDAP Group " + name
|
throw new IllegalStateException("LDAP Group " + name +
|
||||||
+ " is missing a location attribute, or it is not an array or the array is empty");
|
" is missing a location attribute, or it is not an array or the array is empty");
|
||||||
if (!config.has(LOCATION) || !config.get(LOCATION).isJsonArray()
|
if (!config.has(LOCATION) || !config.get(LOCATION).isJsonArray() ||
|
||||||
|| config.get(LOCATION).getAsJsonArray().size() == 0)
|
config.get(LOCATION).getAsJsonArray().isEmpty())
|
||||||
throw new IllegalStateException("LDAP Group " + name
|
throw new IllegalStateException("LDAP Group " + name +
|
||||||
+ " is missing a roles attribute, or it is not an array or the array is empty");
|
" is missing a roles attribute, or it is not an array or the array is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userLdapGroupOverrides = new HashMap<>();
|
this.userLdapGroupOverrides = new HashMap<>();
|
||||||
|
@ -133,17 +132,16 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
|
||||||
logger.info("Overriding LDAP group for user " + username + " to " + overrideGroup);
|
logger.info("Overriding LDAP group for user " + username + " to " + overrideGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> relevantLdapGroups = ldapGroups.stream()
|
Set<String> relevantLdapGroups = ldapGroups.stream().filter(s -> this.ldapGroupNames.contains(s))
|
||||||
.filter(s -> this.ldapGroupNames.contains(s))
|
|
||||||
.collect(toSet());
|
.collect(toSet());
|
||||||
if (relevantLdapGroups.isEmpty())
|
if (relevantLdapGroups.isEmpty())
|
||||||
throw new IllegalStateException("User " + username
|
throw new IllegalStateException("User " + username +
|
||||||
+ " can not login, as none of their LDAP Groups have mappings to Strolch Roles!");
|
" can not login, as none of their LDAP Groups have mappings to Strolch Roles!");
|
||||||
|
|
||||||
if (relevantLdapGroups.size() > 1) {
|
if (relevantLdapGroups.size() > 1) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"User " + username + " has multiple relevant LDAP Groups which will lead to undefined behaviour: "
|
"User " + username + " has multiple relevant LDAP Groups which will lead to undefined behaviour: " +
|
||||||
+ join(",", relevantLdapGroups));
|
join(",", relevantLdapGroups));
|
||||||
}
|
}
|
||||||
|
|
||||||
return relevantLdapGroups;
|
return relevantLdapGroups;
|
||||||
|
@ -194,9 +192,8 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
|
||||||
} else {
|
} else {
|
||||||
String location = primaryLocationJ.getAsString();
|
String location = primaryLocationJ.getAsString();
|
||||||
if (!secondaryLocations.contains(location)) {
|
if (!secondaryLocations.contains(location)) {
|
||||||
logger.warn(
|
logger.warn("Primary location already set by previous LDAP Group config for LDAP Group " +
|
||||||
"Primary location already set by previous LDAP Group config for LDAP Group " + ldapGroup
|
ldapGroup + ", adding to secondary locations.");
|
||||||
+ ", adding to secondary locations.");
|
|
||||||
secondaryLocations.add(location);
|
secondaryLocations.add(location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,9 +207,8 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
|
||||||
else
|
else
|
||||||
secondaryLocationsJ.getAsJsonArray().forEach(s -> secondaryLocations.add(s.getAsString()));
|
secondaryLocationsJ.getAsJsonArray().forEach(s -> secondaryLocations.add(s.getAsString()));
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
logger.warn("Secondary locations already set by previous LDAP Group config for LDAP Group " +
|
||||||
"Secondary locations already set by previous LDAP Group config for LDAP Group " + ldapGroup
|
ldapGroup + ", adding additional");
|
||||||
+ ", adding additional");
|
|
||||||
if (secondaryLocationsJ.isJsonPrimitive())
|
if (secondaryLocationsJ.isJsonPrimitive())
|
||||||
secondaryLocations.add(secondaryLocationsJ.getAsString());
|
secondaryLocations.add(secondaryLocationsJ.getAsString());
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,9 +16,9 @@ public class MailUserChallengeHandler extends UserChallengeHandler {
|
||||||
|
|
||||||
String subject = "Mail TAN";
|
String subject = "Mail TAN";
|
||||||
|
|
||||||
String text = "Hello " + user.getFirstname() + " " + user.getLastname() + "\n\n"
|
String text = "Hello " + user.getFirstname() + " " + user.getLastname() + "\n\n" +
|
||||||
+ "You have requested an action which requires you to respond to a challenge.\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;
|
"Please use the following code to response to the challenge:\n\n" + challenge;
|
||||||
String recipient = user.getEmail();
|
String recipient = user.getEmail();
|
||||||
if (StringHelper.isEmpty(recipient)) {
|
if (StringHelper.isEmpty(recipient)) {
|
||||||
String msg = "User {0} has no property {1}, so can not initiate challenge!";
|
String msg = "User {0} has no property {1}, so can not initiate challenge!";
|
||||||
|
|
|
@ -12,8 +12,7 @@ public interface PasswordStrengthHandler {
|
||||||
* Initialize the concrete {@link PasswordStrengthHandler}. The passed parameter map contains any configuration the
|
* Initialize the concrete {@link PasswordStrengthHandler}. The passed parameter map contains any configuration the
|
||||||
* concrete {@link PasswordStrengthHandler} might need
|
* concrete {@link PasswordStrengthHandler} might need
|
||||||
*
|
*
|
||||||
* @param parameterMap
|
* @param parameterMap a map containing configuration properties
|
||||||
* a map containing configuration properties
|
|
||||||
*/
|
*/
|
||||||
void initialize(Map<String, String> parameterMap);
|
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
|
* Returns a description what a password must contain in order to be regarded as strong for this concrete
|
||||||
* implementation
|
* implementation
|
||||||
*
|
*
|
||||||
|
* @param locale the locale in which to return the description
|
||||||
|
*
|
||||||
* @return a description of a strong password
|
* @return a description of a strong password
|
||||||
* @param locale
|
|
||||||
*/
|
*/
|
||||||
String getDescription(Locale locale);
|
String getDescription(Locale locale);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the validation of the given password
|
* Performs the validation of the given password
|
||||||
*
|
*
|
||||||
* @param password
|
* @param password the password to validate
|
||||||
* the password to validate
|
|
||||||
*
|
*
|
||||||
* @return true if the password meets the criteria for a strong password
|
* @return true if the password meets the criteria for a strong password
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -39,8 +39,7 @@ public class SimpleLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
|
||||||
this.realm = parameterMap.getOrDefault(REALM, "");
|
this.realm = parameterMap.getOrDefault(REALM, "");
|
||||||
|
|
||||||
this.defaultLocale = parameterMap.containsKey("defaultLocale") ?
|
this.defaultLocale = parameterMap.containsKey("defaultLocale") ?
|
||||||
Locale.forLanguageTag(parameterMap.get("defaultLocale")) :
|
Locale.forLanguageTag(parameterMap.get("defaultLocale")) : Locale.getDefault();
|
||||||
Locale.getDefault();
|
|
||||||
|
|
||||||
this.adminUsers = parameterMap.get("adminUsers");
|
this.adminUsers = parameterMap.get("adminUsers");
|
||||||
this.rolesForLdapGroups = getLdapGroupToRolesMappingFromConfig(parameterMap);
|
this.rolesForLdapGroups = getLdapGroupToRolesMappingFromConfig(parameterMap);
|
||||||
|
|
Loading…
Reference in New Issue