Class BasicUserServiceImpl<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
java.lang.Object
org.genesys.blocks.security.service.impl.BasicUserServiceImpl<R,T>
- Type Parameters:
R- the generic typeT- the generic type
- All Implemented Interfaces:
BasicUserService<R,,T> org.springframework.beans.factory.InitializingBean,org.springframework.security.core.userdetails.UserDetailsService
@Transactional(readOnly=true)
public abstract class BasicUserServiceImpl<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
extends Object
implements BasicUserService<R,T>, org.springframework.beans.factory.InitializingBean
The Class BasicUserServiceImpl.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AclEntryPersistenceThe acl entry repository.protected org.springframework.security.crypto.password.PasswordEncoderThe password encoder.Fields inherited from interface org.genesys.blocks.security.service.BasicUserService
SYSTEM_ADMIN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidassureGoodPassword(String password) Test if password passes the password policy (if set).changePassword(T user, String password) Change password.protected abstract TcreateSystemAdministrator(String username) Implementations must create a user with specified username with ADMINISTRATOR role and account typeBasicUser.AccountType.SYSTEM.Deep load.voiddeleteUser(T user) Try to delete user.Get default roles assigned to users.protected abstract Set<org.springframework.security.core.GrantedAuthority>getDynamicAuthorities(T user) Allow the application to register additional authorities.getUser(long id) Get User by id.Gets the user repository.List available roles.org.springframework.security.core.userdetails.UserDetailsloadUserByUsername(String username) voidsetAccountLock(long userId, boolean locked) Sets the account lock.voidsetAccountLockLocal(long userId, boolean locked) For internal use only.voidsetAccountLockoutTime(long accountLockoutTime) Sets the account lockout time.setAccountType(T user, BasicUser.AccountType accountType) Sets the account type.protected final voidsetPassword(T user, String password) Sets the password.Grant specified roles to user.updateUser(T user, String email, String fullName) Update user information.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.genesys.blocks.security.service.BasicUserService
createUser, getUserByEmail, updateLastLogin
-
Field Details
-
passwordEncoder
@Autowired @Lazy protected org.springframework.security.crypto.password.PasswordEncoder passwordEncoderThe password encoder. -
aclEntryRepository
The acl entry repository.
-
-
Constructor Details
-
BasicUserServiceImpl
public BasicUserServiceImpl()
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
getUserRepository
protected abstract org.springframework.data.jpa.repository.JpaRepository<T,Long> getUserRepository()Gets the user repository.- Returns:
- the user repository
-
createSystemAdministrator
Implementations must create a user with specified username with ADMINISTRATOR role and account typeBasicUser.AccountType.SYSTEM.- Parameters:
username- Generally SYSTEM_ADMIN- Returns:
- user instance with ADMINISTRATOR role
- Throws:
UserException- the user exception
-
setAccountLockoutTime
public void setAccountLockoutTime(long accountLockoutTime) Sets the account lockout time.- Parameters:
accountLockoutTime- the new account lockout time
-
getDefaultUserRoles
Description copied from interface:BasicUserServiceGet default roles assigned to users. These are transient and not persisted to the database.- Specified by:
getDefaultUserRolesin interfaceBasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>> - Returns:
- collection of roles assigned to all users
-
listAvailableRoles
Description copied from interface:BasicUserServiceList available roles.- Specified by:
listAvailableRolesin interfaceBasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>> - Returns:
- the list
-
loadUserByUsername
public org.springframework.security.core.userdetails.UserDetails 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
-
getDynamicAuthorities
protected abstract Set<org.springframework.security.core.GrantedAuthority> getDynamicAuthorities(T user) Allow the application to register additional authorities.- Parameters:
user- the user- Returns:
- the same object
-
getUser
Description copied from interface:BasicUserServiceGet User by id. -
deepLoad
Deep load.- Parameters:
user- the user- Returns:
- the t
-
updateUser
@Transactional @PreAuthorize("hasRole(\'ADMINISTRATOR\') || principal.id == #user.id") public T updateUser(T user, String email, String fullName) throws NotUniqueUserException, UserException Description copied from interface:BasicUserServiceUpdate user information.- Specified by:
updateUserin interfaceBasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>> - Parameters:
user- the useremail- new email addressfullName- new fullName- Returns:
- the updated user
- Throws:
NotUniqueUserException- when email address is already registeredUserException- a generic user service exception
-
deleteUser
Description copied from interface:BasicUserServiceTry to delete user.- Specified by:
deleteUserin interfaceBasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>> - Parameters:
user- user to delete
-
setRoles
Description copied from interface:BasicUserServiceGrant specified roles to user. TheBasicUserService.getDefaultUserRoles()will not be persisted. -
changePassword
@Transactional @PreAuthorize("hasRole(\'ADMINISTRATOR\') || principal.id == #user.id") public T changePassword(T user, String password) throws PasswordPolicy.PasswordPolicyException Description copied from interface:BasicUserServiceChange password.- Specified by:
changePasswordin interfaceBasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>> - Parameters:
user- the userpassword- new password- Returns:
- the updated user
- Throws:
PasswordPolicy.PasswordPolicyException- the password policy exception
-
setPassword
protected final void setPassword(T user, String password) throws PasswordPolicy.PasswordPolicyException Sets the password.- Parameters:
user- the userpassword- the password- Throws:
PasswordPolicy.PasswordPolicyException- the password policy exception
-
assureGoodPassword
Test if password passes the password policy (if set).- Parameters:
password- candidate password- Throws:
PasswordPolicy.PasswordPolicyException- if password does not match policy
-
setAccountLockLocal
@Transactional public void setAccountLockLocal(long userId, boolean locked) throws NoUserFoundException For internal use only.- Specified by:
setAccountLockLocalin interfaceBasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>> - Parameters:
userId- the user idlocked- the locked- Throws:
NoUserFoundException- the no user found exception
-
setAccountLock
@Transactional @PreAuthorize("hasRole(\'ADMINISTRATOR\')") public void setAccountLock(long userId, boolean locked) throws NoUserFoundException Description copied from interface:BasicUserServiceSets the account lock.- Specified by:
setAccountLockin interfaceBasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>> - Parameters:
userId- the user idlocked- the locked- Throws:
NoUserFoundException- the no user found exception
-
setAccountType
Description copied from interface:BasicUserServiceSets the account type.- Specified by:
setAccountTypein interfaceBasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>> - Parameters:
user- the useraccountType- the account type- Returns:
- the t
-