Package org.onebusaway.users.impl
Class UserServiceImpl
- java.lang.Object
-
- org.onebusaway.users.impl.UserServiceImpl
-
- All Implemented Interfaces:
UserService
@Component public class UserServiceImpl extends Object implements UserService
-
-
Constructor Summary
Constructors Constructor Description UserServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UserIndexaddUserIndexToUser(User user, UserIndexKey key, String credentials)Add aUserIndexwith the specified id and credentials to an existing user, returning the new index.voidcancelDeleteStaleUsers()Cancel the task to delete state users (started withUserService.deleteStaleUsers()) if it is running.voidclearPhoneNumberRegistration(UserIndexKey userIndexKey)Reset a previous call toUserService.registerPhoneNumber(User, String)for the specified userUserIndexcompletePhoneNumberRegistration(UserIndex userIndex, String registrationCode)Complete phone number registration.voiddeleteStaleUsers()Deletes stale users from the system.voiddeleteStaleUsers(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).voiddeleteUser(User user)Delete the specified user.voiddisableAdminRoleForUser(User user, boolean onlyIfOtherAdmins)Remove the admin role for a User.voidenableAdminRoleForUser(User user, boolean onlyIfNoOtherAdmins)Enable the admin role for a User.List<Integer>getAllUserIds()List<Integer>getAllUserIdsInRange(int offset, int limit)UserBeangetAnonymousUser()IntegergetApiKeyCount()List<User>getApiKeys(int start, int maxResults)LonggetMinApiRequestIntervalForKey(String key, boolean forceRefresh)intgetNumberOfAdmins()longgetNumberOfStaleUsers()intgetNumberOfUsers()UserServiceInterfaceUserIndexgetOrCreateUserForIndexKey(UserIndexKey key, String credentials, boolean isAnonymous)UserIndexgetOrCreateUserForUsernameAndPassword(String username, String password)UserBeangetUserAsBean(User user)UsergetUserForId(int userId)UserIndexgetUserIndexForId(UserIndexKey key)UserIndexgetUserIndexForUsername(String username)* @return the user index from the username stringList<String>getUserIndexKeyValuesForKeyType(String keyType)UserPropertiesMigrationStatusgetUserPropertiesMigrationStatus()booleanhasPhoneNumberRegistration(UserIndexKey userIndexKey)booleanisAdministrator(User user)Is the specified user an administrator?booleanisAnonymous(User user)Is the specified user anonymous?booleanisDeletingStaleUsers()voidmergeUsers(User sourceUser, User targetUser)Given two user accounts, merge the two users into one.StringregisterPhoneNumber(User user, String phoneNumber)Begin phone number registration for the specified user.voidremoveUserIndexForUser(User user, UserIndexKey key)Remove theUserIndexwith the specified id from the user.voidresetUser(User user)Reset all properties for the specified user to default values.voidsetAuthoritiesService(StandardAuthoritiesService authoritiesService)voidsetCredentialsForUserIndex(UserIndex userIndex, String credentials)Update the credentials for the specified user indexvoidsetPasswordEncoder(VersionedPasswordEncoder passwordEncoder)voidsetPasswordForUsernameUserIndex(UserIndex userIndex, String password)Update the password for theUserIndexTypes.USERNAMEuser indexvoidsetUserDao(UserDao dao)voidsetUserIndexRegistrationService(UserIndexRegistrationService userIndexRegistrationService)voidsetUserPropertiesService(UserPropertiesService userPropertiesService)voidstart()voidstartUserPropertiesMigration()Start the user property migration task - seeUserPropertiesMigrationvoidstop()
-
-
-
Method Detail
-
setUserDao
@Autowired public void setUserDao(UserDao dao)
-
setAuthoritiesService
@Autowired public void setAuthoritiesService(StandardAuthoritiesService authoritiesService)
-
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()
UserServiceInterface- Specified by:
getNumberOfUsersin interfaceUserService- Returns:
- the number of users in the system
-
getAllUserIds
@Transactional public List<Integer> getAllUserIds()
- Specified by:
getAllUserIdsin interfaceUserService- Returns:
- the list of all user ids
-
getAllUserIdsInRange
@Transactional(readOnly=true) public List<Integer> getAllUserIdsInRange(int offset, int limit)
- Specified by:
getAllUserIdsInRangein interfaceUserService- Parameters:
offset- index offset into the full user id listlimit- 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:
getNumberOfAdminsin interfaceUserService- Returns:
- the number of users with the admin role set
-
getUserForId
@Transactional(readOnly=true) public User getUserForId(int userId)
- Specified by:
getUserForIdin interfaceUserService- Parameters:
userId- seeUser.getId()- Returns:
- the user with the specifed id, or null if not found
-
getUserAsBean
public UserBean getUserAsBean(User user)
- Specified by:
getUserAsBeanin interfaceUserService- Returns:
- the specified user as a user bean object
-
getAnonymousUser
public UserBean getAnonymousUser()
- Specified by:
getAnonymousUserin interfaceUserService- Returns:
- an anonymous default user object
-
resetUser
public void resetUser(User user)
Description copied from interface:UserServiceReset all properties for the specified user to default values.- Specified by:
resetUserin interfaceUserService
-
deleteUser
@Transactional public void deleteUser(User user)
Description copied from interface:UserServiceDelete the specified user. Will delete anyUserIndexobjects pointing to that user as well.- Specified by:
deleteUserin interfaceUserService
-
isAnonymous
public boolean isAnonymous(User user)
Description copied from interface:UserServiceIs the specified user anonymous? See the discussion inStandardAuthoritiesService- Specified by:
isAnonymousin interfaceUserService- Returns:
- true if the user is anonymous, otherwise false
-
isAdministrator
public boolean isAdministrator(User user)
Description copied from interface:UserServiceIs the specified user an administrator? See the discussion inStandardAuthoritiesService- Specified by:
isAdministratorin interfaceUserService- Returns:
- true if the user is an administrator, otherwise false
-
enableAdminRoleForUser
@Transactional public void enableAdminRoleForUser(User user, boolean onlyIfNoOtherAdmins)
Description copied from interface:UserServiceEnable 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:
enableAdminRoleForUserin interfaceUserService- Parameters:
user- the user to mark as an adminonlyIfNoOtherAdmins- 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:UserServiceRemove the admin role for a User.- Specified by:
disableAdminRoleForUserin interfaceUserServiceonlyIfOtherAdmins- when true, will only remove the admin role if at least one other user is marked as admin
-
getUserIndexKeyValuesForKeyType
@Transactional(readOnly=true) public List<String> getUserIndexKeyValuesForKeyType(String keyType)
- Specified by:
getUserIndexKeyValuesForKeyTypein interfaceUserService- Returns:
- the set of UserIndexKey values having the specified UserIndexKey type
-
getApiKeyCount
@Transactional(readOnly=true) public Integer getApiKeyCount()
- Specified by:
getApiKeyCountin interfaceUserService- Returns:
- the number (count) of Users of type=API_KEY
-
getApiKeys
@Transactional(readOnly=true) public List<User> getApiKeys(int start, int maxResults)
- Specified by:
getApiKeysin interfaceUserService- Returns:
- the list of Users of type=API_KEY for maxResults of users staring with 'start'
-
getOrCreateUserForIndexKey
@Transactional public UserIndex getOrCreateUserForIndexKey(UserIndexKey key, String credentials, boolean isAnonymous)
- Specified by:
getOrCreateUserForIndexKeyin interfaceUserService- Parameters:
key- seeUserIndex.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
@Transactional public UserIndex getOrCreateUserForUsernameAndPassword(String username, String password)
- Specified by:
getOrCreateUserForUsernameAndPasswordin interfaceUserService- 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
-
getUserIndexForId
@Transactional(readOnly=true) public UserIndex getUserIndexForId(UserIndexKey key)
- Specified by:
getUserIndexForIdin interfaceUserService- Parameters:
key- seeUserIndex.getId()- Returns:
- the user index with the specified key, or null if not found
-
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:
getUserIndexForUsernamein interfaceUserService- Throws:
org.springframework.security.core.userdetails.UsernameNotFoundException
-
addUserIndexToUser
@Transactional public UserIndex addUserIndexToUser(User user, UserIndexKey key, String credentials)
Description copied from interface:UserServiceAdd aUserIndexwith 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.- Specified by:
addUserIndexToUserin interfaceUserService- Parameters:
user- the target userkey- seeUserIndex.getId()credentials- seeUserIndex.getCredentials()- Returns:
- the newly attached user index, or an existing index if already attached
-
removeUserIndexForUser
@Transactional public void removeUserIndexForUser(User user, UserIndexKey key)
Description copied from interface:UserServiceRemove theUserIndexwith the specified id from the user.- Specified by:
removeUserIndexForUserin interfaceUserServicekey- seeUserIndex.getId()
-
setCredentialsForUserIndex
@Transactional public void setCredentialsForUserIndex(UserIndex userIndex, String credentials)
Description copied from interface:UserServiceUpdate the credentials for the specified user index- Specified by:
setCredentialsForUserIndexin interfaceUserService
-
setPasswordForUsernameUserIndex
@Transactional public void setPasswordForUsernameUserIndex(UserIndex userIndex, String password)
Description copied from interface:UserServiceUpdate the password for theUserIndexTypes.USERNAMEuser index- Specified by:
setPasswordForUsernameUserIndexin interfaceUserService
-
mergeUsers
@Transactional public void mergeUsers(User sourceUser, User targetUser)
Description copied from interface:UserServiceGiven 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:
mergeUsersin interfaceUserService- Parameters:
sourceUser- this user will be deletedtargetUser- this user will be updated and kept
-
registerPhoneNumber
public String registerPhoneNumber(User user, String phoneNumber)
Description copied from interface:UserServiceBegin phone number registration for the specified user. Returns a code that the user must specify in a call toUserService.completePhoneNumberRegistration(UserIndex, String)to verify that they do in fact own that phone number.- Specified by:
registerPhoneNumberin interfaceUserService- Returns:
- the code that must be supplied in a subsequent call to
UserService.completePhoneNumberRegistration(UserIndex, String)
-
hasPhoneNumberRegistration
public boolean hasPhoneNumberRegistration(UserIndexKey userIndexKey)
- Specified by:
hasPhoneNumberRegistrationin interfaceUserService- Returns:
- true if a phone number registration task is pending for the specified user
-
completePhoneNumberRegistration
@Transactional public UserIndex completePhoneNumberRegistration(UserIndex userIndex, String registrationCode)
Description copied from interface:UserServiceComplete phone number registration. If the registrationCode matches one returned in a previous call toUserService.registerPhoneNumber(User, String), then registration is completed by creating a newUserIndexwith typeUserIndexTypes.PHONE_NUMBERwith the phone number specified in the previous call to register phone number.- Specified by:
completePhoneNumberRegistrationin interfaceUserService- Returns:
- the newly created
UserIndexobject for the phone number user index
-
clearPhoneNumberRegistration
public void clearPhoneNumberRegistration(UserIndexKey userIndexKey)
Description copied from interface:UserServiceReset a previous call toUserService.registerPhoneNumber(User, String)for the specified user- Specified by:
clearPhoneNumberRegistrationin interfaceUserService
-
startUserPropertiesMigration
public void startUserPropertiesMigration()
Description copied from interface:UserServiceStart the user property migration task - seeUserPropertiesMigration- Specified by:
startUserPropertiesMigrationin interfaceUserService
-
getUserPropertiesMigrationStatus
public UserPropertiesMigrationStatus getUserPropertiesMigrationStatus()
Description copied from interface:UserService- Specified by:
getUserPropertiesMigrationStatusin interfaceUserService- Returns:
- the status for the user properties migration task
-
deleteStaleUsers
public void deleteStaleUsers()
Description copied from interface:UserServiceDeletes stale users from the system. Stale users have a last access time of more than a month ago.- Specified by:
deleteStaleUsersin interfaceUserService
-
isDeletingStaleUsers
public boolean isDeletingStaleUsers()
- Specified by:
isDeletingStaleUsersin interfaceUserService- Returns:
- true if the task to delete stale users is currently running.
-
cancelDeleteStaleUsers
public void cancelDeleteStaleUsers()
Description copied from interface:UserServiceCancel the task to delete state users (started withUserService.deleteStaleUsers()) if it is running.- Specified by:
cancelDeleteStaleUsersin interfaceUserService
-
getNumberOfStaleUsers
@Transactional(readOnly=true) public long getNumberOfStaleUsers()
- Specified by:
getNumberOfStaleUsersin interfaceUserService- 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:
getMinApiRequestIntervalForKeyin interfaceUserService- Parameters:
key- an API keyforceRefresh- 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-
-
-