Class InMemoryUserRepository<A extends Identity,B extends User<A>>
- Type Parameters:
A- the identity typeB- the user type
- All Implemented Interfaces:
CredentialsResolver<B>,UserRepository<A,B>
A UserRepository implementation that stores users in memory.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreates an in-memory user repository with default password encoder and policy.InMemoryUserRepository(Collection<B> users) Creates an in-memory user repository initialized with the specified list of users with default password encoder and policy.InMemoryUserRepository(Collection<B> users, Password.Encoder<?, ?> passwordEncoder, PasswordPolicy<B, ?> passwordPolicy) Creates an in-memory user repository initialized with the specified list of users using the specified password encoder and policy. -
Method Summary
Modifier and TypeMethodDescriptionaddUserToGroups(String username, String... groups) Adds the user identified by the specified username to the specified groups.changePassword(LoginCredentials credentials, String rawPassword) Changes the password of the user identified by the specified credentials.createUser(B user) Creates a user.deleteUser(String username) Deletes the he user identified by the specified username from the repository.Password.Encoder<?, ?> Returns the password encoder used to encode passwords.PasswordPolicy<B, ?> Returns the password policy used to verify passwords.Returns the user identified by the specified username.Lists the users in the repository.Locks the user identified by the specified username.static <A extends Identity,B extends User<A>>
InMemoryUserRepository.Builder<A, B> of()Returns an in-memory user repository builder.static <A extends Identity,B extends User<A>>
InMemoryUserRepository.Builder<A, B> of(Collection<B> users) Returns an in-memory user repository builder initialized with the specified list of users.removeUserFromGroups(String username, String... groups) Removes the user identified by the specified username from the specified groups.Returns trusted credentials for the specified identifier.unlockUser(String username) Unlocks the user identified by the specified username.updateUser(B user) Updates the specified user.
-
Constructor Details
-
InMemoryUserRepository
public InMemoryUserRepository()Creates an in-memory user repository with default password encoder and policy.
-
InMemoryUserRepository
Creates an in-memory user repository initialized with the specified list of users with default password encoder and policy.
- Parameters:
users- a collection of users
-
InMemoryUserRepository
public InMemoryUserRepository(Collection<B> users, Password.Encoder<?, ?> passwordEncoder, PasswordPolicy<B, throws UserRepositoryException?> passwordPolicy) Creates an in-memory user repository initialized with the specified list of users using the specified password encoder and policy.
- Parameters:
users- a collection of userspasswordEncoder- the password encoderpasswordPolicy- the password policy- Throws:
UserRepositoryException
-
-
Method Details
-
of
Returns an in-memory user repository builder.
- Type Parameters:
A- the identity typeB- the user type- Returns:
- an in-memory user repository builder.
-
of
public static <A extends Identity,B extends User<A>> InMemoryUserRepository.Builder<A,B> of(Collection<B> users) Returns an in-memory user repository builder initialized with the specified list of users.
- Type Parameters:
A- the identity typeB- the user type- Parameters:
users- a collection of users- Returns:
- an in-memory user repository builder.
-
getPasswordEncoder
Returns the password encoder used to encode passwords.
- Returns:
- the password encoder
-
getPasswordPolicy
Returns the password policy used to verify passwords.
- Returns:
- the password policy
-
createUser
Description copied from interface:UserRepositoryCreates a user.
- Specified by:
createUserin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
user- the user to create- Returns:
- a mono emitting the created user
- Throws:
UserRepositoryException- if there was an error creating the user
-
updateUser
Description copied from interface:UserRepositoryUpdates the specified user.
Note that this method does not update password nor groups and can not be used to lock a user, adhoc methods
UserRepository.changePassword(io.inverno.mod.security.authentication.LoginCredentials, java.lang.String),UserRepository.addUserToGroups(java.lang.String, java.lang.String...),UserRepository.lockUser(java.lang.String)must be used instead.- Specified by:
updateUserin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
user- the user to update- Returns:
- a mono emitting the updated user
-
getUser
Description copied from interface:UserRepositoryReturns the user identified by the specified username.
- Specified by:
getUserin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
username- a username- Returns:
- a mono emitting the user or an empty mono if no user exists with the specified name
- Throws:
UserRepositoryException- if there was an error fetching the user
-
listUsers
Description copied from interface:UserRepositoryLists the users in the repository.
- Specified by:
listUsersin interfaceUserRepository<A extends Identity,B extends User<A>> - Returns:
- a publisher of users
- Throws:
UserRepositoryException- if there was an error fetching users
-
lockUser
Description copied from interface:UserRepositoryLocks the user identified by the specified username.
- Specified by:
lockUserin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
username- the name of the user to lock- Returns:
- a mono emitting the updated user
- Throws:
UserRepositoryException- if there was an error updating the user
-
unlockUser
Description copied from interface:UserRepositoryUnlocks the user identified by the specified username.
- Specified by:
unlockUserin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
username- the name of the user to unlock- Returns:
- a mono emitting the updated user
- Throws:
UserRepositoryException- if there was an error updating the user
-
changePassword
public Mono<B> changePassword(LoginCredentials credentials, String rawPassword) throws AuthenticationException, PasswordPolicyException, PasswordException, UserRepositoryException Description copied from interface:UserRepositoryChanges the password of the user identified by the specified credentials.
Implementors must make sure the provided credentials are valid before actually updating the password. Whether a full authentication is performed or a simple password match is implementation specific.
- Specified by:
changePasswordin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
credentials- the current login credentials of the user for which password must be changedrawPassword- the new raw password value- Returns:
- a mono emitting the updated user
- Throws:
AuthenticationException- if there was an error authenticating the credentialsPasswordPolicyException- if the new password is not compliant with the password policyPasswordException- if there was an error processing the new passwordUserRepositoryException- if there was an error updating the user
-
addUserToGroups
Description copied from interface:UserRepositoryAdds the user identified by the specified username to the specified groups.
- Specified by:
addUserToGroupsin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
username- a usernamegroups- a list of groups- Returns:
- a mono emitting the updated user
- Throws:
UserRepositoryException- if there was an error updating the user
-
removeUserFromGroups
public Mono<B> removeUserFromGroups(String username, String... groups) throws UserRepositoryException Description copied from interface:UserRepositoryRemoves the user identified by the specified username from the specified groups.
- Specified by:
removeUserFromGroupsin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
username- a usernamegroups- a list of groups- Returns:
- a mono emitting the updated user
- Throws:
UserRepositoryException- if there was an error updating the user
-
deleteUser
Description copied from interface:UserRepositoryDeletes the he user identified by the specified username from the repository.
- Specified by:
deleteUserin interfaceUserRepository<A extends Identity,B extends User<A>> - Parameters:
username- a username- Returns:
- a mono emitting the deleted user or an empty mono if no user exists with the specified name
- Throws:
UserRepositoryException- if there was an error deleting the user
-
resolveCredentials
Description copied from interface:CredentialsResolverReturns trusted credentials for the specified identifier.
- Specified by:
resolveCredentialsin interfaceCredentialsResolver<A extends Identity>- Parameters:
id- the identifier of the credentials to resolve- Returns:
- a mono emitting the credentials or an empty mono if no credentials exist with the specified identifier
- Throws:
SecurityException- if there was an error during the resolution of credentials
-