mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
Add tests for the Change Password Endpoints
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package sonia.scm.user;
|
||||
|
||||
public class ChangePasswordNotAllowedException extends RuntimeException {
|
||||
|
||||
public ChangePasswordNotAllowedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package sonia.scm.user;
|
||||
|
||||
public class InvalidPasswordException extends RuntimeException {
|
||||
|
||||
public InvalidPasswordException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,9 @@ package sonia.scm.user;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.search.Searchable;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* The central class for managing {@link User} objects.
|
||||
* This class is a singleton and is available via injection.
|
||||
@@ -68,4 +71,22 @@ public interface UserManager
|
||||
* @since 1.14
|
||||
*/
|
||||
public String getDefaultType();
|
||||
|
||||
|
||||
/**
|
||||
* Only account of the default type "xml" can change their password
|
||||
*/
|
||||
default Consumer<User> getUserTypeChecker() {
|
||||
return user -> {
|
||||
if (!isTypeDefault(user)) {
|
||||
throw new ChangePasswordNotAllowedException(MessageFormat.format("It is not possible to change password for User of type {0}", user.getType()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
default boolean isTypeDefault(User user) {
|
||||
return getDefaultType().equals(user.getType());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user