Class UserServiceImpl

    • Constructor Detail

      • UserServiceImpl

        public UserServiceImpl()
    • Method Detail

      • setUserDao

        @Autowired
        public void setUserDao​(UserDao dao)
      • setUserPropertiesService

        @Autowired
        public void setUserPropertiesService​(UserPropertiesService userPropertiesService)
      • setUserIndexRegistrationService

        @Autowired
        public void setUserIndexRegistrationService​(UserIndexRegistrationService userIndexRegistrationService)
      • setPasswordEncoder

        @Autowired
        @Qualifier("passwordEncoderV1")
        public void setPasswordEncoder​(VersionedPasswordEncoder passwordEncoder)
      • start

        @PostConstruct
        public void start()
      • stop

        @PreDestroy
        public void stop()
      • getNumberOfUsers

        @Transactional(readOnly=true)
        public int getNumberOfUsers()
        UserService Interface
        Specified by:
        getNumberOfUsers in interface UserService
        Returns:
        the number of users in the system
      • getAllUserIdsInRange

        @Transactional(readOnly=true)
        public List<Integer> getAllUserIdsInRange​(int offset,
                                                  int limit)
        Specified by:
        getAllUserIdsInRange in interface UserService
        Parameters:
        offset - index offset into the full user id list
        limit - length of subset of the user id list to return
        Returns:
        a subset of the list of all user ids in the system
      • getNumberOfAdmins

        @Transactional(readOnly=true)
        public int getNumberOfAdmins()
        Specified by:
        getNumberOfAdmins in interface UserService
        Returns:
        the number of users with the admin role set
      • getUserForId

        @Transactional(readOnly=true)
        public User getUserForId​(int userId)
        Specified by:
        getUserForId in interface UserService
        Parameters:
        userId - see User.getId()
        Returns:
        the user with the specifed id, or null if not found
      • resetUser

        public void resetUser​(User user)
        Description copied from interface: UserService
        Reset all properties for the specified user to default values.
        Specified by:
        resetUser in interface UserService
      • deleteUser

        @Transactional
        public void deleteUser​(User user)
        Description copied from interface: UserService
        Delete the specified user. Will delete any UserIndex objects pointing to that user as well.
        Specified by:
        deleteUser in interface UserService
      • enableAdminRoleForUser

        @Transactional
        public void enableAdminRoleForUser​(User user,
                                           boolean onlyIfNoOtherAdmins)
        Description copied from interface: UserService
        Enable the admin role for a User. For admin bootstrapping, we have a check that will only allow you to set an admin role if no other admins exist. This would be useful for marking the very first user in a system as admin.
        Specified by:
        enableAdminRoleForUser in interface UserService
        Parameters:
        user - the user to mark as an admin
        onlyIfNoOtherAdmins - when true, will only add the admin role if no other users are marked as admin
      • disableAdminRoleForUser

        @Transactional
        public void disableAdminRoleForUser​(User user,
                                            boolean onlyIfOtherAdmins)
        Description copied from interface: UserService
        Remove the admin role for a User.
        Specified by:
        disableAdminRoleForUser in interface UserService
        onlyIfOtherAdmins - when true, will only remove the admin role if at least one other user is marked as admin
      • getApiKeyCount

        @Transactional(readOnly=true)
        public Integer getApiKeyCount()
        Specified by:
        getApiKeyCount in interface UserService
        Returns:
        the number (count) of Users of type=API_KEY
      • getApiKeys

        @Transactional(readOnly=true)
        public List<User> getApiKeys​(int start,
                                     int maxResults)
        Specified by:
        getApiKeys in interface UserService
        Returns:
        the list of Users of type=API_KEY for maxResults of users staring with 'start'
      • getOrCreateUserForUsernameAndPassword

        @Transactional
        public UserIndex getOrCreateUserForUsernameAndPassword​(String username,
                                                               String password)
        Specified by:
        getOrCreateUserForUsernameAndPassword in interface UserService
        Returns:
        an existing user index with the specified username if it already exists, or a newly created user index (and underlying user) with the specified username and password credentials
      • getUserIndexForUsername

        public UserIndex getUserIndexForUsername​(String username)
                                          throws org.springframework.security.core.userdetails.UsernameNotFoundException
        Description copied from interface: UserService
        * @return the user index from the username string
        Specified by:
        getUserIndexForUsername in interface UserService
        Throws:
        org.springframework.security.core.userdetails.UsernameNotFoundException
      • mergeUsers

        @Transactional
        public void mergeUsers​(User sourceUser,
                               User targetUser)
        Description copied from interface: UserService
        Given two user accounts, merge the two users into one. The source user is deleted while the target user is updated. Properties in the target user take presedence over properties in the source user if there is overlap.
        Specified by:
        mergeUsers in interface UserService
        Parameters:
        sourceUser - this user will be deleted
        targetUser - this user will be updated and kept
      • hasPhoneNumberRegistration

        public boolean hasPhoneNumberRegistration​(UserIndexKey userIndexKey)
        Specified by:
        hasPhoneNumberRegistration in interface UserService
        Returns:
        true if a phone number registration task is pending for the specified user
      • deleteStaleUsers

        public void deleteStaleUsers()
        Description copied from interface: UserService
        Deletes stale users from the system. Stale users have a last access time of more than a month ago.
        Specified by:
        deleteStaleUsers in interface UserService
      • isDeletingStaleUsers

        public boolean isDeletingStaleUsers()
        Specified by:
        isDeletingStaleUsers in interface UserService
        Returns:
        true if the task to delete stale users is currently running.
      • getNumberOfStaleUsers

        @Transactional(readOnly=true)
        public long getNumberOfStaleUsers()
        Specified by:
        getNumberOfStaleUsers in interface UserService
        Returns:
        the number of user accounts that have not been accessed in the last month
      • getMinApiRequestIntervalForKey

        @Transactional
        public Long getMinApiRequestIntervalForKey​(String key,
                                                   boolean forceRefresh)
        Specified by:
        getMinApiRequestIntervalForKey in interface UserService
        Parameters:
        key - an API key
        forceRefresh - guarantees that supplied value has not been cached
        Returns:
        the minimum interval between requests in milliseconds for the key, or null for a key with no permission to access the API
      • deleteStaleUsers

        @Transactional
        public void deleteStaleUsers​(Date lastAccessTime)
        Unfortunately, deleting a user is a somewhat complex operation, so we can do it in bulk (TODO: maybe someone can figure out a clever cascading bulk delete that plays well with all the caches / etc).
        Parameters:
        lastAccessTime -