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
Fields Modifier and Type Field Description protected AclEntryPersistenceaclEntryRepositoryThe acl entry repository.static org.slf4j.LoggerLOGThe Constant LOG.protected org.springframework.security.crypto.password.PasswordEncoderpasswordEncoderThe password encoder.-
Fields inherited from interface org.genesys.blocks.security.service.BasicUserService
SYSTEM_ADMIN
-
-
Constructor Summary
Constructors Constructor Description BasicUserServiceImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()voidassureGoodPassword(String password)Test if password passes the password policy (if set).TchangePassword(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.TdeepLoad(T user)Deep load.voiddeleteUser(T user)Try to delete user.abstract List<R>getDefaultUserRoles()Get default roles assigned to users.protected abstract Set<org.springframework.security.core.GrantedAuthority>getDynamicAuthorities(T user)Allow the application to register additional authorities.TgetUser(long id)Get User by id.protected abstract org.springframework.data.jpa.repository.JpaRepository<T,Long>getUserRepository()Gets the user repository.abstract List<R>listAvailableRoles()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.TsetAccountType(T user, BasicUser.AccountType accountType)Sets the account type.protected voidsetPassword(T user, String password)Sets the password.TsetRoles(T user, Set<R> newRoles)Grant specified roles to user.TupdateUser(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, wait
-
Methods inherited from interface org.genesys.blocks.security.service.BasicUserService
createUser, getUserByEmail, updateLastLogin
-
-
-
-
Field Detail
-
LOG
public static final org.slf4j.Logger LOG
The Constant LOG.
-
passwordEncoder
@Autowired protected org.springframework.security.crypto.password.PasswordEncoder passwordEncoder
The password encoder.
-
aclEntryRepository
@Autowired(required=false) protected AclEntryPersistence aclEntryRepository
The acl entry repository.
-
-
Method Detail
-
afterPropertiesSet
@Transactional public void afterPropertiesSet() throws Exception- 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
protected abstract T createSystemAdministrator(String username) throws UserException
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
public abstract List<R> 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
public abstract List<R> 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
public T getUser(long id)
Description copied from interface:BasicUserServiceGet User by id.
-
updateUser
@Transactional @PreAuthorize("hasRole(\'ADMINISTRATOR\') || principal.id == #user.id") public T updateUser(T user, String email, String fullName) throws NotUniqueUserException, UserExceptionDescription 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
@Transactional @PreAuthorize("hasRole(\'ADMINISTRATOR\')") public void deleteUser(T user)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
@Transactional public T setRoles(T user, Set<R> newRoles)
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.PasswordPolicyExceptionDescription 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
public void assureGoodPassword(String password) throws PasswordPolicy.PasswordPolicyException
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 NoUserFoundExceptionFor 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 NoUserFoundExceptionDescription 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
@Transactional public T setAccountType(T user, BasicUser.AccountType accountType)
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
-
-