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 type
T - 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 Details

    • passwordEncoder

      @Autowired @Lazy protected org.springframework.security.crypto.password.PasswordEncoder passwordEncoder
      The password encoder.
    • aclEntryRepository

      @Autowired(required=false) @Lazy protected AclEntryPersistence aclEntryRepository
      The acl entry repository.
  • Constructor Details

    • BasicUserServiceImpl

      public BasicUserServiceImpl()
  • Method Details

    • afterPropertiesSet

      @Transactional public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.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 type BasicUser.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: BasicUserService
      Get default roles assigned to users. These are transient and not persisted to the database.
      Specified by:
      getDefaultUserRoles in interface BasicUserService<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: BasicUserService
      List available roles.
      Specified by:
      listAvailableRoles in interface BasicUserService<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:
      loadUserByUsername in interface org.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: BasicUserService
      Get User by id.
      Specified by:
      getUser in interface BasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
      Parameters:
      id - the id
      Returns:
      the user or null
    • deepLoad

      public T deepLoad(T user)
      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: BasicUserService
      Update user information.
      Specified by:
      updateUser in interface BasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
      Parameters:
      user - the user
      email - new email address
      fullName - new fullName
      Returns:
      the updated user
      Throws:
      NotUniqueUserException - when email address is already registered
      UserException - a generic user service exception
    • deleteUser

      @Transactional @PreAuthorize("hasRole(\'ADMINISTRATOR\')") public void deleteUser(T user)
      Description copied from interface: BasicUserService
      Try to delete user.
      Specified by:
      deleteUser in interface BasicUserService<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: BasicUserService
      Grant specified roles to user. The BasicUserService.getDefaultUserRoles() will not be persisted.
      Specified by:
      setRoles in interface BasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
      Parameters:
      user - the user
      newRoles - the roles
      Returns:
      the updated user
    • changePassword

      @Transactional @PreAuthorize("hasRole(\'ADMINISTRATOR\') || principal.id == #user.id") public T changePassword(T user, String password) throws PasswordPolicy.PasswordPolicyException
      Description copied from interface: BasicUserService
      Change password.
      Specified by:
      changePassword in interface BasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
      Parameters:
      user - the user
      password - 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 user
      password - 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 NoUserFoundException
      For internal use only.
      Specified by:
      setAccountLockLocal in interface BasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
      Parameters:
      userId - the user id
      locked - 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: BasicUserService
      Sets the account lock.
      Specified by:
      setAccountLock in interface BasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
      Parameters:
      userId - the user id
      locked - the locked
      Throws:
      NoUserFoundException - the no user found exception
    • setAccountType

      @Transactional public T setAccountType(T user, BasicUser.AccountType accountType)
      Description copied from interface: BasicUserService
      Sets the account type.
      Specified by:
      setAccountType in interface BasicUserService<R extends org.springframework.security.core.GrantedAuthority,T extends BasicUser<R>>
      Parameters:
      user - the user
      accountType - the account type
      Returns:
      the t