org.onebusaway.users.impl
Class UserServiceImpl

java.lang.Object
  extended by org.onebusaway.users.impl.UserServiceImpl
All Implemented Interfaces:
UserService

@Component
public class UserServiceImpl
extends Object
implements UserService


Constructor Summary
UserServiceImpl()
           
 
Method Summary
 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.
 void clearPhoneNumberRegistration(UserIndexKey userIndexKey)
          Reset a previous call to UserService.registerPhoneNumber(User, String) for the specified user
 UserIndex completePhoneNumberRegistration(UserIndex userIndex, String registrationCode)
          Complete phone number registration.
 void deleteStaleUsers()
          Deletes stale users from the system.
 void deleteUser(User user)
          Delete the specified user.
 void disableAdminRoleForUser(User user, boolean onlyIfOtherAdmins)
          Remove the admin role for a User.
 void enableAdminRoleForUser(User user, boolean onlyIfNoOtherAdmins)
          Enable the admin role for a User.
 List<Integer> getAllUserIds()
           
 List<Integer> getAllUserIdsInRange(int offset, int limit)
           
 UserBean getAnonymousUser()
           
 Long getMinApiRequestIntervalForKey(String key, boolean forceRefresh)
           
 int getNumberOfAdmins()
           
 int getNumberOfUsers()
          UserService Interface
 UserIndex getOrCreateUserForIndexKey(UserIndexKey key, String credentials, boolean isAnonymous)
           
 UserIndex getOrCreateUserForUsernameAndPassword(String username, String password)
           
 UserBean getUserAsBean(User user)
           
 User getUserForId(int userId)
           
 UserIndex getUserIndexForId(UserIndexKey key)
           
 List<String> getUserIndexKeyValuesForKeyType(String keyType)
           
 UserPropertiesMigrationStatus getUserPropertiesMigrationStatus()
          See UserPropertiesMigration
 boolean hasPhoneNumberRegistration(UserIndexKey userIndexKey)
           
 boolean isAdministrator(User user)
          Is the specified user an administrator? See the discussion in StandardAuthoritiesService
 boolean isAnonymous(User user)
          Is the specified user anonymous? See the discussion in StandardAuthoritiesService
 void mergeUsers(User sourceUser, User targetUser)
          Given two user accounts, merge the two users into one.
 String registerPhoneNumber(User user, String phoneNumber)
          Begin phone number registration for the specified user.
 void removeUserIndexForUser(User user, UserIndexKey key)
          Remove the UserIndex with the specified id from the user.
 void resetUser(User user)
          Reset all properties for the specified user to default values.
 void setAuthoritiesService(StandardAuthoritiesService authoritiesService)
           
 void setCredentialsForUserIndex(UserIndex userIndex, String credentials)
          Update the credentials for the specified user index
 void setPasswordEncoder(org.springframework.security.providers.encoding.PasswordEncoder passwordEncoder)
           
 void setPasswordForUsernameUserIndex(UserIndex userIndex, String password)
          Update the password for the UserIndexTypes.USERNAME user index
 void setUserDao(UserDao dao)
           
 void setUserIndexRegistrationService(UserIndexRegistrationService userIndexRegistrationService)
           
 void setUserPropertiesService(UserPropertiesService userPropertiesService)
           
 void start()
           
 void startUserPropertiesMigration()
          Start the user property migration task - see UserPropertiesMigration
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserServiceImpl

public UserServiceImpl()
Method Detail

setUserDao

public void setUserDao(UserDao dao)

setAuthoritiesService

public void setAuthoritiesService(StandardAuthoritiesService authoritiesService)

setUserPropertiesService

public void setUserPropertiesService(UserPropertiesService userPropertiesService)

setUserIndexRegistrationService

public void setUserIndexRegistrationService(UserIndexRegistrationService userIndexRegistrationService)

setPasswordEncoder

public void setPasswordEncoder(org.springframework.security.providers.encoding.PasswordEncoder passwordEncoder)

start

@PostConstruct
public void start()

stop

@PreDestroy
public void stop()

getNumberOfUsers

public int getNumberOfUsers()
UserService Interface

Specified by:
getNumberOfUsers in interface UserService
Returns:
the number of users in the system

getAllUserIds

public List<Integer> getAllUserIds()
Specified by:
getAllUserIds in interface UserService
Returns:
the list of all user ids

getAllUserIdsInRange

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

public int getNumberOfAdmins()
Specified by:
getNumberOfAdmins in interface UserService
Returns:
the number of users with the admin role set

getUserForId

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

getUserAsBean

public UserBean getUserAsBean(User user)
Specified by:
getUserAsBean in interface UserService
Returns:
the specified user as a user bean object

getAnonymousUser

public UserBean getAnonymousUser()
Specified by:
getAnonymousUser in interface UserService
Returns:
an anonymous default user object

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

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

isAnonymous

public boolean isAnonymous(User user)
Description copied from interface: UserService
Is the specified user anonymous? See the discussion in StandardAuthoritiesService

Specified by:
isAnonymous in interface UserService
Returns:
true if the user is anonymous, otherwise false

isAdministrator

public boolean isAdministrator(User user)
Description copied from interface: UserService
Is the specified user an administrator? See the discussion in StandardAuthoritiesService

Specified by:
isAdministrator in interface UserService
Returns:
true if the user is an administrator, otherwise false

enableAdminRoleForUser

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

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

getUserIndexKeyValuesForKeyType

public List<String> getUserIndexKeyValuesForKeyType(String keyType)
Specified by:
getUserIndexKeyValuesForKeyType in interface UserService
Returns:
the set of UserIndexKey values having the specified UserIndexKey type

getOrCreateUserForIndexKey

public UserIndex getOrCreateUserForIndexKey(UserIndexKey key,
                                            String credentials,
                                            boolean isAnonymous)
Specified by:
getOrCreateUserForIndexKey in interface UserService
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

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

getUserIndexForId

public UserIndex getUserIndexForId(UserIndexKey key)
Specified by:
getUserIndexForId in interface UserService
Parameters:
key - see UserIndex.getId()
Returns:
the user index with the specified key, or null if not found

addUserIndexToUser

public UserIndex addUserIndexToUser(User user,
                                    UserIndexKey key,
                                    String credentials)
Description copied from interface: UserService
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.

Specified by:
addUserIndexToUser in interface UserService
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

removeUserIndexForUser

public void removeUserIndexForUser(User user,
                                   UserIndexKey key)
Description copied from interface: UserService
Remove the UserIndex with the specified id from the user.

Specified by:
removeUserIndexForUser in interface UserService
key - see UserIndex.getId()

setCredentialsForUserIndex

public void setCredentialsForUserIndex(UserIndex userIndex,
                                       String credentials)
Description copied from interface: UserService
Update the credentials for the specified user index

Specified by:
setCredentialsForUserIndex in interface UserService

setPasswordForUsernameUserIndex

public void setPasswordForUsernameUserIndex(UserIndex userIndex,
                                            String password)
Description copied from interface: UserService
Update the password for the UserIndexTypes.USERNAME user index

Specified by:
setPasswordForUsernameUserIndex in interface UserService

mergeUsers

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

registerPhoneNumber

public String registerPhoneNumber(User user,
                                  String phoneNumber)
Description copied from interface: UserService
Begin phone number registration for the specified user. Returns a code that the user must specify in a call to UserService.completePhoneNumberRegistration(UserIndex, String) to verify that they do in fact own that phone number.

Specified by:
registerPhoneNumber in interface UserService
Returns:
the code that must be supplied in a subsequent call to UserService.completePhoneNumberRegistration(UserIndex, String)

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

completePhoneNumberRegistration

public UserIndex completePhoneNumberRegistration(UserIndex userIndex,
                                                 String registrationCode)
Description copied from interface: UserService
Complete phone number registration. If the registrationCode matches one returned in a previous call to UserService.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.

Specified by:
completePhoneNumberRegistration in interface UserService
Returns:
the newly created UserIndex object for the phone number user index

clearPhoneNumberRegistration

public void clearPhoneNumberRegistration(UserIndexKey userIndexKey)
Description copied from interface: UserService
Reset a previous call to UserService.registerPhoneNumber(User, String) for the specified user

Specified by:
clearPhoneNumberRegistration in interface UserService

startUserPropertiesMigration

public void startUserPropertiesMigration()
Description copied from interface: UserService
Start the user property migration task - see UserPropertiesMigration

Specified by:
startUserPropertiesMigration in interface UserService

getUserPropertiesMigrationStatus

public UserPropertiesMigrationStatus getUserPropertiesMigrationStatus()
Description copied from interface: UserService
See UserPropertiesMigration

Specified by:
getUserPropertiesMigrationStatus in interface UserService
Returns:
the status for the user properties migration task

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

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


Copyright © 2012 OneBusAway. All Rights Reserved.