Package io.jmix.securitydata.user
Class AbstractDatabaseUserRepository<T extends org.springframework.security.core.userdetails.UserDetails>
java.lang.Object
io.jmix.securitydata.user.AbstractDatabaseUserRepository<T>
- Type Parameters:
T- type of entity representing users
- All Implemented Interfaces:
UserManager,UserRepository,org.springframework.security.core.userdetails.UserDetailsService
- Direct Known Subclasses:
DatabaseUserRepository
public abstract class AbstractDatabaseUserRepository<T extends org.springframework.security.core.userdetails.UserDetails>
extends Object
implements UserRepository, UserManager
Base implementation of
UserRepository that loads users from the database.
The type of entity representing users is specified in the getUserClass() method.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassHelps create authorities from roles. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected UnconstrainedDataManagerprotected org.springframework.context.ApplicationEventPublisherprotected Metadataprotected org.springframework.security.crypto.password.PasswordEncoderprotected RoleAssignmentRepositoryprotected RoleGrantedAuthorityUtilsprotected org.springframework.security.web.authentication.rememberme.PersistentTokenRepository -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchangePassword(String userName, String oldPassword, String newPassword, boolean saveChanges) Changes the password for the specific user.protected TCreates the built-in 'anonymous' user.protected Collection<? extends org.springframework.security.core.GrantedAuthority>createAuthorities(String username) protected org.springframework.security.core.GrantedAuthoritycreateAuthority(RoleAssignment roleAssignment) protected TCreates the built-in 'system' user.Returns the built-in 'anonymous' user.getByUsernameLike(String substring) Returns the list of users whose username contains the given substring.Returns a builder that helps create authorities from roles.Returns the built-in 'system' user.Returns the class of a JPA entity representing users in the application.protected voidinitAnonymousUser(T anonymousUser) Initializes the built-in 'anonymous' user.protected voidinitSystemUser(T systemUser) Initializes the built-in 'system' user.protected booleanisUserDisabled(EntityChangedEvent<? extends org.springframework.security.core.userdetails.UserDetails> event) loadUserByUsername(String username) loadUsersByUsernameFromDatabase(String username) resetPasswords(Set<org.springframework.security.core.userdetails.UserDetails> users, boolean saveChanges) Generates new passwords for passed users.voidresetRememberMe(Collection<org.springframework.security.core.userdetails.UserDetails> users) Resets 'remember me' token for the specific user.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jmix.core.security.UserManager
changePassword, resetPasswords
-
Field Details
-
dataManager
-
metadata
-
roleAssignmentRepository
-
passwordEncoder
@Autowired protected org.springframework.security.crypto.password.PasswordEncoder passwordEncoder -
tokenRepository
@Autowired protected org.springframework.security.web.authentication.rememberme.PersistentTokenRepository tokenRepository -
eventPublisher
@Autowired protected org.springframework.context.ApplicationEventPublisher eventPublisher -
roleGrantedAuthorityUtils
-
-
Constructor Details
-
AbstractDatabaseUserRepository
public AbstractDatabaseUserRepository()
-
-
Method Details
-
getUserClass
Returns the class of a JPA entity representing users in the application. -
createSystemUser
Creates the built-in 'system' user. -
initSystemUser
Initializes the built-in 'system' user. Override in the application to grant authorities or initialize attributes. -
createAnonymousUser
Creates the built-in 'anonymous' user. -
initAnonymousUser
Initializes the built-in 'anonymous' user. Override in the application to grant authorities or initialize attributes. -
getSystemUser
Description copied from interface:UserRepositoryReturns the built-in 'system' user.- Specified by:
getSystemUserin interfaceUserRepository
-
getAnonymousUser
Description copied from interface:UserRepositoryReturns the built-in 'anonymous' user.- Specified by:
getAnonymousUserin interfaceUserRepository
-
getByUsernameLike
Description copied from interface:UserRepositoryReturns the list of users whose username contains the given substring.- Specified by:
getByUsernameLikein interfaceUserRepository
-
loadUserByUsername
public T loadUserByUsername(String username) throws org.springframework.security.core.userdetails.UsernameNotFoundException - Specified by:
loadUserByUsernamein interfaceorg.springframework.security.core.userdetails.UserDetailsService- Throws:
org.springframework.security.core.userdetails.UsernameNotFoundException
-
loadUsersByUsernameFromDatabase
-
changePassword
public T changePassword(String userName, @Nullable String oldPassword, @Nullable String newPassword, boolean saveChanges) throws PasswordNotMatchException Description copied from interface:UserManagerChanges the password for the specific user.- Specified by:
changePasswordin interfaceUserManager- Parameters:
userName- users loginoldPassword- non-encoded old user passwordnewPassword- non-encoded new user passwordsaveChanges- whether to save changes to the database- Throws:
PasswordNotMatchException- if the oldPassword is notnulland the oldPassword does not equal to the current password or if the oldPassword isnulland the newPassword does equal the current password
-
resetPasswords
public Map<org.springframework.security.core.userdetails.UserDetails,String> resetPasswords(Set<org.springframework.security.core.userdetails.UserDetails> users, boolean saveChanges) Description copied from interface:UserManagerGenerates new passwords for passed users.- Specified by:
resetPasswordsin interfaceUserManager- Parameters:
users- users which need reset passwordssaveChanges- whether to save changes to the database- Returns:
- map which contains new passwords for the passed users
-
resetRememberMe
public void resetRememberMe(Collection<org.springframework.security.core.userdetails.UserDetails> users) Description copied from interface:UserManagerResets 'remember me' token for the specific user.- Specified by:
resetRememberMein interfaceUserManager- Parameters:
users- - users which need reset 'remember me' token
-
createAuthorities
protected Collection<? extends org.springframework.security.core.GrantedAuthority> createAuthorities(String username) -
createAuthority
@Nullable protected org.springframework.security.core.GrantedAuthority createAuthority(RoleAssignment roleAssignment) -
getGrantedAuthoritiesBuilder
protected AbstractDatabaseUserRepository<T>.GrantedAuthoritiesBuilder getGrantedAuthoritiesBuilder()Returns a builder that helps create authorities from roles. -
isUserDisabled
protected boolean isUserDisabled(EntityChangedEvent<? extends org.springframework.security.core.userdetails.UserDetails> event)
-