Interface UserService

  • All Known Implementing Classes:
    UserServiceImpl

    public interface UserService
    Service methods for performing operations on user accounts.
    Author:
    bdferris
    See Also:
    UserIndex, User, UserBean
    • Method Detail

      • getNumberOfUsers

        int getNumberOfUsers()
        Returns:
        the number of users in the system
      • getAllUserIds

        List<Integer> getAllUserIds()
        Returns:
        the list of all user ids
      • getAllUserIdsInRange

        List<Integer> getAllUserIdsInRange​(int offset,
                                           int limit)
        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
      • getUserForId

        User getUserForId​(int userId)
        Parameters:
        userId - see User.getId()
        Returns:
        the user with the specifed id, or null if not found
      • getNumberOfAdmins

        int getNumberOfAdmins()
        Returns:
        the number of users with the admin role set
      • getApiKeyCount

        Integer getApiKeyCount()
        Returns:
        the number (count) of Users of type=API_KEY
      • getApiKeys

        List<User> getApiKeys​(int start,
                              int maxResults)
        Returns:
        the list of Users of type=API_KEY for maxResults of users staring with 'start'
      • getUserIndexForUsername

        UserIndex getUserIndexForUsername​(String username)
        * @return the user index from the username string
      • getOrCreateUserForIndexKey

        UserIndex getOrCreateUserForIndexKey​(UserIndexKey key,
                                             String credentials,
                                             boolean isAnonymous)
        Parameters:
        key - see UserIndex.getId()
        credentials - UserIndex.getCredentials()
        isAnonymous - is a newly created user anonymous - User.getRoles()
        Returns:
        an existing user index with the specified key if it already exists, or a newly created user index (and underlying user) with the specified properties
      • getOrCreateUserForUsernameAndPassword

        UserIndex getOrCreateUserForUsernameAndPassword​(String username,
                                                        String password)
        Parameters:
        username -
        password -
        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
      • addUserIndexToUser

        UserIndex addUserIndexToUser​(User user,
                                     UserIndexKey key,
                                     String credentials)
        Add a UserIndex with the specified id and credentials to an existing user, returning the new index. If an index with the specified id already exists, it is returned instead.
        Parameters:
        user - the target user
        key - see UserIndex.getId()
        credentials - see UserIndex.getCredentials()
        Returns:
        the newly attached user index, or an existing index if already attached
      • setCredentialsForUserIndex

        void setCredentialsForUserIndex​(UserIndex userIndex,
                                        String credentials)
        Update the credentials for the specified user index
        Parameters:
        userIndex -
        credentials -
      • setPasswordForUsernameUserIndex

        void setPasswordForUsernameUserIndex​(UserIndex userIndex,
                                             String password)
        Update the password for the UserIndexTypes.USERNAME user index
        Parameters:
        userIndex -
        password -
      • getUserAsBean

        UserBean getUserAsBean​(User user)
        Parameters:
        user -
        Returns:
        the specified user as a user bean object
      • getAnonymousUser

        UserBean getAnonymousUser()
        Returns:
        an anonymous default user object
      • deleteUser

        void deleteUser​(User user)
        Delete the specified user. Will delete any UserIndex objects pointing to that user as well.
        Parameters:
        user -
      • resetUser

        void resetUser​(User user)
        Reset all properties for the specified user to default values.
        Parameters:
        user -
      • isAnonymous

        boolean isAnonymous​(User user)
        Is the specified user anonymous? See the discussion in StandardAuthoritiesService
        Parameters:
        user -
        Returns:
        true if the user is anonymous, otherwise false
      • isAdministrator

        boolean isAdministrator​(User user)
        Is the specified user an administrator? See the discussion in StandardAuthoritiesService
        Parameters:
        user -
        Returns:
        true if the user is an administrator, otherwise false
      • enableAdminRoleForUser

        void enableAdminRoleForUser​(User user,
                                    boolean onlyIfNoOtherAdmins)
        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.
        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

        void disableAdminRoleForUser​(User user,
                                     boolean onlyIfOtherAdmins)
        Remove the admin role for a User.
        Parameters:
        user -
        onlyIfOtherAdmins - when true, will only remove the admin role if at least one other user is marked as admin
      • mergeUsers

        void mergeUsers​(User sourceUser,
                        User targetUser)
        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.
        Parameters:
        sourceUser - this user will be deleted
        targetUser - this user will be updated and kept
      • startUserPropertiesMigration

        void startUserPropertiesMigration()
        Start the user property migration task - see UserPropertiesMigration
      • hasPhoneNumberRegistration

        boolean hasPhoneNumberRegistration​(UserIndexKey userIndexKey)
        Parameters:
        userIndexKey -
        Returns:
        true if a phone number registration task is pending for the specified user
      • completePhoneNumberRegistration

        UserIndex completePhoneNumberRegistration​(UserIndex userIndex,
                                                  String registrationCode)
        Complete phone number registration. If the registrationCode matches one returned in a previous call to registerPhoneNumber(User, String), then registration is completed by creating a new UserIndex with type UserIndexTypes.PHONE_NUMBER with the phone number specified in the previous call to register phone number.
        Parameters:
        userIndex -
        registrationCode -
        Returns:
        the newly created UserIndex object for the phone number user index
      • getMinApiRequestIntervalForKey

        Long getMinApiRequestIntervalForKey​(String key,
                                            boolean forceRefresh)
        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

        void deleteStaleUsers()
        Deletes stale users from the system. Stale users have a last access time of more than a month ago.
      • isDeletingStaleUsers

        boolean isDeletingStaleUsers()
        Returns:
        true if the task to delete stale users is currently running.
      • cancelDeleteStaleUsers

        void cancelDeleteStaleUsers()
        Cancel the task to delete state users (started with deleteStaleUsers()) if it is running.
      • getNumberOfStaleUsers

        long getNumberOfStaleUsers()
        Returns:
        the number of user accounts that have not been accessed in the last month