Class InMemoryUserManager

java.lang.Object
one.jpro.platform.auth.core.basic.InMemoryUserManager
All Implemented Interfaces:
UserManager

public class InMemoryUserManager extends Object implements 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 Details

    • InMemoryUserManager

      public InMemoryUserManager()
    • InMemoryUserManager

      public InMemoryUserManager(@NotNull @NotNull Collection<User> users)
    • InMemoryUserManager

      public InMemoryUserManager(User... users)
  • Method Details

    • createUser

      public CompletableFuture<User> createUser(@NotNull @NotNull UsernamePasswordCredentials credentials, @Nullable @Nullable Set<String> roles, @Nullable @Nullable Map<String,Object> attributes) throws CredentialValidationException
      Description copied from interface: UserManager
      Creates a new user with the specified credentials. The method allows specifying roles and additional attributes for the user.
      Specified by:
      createUser in interface UserManager
      Parameters:
      credentials - the credentials for the new user, typically containing a username and password
      roles - an optional set of roles to assign to the user
      attributes - an optional map of additional attributes to associate with the user
      Returns:
      a CompletableFuture that, upon completion, returns the created User object.
      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, CredentialValidationException
      Description copied from interface: UserManager
      Updates an existing user identified by the username. This method allows updating the user's roles and additional attributes.
      Specified by:
      updateUser in interface UserManager
      Parameters:
      username - the username of the user to be updated
      roles - an optional new set of roles for the user
      attributes - an optional map of new or updated attributes for the user
      Returns:
      a CompletableFuture that, when completed, returns the updated User object.
      Throws:
      UserNotFoundException - if no user exists with the given username
      CredentialValidationException - if any provided credentials are invalid
    • deleteUser

      public CompletableFuture<User> deleteUser(@Nullable @Nullable String username)
      Description copied from interface: UserManager
      Deletes a user with the specified username.
      Specified by:
      deleteUser in interface UserManager
      Parameters:
      username - the username of the user to be deleted.
      Returns:
      a CompletableFuture that, when completed, returns the deleted User
    • changePassword

      public CompletableFuture<User> changePassword(@NotNull @NotNull String username, @NotNull @NotNull String newPassword) throws UserNotFoundException, CredentialValidationException
      Description copied from interface: UserManager
      Changes the password of an existing user.
      Specified by:
      changePassword in interface UserManager
      Parameters:
      username - the username of the user whose password is to be changed
      newPassword - the new password for the user
      Returns:
      a CompletableFuture that, when completed, returns the user with the updated password
      Throws:
      UserNotFoundException - if no user exists with the given username
      CredentialValidationException - if the new password does not meet the required validation criteria
    • userExists

      public boolean userExists(@Nullable @Nullable String username)
      Description copied from interface: UserManager
      Checks if a user exists with the specified username.
      Specified by:
      userExists in interface UserManager
      Parameters:
      username - The username to check for existence.
      Returns:
      true if the user exists, false otherwise.
    • loadUserByUsername

      public CompletableFuture<User> loadUserByUsername(@NotNull @NotNull String username) throws UserNotFoundException
      Description copied from interface: UserManager
      Locates the user based on the username.
      Specified by:
      loadUserByUsername in interface UserManager
      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