Module one.jpro.platform.auth.core
Class InMemoryUserManager
java.lang.Object
one.jpro.platform.auth.core.basic.InMemoryUserManager
- All Implemented Interfaces:
UserManager
Non-persistent implementation of
UserDetailsManager which is backed
by an in-memory map.
Mainly intended for testing and demonstration purposes, where a persistent system isn't required.
-
Constructor Summary
ConstructorsConstructorDescriptionInMemoryUserManager(@NotNull Collection<User> users) InMemoryUserManager(User... users) -
Method Summary
Modifier and TypeMethodDescriptionchangePassword(@NotNull String username, @NotNull String newPassword) Changes the password of an existing user.createUser(@NotNull UsernamePasswordCredentials credentials, @Nullable Set<String> roles, @Nullable Map<String, Object> attributes) Creates a new user with the specified credentials.deleteUser(@Nullable String username) Deletes a user with the specified username.loadUserByUsername(@NotNull String username) Locates the user based on the username.updateUser(@NotNull String username, @Nullable Set<String> roles, @Nullable Map<String, Object> attributes) Updates an existing user identified by the username.booleanuserExists(@Nullable String username) Checks if a user exists with the specified username.
-
Constructor Details
-
InMemoryUserManager
public InMemoryUserManager() -
InMemoryUserManager
-
InMemoryUserManager
-
-
Method Details
-
createUser
public CompletableFuture<User> createUser(@NotNull @NotNull UsernamePasswordCredentials credentials, @Nullable @Nullable Set<String> roles, @Nullable @Nullable Map<String, Object> attributes) throws CredentialValidationExceptionDescription copied from interface:UserManagerCreates a new user with the specified credentials. The method allows specifying roles and additional attributes for the user.- Specified by:
createUserin interfaceUserManager- Parameters:
credentials- the credentials for the new user, typically containing a username and passwordroles- an optional set of roles to assign to the userattributes- an optional map of additional attributes to associate with the user- Returns:
- a
CompletableFuturethat, upon completion, returns the createdUserobject. - Throws:
CredentialValidationException- if the provided credentials do not meet the required validation criteria.
-
updateUser
public CompletableFuture<User> updateUser(@NotNull @NotNull String username, @Nullable @Nullable Set<String> roles, @Nullable @Nullable Map<String, Object> attributes) throws UserNotFoundException, CredentialValidationExceptionDescription copied from interface:UserManagerUpdates an existing user identified by the username. This method allows updating the user's roles and additional attributes.- Specified by:
updateUserin interfaceUserManager- Parameters:
username- the username of the user to be updatedroles- an optional new set of roles for the userattributes- an optional map of new or updated attributes for the user- Returns:
- a
CompletableFuturethat, when completed, returns the updatedUserobject. - Throws:
UserNotFoundException- if no user exists with the given usernameCredentialValidationException- if any provided credentials are invalid
-
deleteUser
Description copied from interface:UserManagerDeletes a user with the specified username.- Specified by:
deleteUserin interfaceUserManager- Parameters:
username- the username of the user to be deleted.- Returns:
- a
CompletableFuturethat, when completed, returns the deletedUser
-
changePassword
public CompletableFuture<User> changePassword(@NotNull @NotNull String username, @NotNull @NotNull String newPassword) throws UserNotFoundException, CredentialValidationException Description copied from interface:UserManagerChanges the password of an existing user.- Specified by:
changePasswordin interfaceUserManager- Parameters:
username- the username of the user whose password is to be changednewPassword- the new password for the user- Returns:
- a
CompletableFuturethat, when completed, returns the user with the updated password - Throws:
UserNotFoundException- if no user exists with the given usernameCredentialValidationException- if the new password does not meet the required validation criteria
-
userExists
Description copied from interface:UserManagerChecks if a user exists with the specified username.- Specified by:
userExistsin interfaceUserManager- Parameters:
username- The username to check for existence.- Returns:
trueif the user exists,falseotherwise.
-
loadUserByUsername
public CompletableFuture<User> loadUserByUsername(@NotNull @NotNull String username) throws UserNotFoundException Description copied from interface:UserManagerLocates the user based on the username.- Specified by:
loadUserByUsernamein interfaceUserManager- Parameters:
username- the username identifying the user whose data is required- Returns:
- a fully populated user record (never
null) - Throws:
UserNotFoundException- if the user could not be found
-