Package jetbrains.buildServer.users.impl
Class UserModelImpl
- java.lang.Object
 - 
- jetbrains.buildServer.users.impl.UserModelImpl
 
 
- 
- All Implemented Interfaces:
 AfterBuildsCleanupExtension,ServerExtension,TeamCityExtension,PropertyUpdater<Long>,RolesUpdate<Long>,UserModel,UserModelEx,UserUpdate
public class UserModelImpl extends Object implements UserModelEx, UserUpdate, AfterBuildsCleanupExtension
- Author:
 - Pavel Sher
 
 
- 
- 
Nested Class Summary
- 
Nested classes/interfaces inherited from interface jetbrains.buildServer.users.UserModelEx
UserModelEx.SORT_BY 
 - 
 
- 
Constructor Summary
Constructors Constructor Description UserModelImpl(SecurityContextEx securityContext, EventDispatcher<BuildServerListener> serverDispatcher, EventDispatcher<UserModelListener> userModelDispatcher, EventDispatcher<ProjectsImportListener> projectImportListenerEventDispatcher, EventDispatcher<UserModelListenerEx> userModelDispatcherEx, SQLRunnerEx sqlRunner, NumericIdSequences idSequences, UserDataLoader userDataLoader, MultiNodesEvents multiNodesEvents, ExecutorServices executorServices, ServerResponsibility serverResponsibility, AuthenticationTokenStorage authenticationTokenStorage, UserAttributeStorage userAttributeStorage, PasswordComplexityChecker passwordComplexityChecker) 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(UserModelListenerEx listener)voidaddListener(UserModelListener listener)Adds listener to the user modelvoidaddRole(Long userId, RoleScope roleScope, Role role)Adds a role with specified scope to an entity with specified id.voidafterCleanup(CleanupProcessState cleanupState)Invoked upon finishing of the main cleanup process.booleanatLeastOneUserAccountRegistered()Returns true if at least one user account exists.voidblockStateChanged(SUser user)voidcheckUserAccountExists(String username)Checks whether a user account with specified username exists.UserExcreatePermissionsRestrictedUser(UserEx delegate, PermissionsHolder permissionsRestrictor)static GenericQuery.ResultSetProcessor<Map<RoleScope,Set<Role>>>createRolesResultSetProcessor(RolesManager rolesManager)SUsercreateUserAccount(String realm, String username)Creates a new user.SUsercreateUserAccount(NewUserAccount newUserAccount)voiddeleteProperty(Long userId, PropertyKey key)UserExfindUserAccount(String realm, String username)Searches for a user account with specified realm and usernameSUserfindUserAccount(String realm, String username, String password)Searches for a user account with specified realm, username and passwordUserExfindUserById(long userId)Searches for a user by id in the current login domain.SUserfindUserByUsername(String username, AuthPropertyKey usernamePropertyKey)Looks for a TeamCity user with the specified username.List<UserEx>findUsers(SearchOptions searchOptions, UserModelEx.SORT_BY sortOption, boolean ascending)Searches for users with specified keyword in username, name or email.UserSet<SUser>findUsersByAttributeValue(String attributeKey, String attributeValue, boolean caseSensitive)Returns UserSet of users having specified attribute.Collection<SUser>findUsersByIds(Collection<Long> userIds)Searches for users with specified ids, returns collection of existing users only.UserSet<SUser>findUsersByPropertyValue(PropertyKey propertyKey, String propertyValue, boolean caseSensitive)Returns UserSet of users having specified property in the profile.List<SUser>findUsersByVerifiedEmail(String verifiedEmail)static StringfixUsername(String username)static StringgenerateSalt()UserSet<SUser>getAllUsers()Returns all of the registered usersUserExgetGuestUser()Returns guest userintgetNumberOfRegisteredUsers()Returns number of users currently registered in the system.UserExgetSuperUser()Returns Super userbooleanhasAdministratorAccount()Returns true if there is at least one administrator that can be authenticated by specified login module.booleanisGuestUser(User user)Returns true if the specified user is guestbooleanisSpecialUser(User user)Returns true if user is guest or root.static booleanisSpecialUserId(long userId)booleanisSuperUser(User user)Returns true if the specified user is Super userstatic booleanisValidUserId(long userId)voidnotifyUserChanged(SUser user)voidnotifyUserPermissionsMayHaveChanged(SUser user)voidnotifyUserPropertyChanged(SUser user, PropertyKey propertyKey)voidnotifyUserRolesChanged(SUser user)voidpersistLastLoginTimestamp(long userId, Date timestamp)Note: login timestamp will be persisted with some delay.voidremoveListener(UserModelListener listener)Removes listener from the user modelvoidremoveRole(Long userId, Role role)Removes the specified role from the entity with specified id.voidremoveRole(Long userId, RoleScope roleScope, Role role)Removes role with specified scope from the entity with specified id.voidremoveRole(Role role)Removes the specified role for all roles holders.voidremoveRoles(Long userId, RoleScope roleScope)Removes all roles with specified scope from the entity with specified id.voidremoveUserAccount(long userId)Removes user account from database.voidsetAuditLogFactory(AuditLogFactory auditLogFactory)voidsetBuildTypesOrder(long userId, String projectId, UserImpl.BuildTypesOrder buildTypesOrder)Sets order of build typesvoidsetLicenseKeysManager(LicenseKeysManager licKeysManager)voidsetLoginConfiguration(LoginConfiguration loginConfiguration)voidsetPassword(long userId, String password)voidsetProjectManager(ProjectManager projectManager)voidsetProjectsOrder(long userId, List<String> projectsOrder)Sets order of the projects.voidsetProjectsVisibility(long userId, Collection<String> projectIds, boolean isVisible)Set visibility state for selected projects.voidsetProperties(Long userId, Map<? extends PropertyKey,String> properties)voidsetProperty(Long userId, PropertyKey key, String value)voidsetRolesManager(RolesManager rolesManager)voidsetServerImpl(BuildServerImpl server)voidsetServerSettings(ServerSettingsImpl serverSettings)voidsetUserFactory(UserFactoryEx userFactory)voidsetUserGroupManager(UserGroupManager userGroupManager)voidsetVisibleProjects(long userId, Collection<String> visibleProjects)Sets projects visible for specified uservoidupdateUserAccount(long userId, String username, String name, String email)Updates user with specified id and sets his/her username and name. 
 - 
 
- 
- 
Constructor Detail
- 
UserModelImpl
public UserModelImpl(@NotNull SecurityContextEx securityContext, @NotNull EventDispatcher<BuildServerListener> serverDispatcher, @NotNull EventDispatcher<UserModelListener> userModelDispatcher, @NotNull EventDispatcher<ProjectsImportListener> projectImportListenerEventDispatcher, @NotNull EventDispatcher<UserModelListenerEx> userModelDispatcherEx, @NotNull SQLRunnerEx sqlRunner, @NotNull NumericIdSequences idSequences, @NotNull UserDataLoader userDataLoader, @NotNull MultiNodesEvents multiNodesEvents, @NotNull ExecutorServices executorServices, @NotNull ServerResponsibility serverResponsibility, @NotNull AuthenticationTokenStorage authenticationTokenStorage, @NotNull UserAttributeStorage userAttributeStorage, @NotNull PasswordComplexityChecker passwordComplexityChecker) 
 - 
 
- 
Method Detail
- 
setUserFactory
public void setUserFactory(@NotNull UserFactoryEx userFactory) 
- 
setUserGroupManager
public void setUserGroupManager(@NotNull UserGroupManager userGroupManager) 
- 
setLoginConfiguration
public void setLoginConfiguration(@NotNull LoginConfiguration loginConfiguration) 
- 
setProjectManager
public void setProjectManager(@NotNull ProjectManager projectManager) 
- 
setAuditLogFactory
public void setAuditLogFactory(@NotNull AuditLogFactory auditLogFactory) 
- 
setServerImpl
public void setServerImpl(@NotNull BuildServerImpl server) 
- 
setRolesManager
public void setRolesManager(@NotNull RolesManager rolesManager) 
- 
setServerSettings
public void setServerSettings(@NotNull ServerSettingsImpl serverSettings) 
- 
setLicenseKeysManager
public void setLicenseKeysManager(@NotNull LicenseKeysManager licKeysManager)- Specified by:
 setLicenseKeysManagerin interfaceUserModelEx
 
- 
hasAdministratorAccount
public boolean hasAdministratorAccount()
Description copied from interface:UserModelReturns true if there is at least one administrator that can be authenticated by specified login module.- Specified by:
 hasAdministratorAccountin interfaceUserModel- Returns:
 - true if administrator account exists in the system
 
 
- 
findUsers
public List<UserEx> findUsers(@NotNull SearchOptions searchOptions, @NotNull UserModelEx.SORT_BY sortOption, boolean ascending)
Description copied from interface:UserModelExSearches for users with specified keyword in username, name or email. If keyword is empty, then all users returned.- Specified by:
 findUsersin interfaceUserModelEx- Returns:
 - unmodifiable collection of users
 
 
- 
findUsersByVerifiedEmail
@NotNull public List<SUser> findUsersByVerifiedEmail(@NotNull String verifiedEmail)
- Specified by:
 findUsersByVerifiedEmailin interfaceUserModelEx
 
- 
afterCleanup
public void afterCleanup(@NotNull CleanupProcessState cleanupState)Description copied from interface:AfterBuildsCleanupExtensionInvoked upon finishing of the main cleanup process. At this point all data for specific builds is deleted.
Note: This extension might not be called for every cleanup run as cleanup process can be interrupted earlier. Extension must check cleanup process state and if it is interrupted, complete its operations and return as quick as possible.- Specified by:
 afterCleanupin interfaceAfterBuildsCleanupExtension- Parameters:
 cleanupState- cleanup process state
 
- 
addListener
public void addListener(UserModelListener listener)
Description copied from interface:UserModelAdds listener to the user model- Specified by:
 addListenerin interfaceUserModel- Parameters:
 listener- listener to add
 
- 
addListener
public void addListener(UserModelListenerEx listener)
- Specified by:
 addListenerin interfaceUserModelEx
 
- 
removeListener
public void removeListener(UserModelListener listener)
Description copied from interface:UserModelRemoves listener from the user model- Specified by:
 removeListenerin interfaceUserModel- Parameters:
 listener- to remove
 
- 
setProjectsOrder
public void setProjectsOrder(long userId, List<String> projectsOrder) throws UserNotFoundExceptionDescription copied from interface:UserUpdateSets order of the projects.- Specified by:
 setProjectsOrderin interfaceUserUpdate- Parameters:
 userId- id of a userprojectsOrder- identificators of all projects in the order specified by user. The order will be reset to default (system) if null or empty.- Throws:
 UserNotFoundException- if specified user no longer exists
 
- 
setVisibleProjects
public void setVisibleProjects(long userId, @NotNull Collection<String> visibleProjects) throws UserNotFoundExceptionDescription copied from interface:UserUpdateSets projects visible for specified user- Specified by:
 setVisibleProjectsin interfaceUserUpdate- Parameters:
 userId- id of a uservisibleProjects- collection of identifiers of visible projects- Throws:
 UserNotFoundException- if specified user no longer exists
 
- 
setBuildTypesOrder
public void setBuildTypesOrder(long userId, @NotNull String projectId, @Nullable UserImpl.BuildTypesOrder buildTypesOrder) throws UserNotFoundExceptionDescription copied from interface:UserUpdateSets order of build types- Specified by:
 setBuildTypesOrderin interfaceUserUpdatebuildTypesOrder- build type internal ids- Throws:
 UserNotFoundException
 
- 
setProjectsVisibility
public void setProjectsVisibility(long userId, @NotNull Collection<String> projectIds, boolean isVisible)Description copied from interface:UserUpdateSet visibility state for selected projects. Doesn't affect other projects nor project order.- Specified by:
 setProjectsVisibilityin interfaceUserUpdate
 
- 
persistLastLoginTimestamp
public void persistLastLoginTimestamp(long userId, Date timestamp) throws UserNotFoundExceptionDescription copied from interface:UserUpdateNote: login timestamp will be persisted with some delay.- Specified by:
 persistLastLoginTimestampin interfaceUserUpdate- Parameters:
 userId- user idtimestamp- timestamp- Throws:
 UserNotFoundException
 
- 
notifyUserChanged
public void notifyUserChanged(@NotNull SUser user)- Specified by:
 notifyUserChangedin interfaceUserUpdate
 
- 
notifyUserPropertyChanged
public void notifyUserPropertyChanged(@NotNull SUser user, @NotNull PropertyKey propertyKey)- Specified by:
 notifyUserPropertyChangedin interfaceUserUpdate
 
- 
notifyUserRolesChanged
public void notifyUserRolesChanged(@NotNull SUser user)- Specified by:
 notifyUserRolesChangedin interfaceUserUpdate
 
- 
notifyUserPermissionsMayHaveChanged
public void notifyUserPermissionsMayHaveChanged(@NotNull SUser user)- Specified by:
 notifyUserPermissionsMayHaveChangedin interfaceUserUpdate
 
- 
blockStateChanged
public void blockStateChanged(@NotNull SUser user)- Specified by:
 blockStateChangedin interfaceUserUpdate
 
- 
removeUserAccount
public void removeUserAccount(long userId)
Description copied from interface:UserModelRemoves user account from database.- Specified by:
 removeUserAccountin interfaceUserModel- Parameters:
 userId- id of the user
 
- 
findUserById
@Nullable public UserEx findUserById(long userId)
Description copied from interface:UserModelSearches for a user by id in the current login domain. Login domain is defined by currently selected login module.- Specified by:
 findUserByIdin interfaceUserModel- Specified by:
 findUserByIdin interfaceUserModelEx- Parameters:
 userId- id of the user- Returns:
 - found user or null
 
 
- 
findUsersByIds
@NotNull public Collection<SUser> findUsersByIds(@NotNull Collection<Long> userIds)
Description copied from interface:UserModelSearches for users with specified ids, returns collection of existing users only.- Specified by:
 findUsersByIdsin interfaceUserModel- Parameters:
 userIds- user ids- Returns:
 - collection of found users
 
 
- 
getGuestUser
@NotNull public UserEx getGuestUser()
Description copied from interface:UserModelReturns guest user- Specified by:
 getGuestUserin interfaceUserModel- Specified by:
 getGuestUserin interfaceUserModelEx- Returns:
 - guest user
 
 
- 
getSuperUser
@NotNull public UserEx getSuperUser()
Description copied from interface:UserModelReturns Super user- Specified by:
 getSuperUserin interfaceUserModel- Returns:
 - Super user
 
 
- 
createPermissionsRestrictedUser
public UserEx createPermissionsRestrictedUser(@NotNull UserEx delegate, @NotNull PermissionsHolder permissionsRestrictor)
- Specified by:
 createPermissionsRestrictedUserin interfaceUserModelEx
 
- 
isGuestUser
public boolean isGuestUser(@NotNull User user)Description copied from interface:UserModelReturns true if the specified user is guest- Specified by:
 isGuestUserin interfaceUserModel- Parameters:
 user- user to check- Returns:
 - true if user is guest
 
 
- 
isSuperUser
public boolean isSuperUser(@NotNull User user)Description copied from interface:UserModelReturns true if the specified user is Super user- Specified by:
 isSuperUserin interfaceUserModel- Parameters:
 user- user to check- Returns:
 - true if user is Super user
 
 
- 
isSpecialUser
public boolean isSpecialUser(@NotNull User user)Description copied from interface:UserModelExReturns true if user is guest or root.- Specified by:
 isSpecialUserin interfaceUserModelEx- Returns:
 
 
- 
isSpecialUserId
public static boolean isSpecialUserId(long userId)
 
- 
isValidUserId
public static boolean isValidUserId(long userId)
 
- 
findUserAccount
@Nullable public UserEx findUserAccount(@Nullable String realm, @NotNull String username)
Description copied from interface:UserModelSearches for a user account with specified realm and username- Specified by:
 findUserAccountin interfaceUserModel- Specified by:
 findUserAccountin interfaceUserModelEx- Parameters:
 realm- realm is always ignored. Pass null here.username- username- Returns:
 - found user or null
 
 
- 
findUserAccount
@Nullable public SUser findUserAccount(@Nullable String realm, @NotNull String username, @NotNull String password)
Description copied from interface:UserModelSearches for a user account with specified realm, username and password- Specified by:
 findUserAccountin interfaceUserModel- Parameters:
 realm- realm is always ignored. Pass null here.username- usernamepassword- user password- Returns:
 - found user or null
 
 
- 
getAllUsers
public UserSet<SUser> getAllUsers()
Description copied from interface:UserModelReturns all of the registered users- Specified by:
 getAllUsersin interfaceUserModel- Returns:
 - all of the registered users
 
 
- 
getNumberOfRegisteredUsers
public int getNumberOfRegisteredUsers()
Description copied from interface:UserModelReturns number of users currently registered in the system.- Specified by:
 getNumberOfRegisteredUsersin interfaceUserModel- Returns:
 - number of currently registered users
 
 
- 
findUsersByPropertyValue
public UserSet<SUser> findUsersByPropertyValue(PropertyKey propertyKey, @Nullable String propertyValue, boolean caseSensitive)
Description copied from interface:UserModelReturns UserSet of users having specified property in the profile. UserSet collection will be sorted by account name.- Specified by:
 findUsersByPropertyValuein interfaceUserModel- Parameters:
 propertyKey- property keypropertyValue- property valuecaseSensitive- whether to perform case sensitive search- Returns:
 - set of users having the value with specified key in the profile
 
 
- 
findUsersByAttributeValue
public UserSet<SUser> findUsersByAttributeValue(String attributeKey, @Nullable String attributeValue, boolean caseSensitive)
Description copied from interface:UserModelExReturns UserSet of users having specified attribute.- Specified by:
 findUsersByAttributeValuein interfaceUserModelEx- Parameters:
 attributeKey- attribute keyattributeValue- attribute valuecaseSensitive- whether to perform case-sensitive search- Returns:
 - set of users having the attribute with specified key and value
 
 
- 
findUserByUsername
@Nullable public SUser findUserByUsername(@NotNull String username, @NotNull AuthPropertyKey usernamePropertyKey) throws InvalidUsernameException
Description copied from interface:UserModelLooks for a TeamCity user with the specified username. Username is searched as a value of the specified user property and as an account's username itself (property has higher priority).- Specified by:
 findUserByUsernamein interfaceUserModel- Parameters:
 username- username to searchusernamePropertyKey- user property key to search username as a value of; it is assumed that no more than one user can have the specified username as a value of this property- Returns:
 - user with the specified username being the value of the specified user property or, if not found, user with the same TeamCity username as the specified one and empty value of the specified user property or, if not found, null
 - Throws:
 InvalidUsernameException-- if user with the specified username being the value of the specified user property does not exist and user with the same TeamCity username as the specified one exists and his/her value of the specified user property is not empty
 - if several users match the search
 
 
- 
createUserAccount
@NotNull public SUser createUserAccount(@NotNull NewUserAccount newUserAccount) throws DuplicateUserAccountException, MaxNumberOfUserAccountsReachedException
- Specified by:
 createUserAccountin interfaceUserModelEx- Throws:
 DuplicateUserAccountExceptionMaxNumberOfUserAccountsReachedException
 
- 
createUserAccount
public SUser createUserAccount(String realm, String username) throws DuplicateUserAccountException, MaxNumberOfUserAccountsReachedException
Description copied from interface:UserModelCreates a new user.- Specified by:
 createUserAccountin interfaceUserModel- Parameters:
 realm- realm realm is always ignored. Pass null hereusername- username- Returns:
 - newly created user
 - Throws:
 DuplicateUserAccountException- if user with specified username already exists in specified realmMaxNumberOfUserAccountsReachedException- thrown is maximum number of user accounts reached
 
- 
checkUserAccountExists
public void checkUserAccountExists(String username) throws DuplicateUserAccountException
Description copied from interface:UserModelExChecks whether a user account with specified username exists. If such user found then DuplicateUserAccountException is thrown.- Specified by:
 checkUserAccountExistsin interfaceUserModelEx- Throws:
 DuplicateUserAccountException
 
- 
updateUserAccount
public void updateUserAccount(long userId, @NotNull String username, String name, String email) throws UserNotFoundException, DuplicateUserAccountExceptionDescription copied from interface:UserUpdateUpdates user with specified id and sets his/her username and name.- Specified by:
 updateUserAccountin interfaceUserUpdate- Parameters:
 userId- user idusername- usernamename- full name of a user- Throws:
 UserNotFoundException- if specified user no longer exists in the modelDuplicateUserAccountException- if a new username name already assigned to another user
 
- 
addRole
public void addRole(@NotNull Long userId, @NotNull RoleScope roleScope, @NotNull Role role) throws UserNotFoundExceptionDescription copied from interface:RolesUpdateAdds a role with specified scope to an entity with specified id.- Specified by:
 addRolein interfaceRolesUpdate<Long>- Parameters:
 userId- uidroleScope- scope of the rolerole- role- Throws:
 UserNotFoundException
 
- 
removeRole
public void removeRole(@NotNull Long userId, @NotNull RoleScope roleScope, @NotNull Role role) throws UserNotFoundExceptionDescription copied from interface:RolesUpdateRemoves role with specified scope from the entity with specified id.- Specified by:
 removeRolein interfaceRolesUpdate<Long>- Parameters:
 userId- idroleScope- scope of the rolerole- role- Throws:
 UserNotFoundException
 
- 
removeRole
public void removeRole(@NotNull Long userId, @NotNull Role role)Description copied from interface:RolesUpdateRemoves the specified role from the entity with specified id. The role is removed from all of the scopes.- Specified by:
 removeRolein interfaceRolesUpdate<Long>- Parameters:
 userId- idrole- role to remove
 
- 
removeRoles
public void removeRoles(@NotNull Long userId, @NotNull RoleScope roleScope) throws UserNotFoundExceptionDescription copied from interface:RolesUpdateRemoves all roles with specified scope from the entity with specified id.- Specified by:
 removeRolesin interfaceRolesUpdate<Long>- Parameters:
 userId- idroleScope- scope of the role- Throws:
 UserNotFoundException
 
- 
removeRole
public void removeRole(@NotNull Role role)Description copied from interface:RolesUpdateRemoves the specified role for all roles holders.- Specified by:
 removeRolein interfaceRolesUpdate<Long>- Parameters:
 role- role to remove
 
- 
setProperties
public void setProperties(@NotNull Long userId, @NotNull Map<? extends PropertyKey,String> properties) throws UserNotFoundException- Specified by:
 setPropertiesin interfacePropertyUpdater<Long>- Throws:
 UserNotFoundException
 
- 
setProperty
public void setProperty(@NotNull Long userId, @NotNull PropertyKey key, String value) throws UserNotFoundException- Specified by:
 setPropertyin interfacePropertyUpdater<Long>- Throws:
 UserNotFoundException
 
- 
deleteProperty
public void deleteProperty(@NotNull Long userId, @NotNull PropertyKey key) throws UserNotFoundException- Specified by:
 deletePropertyin interfacePropertyUpdater<Long>- Throws:
 UserNotFoundException
 
- 
setPassword
public void setPassword(long userId, String password) throws UserNotFoundException- Specified by:
 setPasswordin interfaceUserUpdate- Throws:
 UserNotFoundException
 
- 
generateSalt
@NotNull public static String generateSalt()
 
- 
atLeastOneUserAccountRegistered
public boolean atLeastOneUserAccountRegistered()
Description copied from interface:UserModelExReturns true if at least one user account exists.- Specified by:
 atLeastOneUserAccountRegisteredin interfaceUserModelEx- Returns:
 - see above
 
 
- 
createRolesResultSetProcessor
public static GenericQuery.ResultSetProcessor<Map<RoleScope,Set<Role>>> createRolesResultSetProcessor(@NotNull RolesManager rolesManager)
 
 - 
 
 -