Class RedisUserRepository<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 a Redis data store.
Users are stored as string entries serialized as JSON, the user key is of the form: keyPrefix ":USER:" username. Groups are stored as set entries, the group key is of the form:
keyPrefix ":GROUP:" group.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Constructor Summary
ConstructorsConstructorDescriptionRedisUserRepository(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper) Creates a Redis user repository with the specified Redis client and mapper.RedisUserRepository(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Password.Encoder<?, ?> passwordEncoder) Creates a Redis user repository with the specified Redis client mapper and password encoder.RedisUserRepository(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Password.Encoder<?, ?> passwordEncoder, PasswordPolicy<B, ?> passwordPolicy) Creates a Redis user repository with the specified Redis client, mapper, password encoder and password policy.RedisUserRepository(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, PasswordPolicy<B, ?> passwordPolicy) Creates a Redis user repository with the specified Redis client, mapper and password 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.final StringReturns the prefix used to format user and group entry keys.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.removeUserFromGroups(String username, String... groups) Removes the user identified by the specified username from the specified groups.Returns trusted credentials for the specified identifier.final voidsetKeyPrefix(String keyPrefix) Sets the prefix used to format user and group entry keys.unlockUser(String username) Unlocks the user identified by the specified username.updateUser(B user) Updates the specified user.
-
Constructor Details
-
RedisUserRepository
public RedisUserRepository(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper) Creates a Redis user repository with the specified Redis client and mapper.
- Parameters:
redisClient- a Redis clientmapper- an object mapper
-
RedisUserRepository
public RedisUserRepository(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, PasswordPolicy<B, ?> passwordPolicy) Creates a Redis user repository with the specified Redis client, mapper and password policy.
- Parameters:
redisClient- a Redis clientmapper- an object mapperpasswordPolicy- a password policy
-
RedisUserRepository
public RedisUserRepository(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Password.Encoder<?, ?> passwordEncoder) Creates a Redis user repository with the specified Redis client mapper and password encoder.
- Parameters:
redisClient- a Redis clientmapper- an object mapperpasswordEncoder- a password encoder
-
RedisUserRepository
public RedisUserRepository(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Password.Encoder<?, ?> passwordEncoder, PasswordPolicy<B, ?> passwordPolicy) Creates a Redis user repository with the specified Redis client, mapper, password encoder and password policy.
- Parameters:
redisClient- a Redis clientmapper- an object mapperpasswordEncoder- a password encoderpasswordPolicy- a password policy
-
-
Method Details
-
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
-
getKeyPrefix
Returns the prefix used to format user and group entry keys.
- A user key is of the form:
keyPrefix ":USER:" username. - A group key is of the form:
keyPrefix ":GROUP:" group.
- Returns:
- the key prefix
- A user key is of the form:
-
setKeyPrefix
Sets the prefix used to format user and group entry keys.
- A user key is of the form:
keyPrefix ":USER:" username. - A group key is of the form:
keyPrefix ":GROUP:" group.
- Parameters:
keyPrefix- the key prefix to set
- A user key is of the form:
-
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
- Throws:
UserRepositoryException- if there was an error updating the 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
-
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
-
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
-
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
-