From 9334136c254f98d7ee315dea682080ac36980959 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 14 Mar 2023 09:18:15 +0100 Subject: [PATCH] [Fix] Allow user to retry password reset if failed password strength --- .../base/PasswordStrengthException.java | 7 +++ .../handler/DefaultPrivilegeHandler.java | 4 +- .../privilege/handler/PrivilegeHandler.java | 44 +++++++++---------- .../rest/endpoint/PrivilegeUsersService.java | 17 ++++--- .../filters/AuthenticationResponseFilter.java | 8 +++- 5 files changed, 46 insertions(+), 34 deletions(-) create mode 100644 privilege/src/main/java/li/strolch/privilege/base/PasswordStrengthException.java diff --git a/privilege/src/main/java/li/strolch/privilege/base/PasswordStrengthException.java b/privilege/src/main/java/li/strolch/privilege/base/PasswordStrengthException.java new file mode 100644 index 000000000..3e51819bf --- /dev/null +++ b/privilege/src/main/java/li/strolch/privilege/base/PasswordStrengthException.java @@ -0,0 +1,7 @@ +package li.strolch.privilege.base; + +public class PasswordStrengthException extends PrivilegeException { + public PasswordStrengthException(String string) { + super(string); + } +} diff --git a/privilege/src/main/java/li/strolch/privilege/handler/DefaultPrivilegeHandler.java b/privilege/src/main/java/li/strolch/privilege/handler/DefaultPrivilegeHandler.java index ce054812b..bb0005790 100644 --- a/privilege/src/main/java/li/strolch/privilege/handler/DefaultPrivilegeHandler.java +++ b/privilege/src/main/java/li/strolch/privilege/handler/DefaultPrivilegeHandler.java @@ -1882,9 +1882,9 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler { } @Override - public void validatePassword(Locale locale, char[] password) throws PrivilegeException { + public void validatePassword(Locale locale, char[] password) throws PasswordStrengthException { if (!this.passwordStrengthHandler.validateStrength(password)) - throw new PrivilegeException(this.passwordStrengthHandler.getDescription(locale)); + throw new PasswordStrengthException(this.passwordStrengthHandler.getDescription(locale)); } @Override diff --git a/privilege/src/main/java/li/strolch/privilege/handler/PrivilegeHandler.java b/privilege/src/main/java/li/strolch/privilege/handler/PrivilegeHandler.java index c24950fcb..2662bb620 100644 --- a/privilege/src/main/java/li/strolch/privilege/handler/PrivilegeHandler.java +++ b/privilege/src/main/java/li/strolch/privilege/handler/PrivilegeHandler.java @@ -19,10 +19,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import li.strolch.privilege.base.AccessDeniedException; -import li.strolch.privilege.base.NotAuthenticatedException; -import li.strolch.privilege.base.PrivilegeConflictResolution; -import li.strolch.privilege.base.PrivilegeException; +import li.strolch.privilege.base.*; import li.strolch.privilege.model.*; import li.strolch.privilege.model.internal.Role; import li.strolch.privilege.model.internal.User; @@ -40,8 +37,8 @@ public interface PrivilegeHandler { /// /** - * Privilege "PrivilegeAction" which is used for privileges which are not further categorized e.g. s {@link - * #PRIVILEGE_ACTION_PERSIST} and {@link #PRIVILEGE_ACTION_GET_POLICIES} + * Privilege "PrivilegeAction" which is used for privileges which are not further categorized e.g. s + * {@link #PRIVILEGE_ACTION_PERSIST} and {@link #PRIVILEGE_ACTION_GET_POLICIES} */ String PRIVILEGE_ACTION = "PrivilegeAction"; @@ -360,7 +357,7 @@ public interface PrivilegeHandler { * *

* If the password given is null, then the user is created, but can not not login! Otherwise the password must meet - * the requirements of the implementation under {@link PrivilegeHandler#validatePassword(char[])} + * the requirements of the implementation under {@link PrivilegeHandler#validatePassword(Locale, char[])} *

* * @param certificate @@ -369,7 +366,7 @@ public interface PrivilegeHandler { * the {@link UserRep} containing the information to create the new {@link User} * @param password * the password of the new user. If the password is null, then this is accepted but the user can not login, - * otherwise the password must be validated against {@link PrivilegeHandler#validatePassword(char[])} + * otherwise the password must be validated against {@link PrivilegeHandler#validatePassword(Locale, char[])} * * @throws AccessDeniedException * if the user for this certificate may not perform the action @@ -386,8 +383,6 @@ public interface PrivilegeHandler { * the {@link Certificate} of the user which has the privilege to perform this action * @param userReps * the list of users to add or update - * - * @throws PrivilegeException */ void addOrUpdateUsers(Certificate certificate, List userReps) throws PrivilegeException; @@ -397,7 +392,7 @@ public interface PrivilegeHandler { * will be updated on the existing user. The username on the given {@link UserRep} must be set and correspond to an * existing user. *

- * + *

* The following fields are considered updateable: *