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 void
addListener(UserModelListenerEx listener)
void
addListener(UserModelListener listener)
Adds listener to the user modelvoid
addRole(Long userId, RoleScope roleScope, Role role)
Adds a role with specified scope to an entity with specified id.void
afterCleanup(CleanupProcessState cleanupState)
Invoked upon finishing of the main cleanup process.boolean
atLeastOneUserAccountRegistered()
Returns true if at least one user account exists.void
blockStateChanged(SUser user)
void
checkUserAccountExists(String username)
Checks whether a user account with specified username exists.UserEx
createPermissionsRestrictedUser(UserEx delegate, PermissionsHolder permissionsRestrictor)
static GenericQuery.ResultSetProcessor<Map<RoleScope,Set<Role>>>
createRolesResultSetProcessor(RolesManager rolesManager)
SUser
createUserAccount(String realm, String username)
Creates a new user.SUser
createUserAccount(NewUserAccount newUserAccount)
void
deleteProperty(Long userId, PropertyKey key)
UserEx
findUserAccount(String realm, String username)
Searches for a user account with specified realm and usernameSUser
findUserAccount(String realm, String username, String password)
Searches for a user account with specified realm, username and passwordUserEx
findUserById(long userId)
Searches for a user by id in the current login domain.SUser
findUserByUsername(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 String
fixUsername(String username)
static String
generateSalt()
UserSet<SUser>
getAllUsers()
Returns all of the registered usersUserEx
getGuestUser()
Returns guest userint
getNumberOfRegisteredUsers()
Returns number of users currently registered in the system.UserEx
getSuperUser()
Returns Super userboolean
hasAdministratorAccount()
Returns true if there is at least one administrator that can be authenticated by specified login module.boolean
isGuestUser(User user)
Returns true if the specified user is guestboolean
isSpecialUser(User user)
Returns true if user is guest or root.static boolean
isSpecialUserId(long userId)
boolean
isSuperUser(User user)
Returns true if the specified user is Super userstatic boolean
isValidUserId(long userId)
void
notifyUserChanged(SUser user)
void
notifyUserPermissionsMayHaveChanged(SUser user)
void
notifyUserPropertyChanged(SUser user, PropertyKey propertyKey)
void
notifyUserRolesChanged(SUser user)
void
persistLastLoginTimestamp(long userId, Date timestamp)
Note: login timestamp will be persisted with some delay.void
removeListener(UserModelListener listener)
Removes listener from the user modelvoid
removeRole(Long userId, Role role)
Removes the specified role from the entity with specified id.void
removeRole(Long userId, RoleScope roleScope, Role role)
Removes role with specified scope from the entity with specified id.void
removeRole(Role role)
Removes the specified role for all roles holders.void
removeRoles(Long userId, RoleScope roleScope)
Removes all roles with specified scope from the entity with specified id.void
removeUserAccount(long userId)
Removes user account from database.void
setAuditLogFactory(AuditLogFactory auditLogFactory)
void
setBuildTypesOrder(long userId, String projectId, UserImpl.BuildTypesOrder buildTypesOrder)
Sets order of build typesvoid
setLicenseKeysManager(LicenseKeysManager licKeysManager)
void
setLoginConfiguration(LoginConfiguration loginConfiguration)
void
setPassword(long userId, String password)
void
setProjectManager(ProjectManager projectManager)
void
setProjectsOrder(long userId, List<String> projectsOrder)
Sets order of the projects.void
setProjectsVisibility(long userId, Collection<String> projectIds, boolean isVisible)
Set visibility state for selected projects.void
setProperties(Long userId, Map<? extends PropertyKey,String> properties)
void
setProperty(Long userId, PropertyKey key, String value)
void
setRolesManager(RolesManager rolesManager)
void
setServerImpl(BuildServerImpl server)
void
setServerSettings(ServerSettingsImpl serverSettings)
void
setUserFactory(UserFactoryEx userFactory)
void
setUserGroupManager(UserGroupManager userGroupManager)
void
setVisibleProjects(long userId, Collection<String> visibleProjects)
Sets projects visible for specified uservoid
updateUserAccount(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:
setLicenseKeysManager
in interfaceUserModelEx
-
hasAdministratorAccount
public boolean hasAdministratorAccount()
Description copied from interface:UserModel
Returns true if there is at least one administrator that can be authenticated by specified login module.- Specified by:
hasAdministratorAccount
in 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:UserModelEx
Searches for users with specified keyword in username, name or email. If keyword is empty, then all users returned.- Specified by:
findUsers
in interfaceUserModelEx
- Returns:
- unmodifiable collection of users
-
findUsersByVerifiedEmail
@NotNull public List<SUser> findUsersByVerifiedEmail(@NotNull String verifiedEmail)
- Specified by:
findUsersByVerifiedEmail
in interfaceUserModelEx
-
afterCleanup
public void afterCleanup(@NotNull CleanupProcessState cleanupState)
Description copied from interface:AfterBuildsCleanupExtension
Invoked 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:
afterCleanup
in interfaceAfterBuildsCleanupExtension
- Parameters:
cleanupState
- cleanup process state
-
addListener
public void addListener(UserModelListener listener)
Description copied from interface:UserModel
Adds listener to the user model- Specified by:
addListener
in interfaceUserModel
- Parameters:
listener
- listener to add
-
addListener
public void addListener(UserModelListenerEx listener)
- Specified by:
addListener
in interfaceUserModelEx
-
removeListener
public void removeListener(UserModelListener listener)
Description copied from interface:UserModel
Removes listener from the user model- Specified by:
removeListener
in interfaceUserModel
- Parameters:
listener
- to remove
-
setProjectsOrder
public void setProjectsOrder(long userId, List<String> projectsOrder) throws UserNotFoundException
Description copied from interface:UserUpdate
Sets order of the projects.- Specified by:
setProjectsOrder
in 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 UserNotFoundException
Description copied from interface:UserUpdate
Sets projects visible for specified user- Specified by:
setVisibleProjects
in 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 UserNotFoundException
Description copied from interface:UserUpdate
Sets order of build types- Specified by:
setBuildTypesOrder
in interfaceUserUpdate
buildTypesOrder
- build type internal ids- Throws:
UserNotFoundException
-
setProjectsVisibility
public void setProjectsVisibility(long userId, @NotNull Collection<String> projectIds, boolean isVisible)
Description copied from interface:UserUpdate
Set visibility state for selected projects. Doesn't affect other projects nor project order.- Specified by:
setProjectsVisibility
in interfaceUserUpdate
-
persistLastLoginTimestamp
public void persistLastLoginTimestamp(long userId, Date timestamp) throws UserNotFoundException
Description copied from interface:UserUpdate
Note: login timestamp will be persisted with some delay.- Specified by:
persistLastLoginTimestamp
in interfaceUserUpdate
- Parameters:
userId
- user idtimestamp
- timestamp- Throws:
UserNotFoundException
-
notifyUserChanged
public void notifyUserChanged(@NotNull SUser user)
- Specified by:
notifyUserChanged
in interfaceUserUpdate
-
notifyUserPropertyChanged
public void notifyUserPropertyChanged(@NotNull SUser user, @NotNull PropertyKey propertyKey)
- Specified by:
notifyUserPropertyChanged
in interfaceUserUpdate
-
notifyUserRolesChanged
public void notifyUserRolesChanged(@NotNull SUser user)
- Specified by:
notifyUserRolesChanged
in interfaceUserUpdate
-
notifyUserPermissionsMayHaveChanged
public void notifyUserPermissionsMayHaveChanged(@NotNull SUser user)
- Specified by:
notifyUserPermissionsMayHaveChanged
in interfaceUserUpdate
-
blockStateChanged
public void blockStateChanged(@NotNull SUser user)
- Specified by:
blockStateChanged
in interfaceUserUpdate
-
removeUserAccount
public void removeUserAccount(long userId)
Description copied from interface:UserModel
Removes user account from database.- Specified by:
removeUserAccount
in interfaceUserModel
- Parameters:
userId
- id of the user
-
findUserById
@Nullable public UserEx findUserById(long userId)
Description copied from interface:UserModel
Searches for a user by id in the current login domain. Login domain is defined by currently selected login module.- Specified by:
findUserById
in interfaceUserModel
- Specified by:
findUserById
in 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:UserModel
Searches for users with specified ids, returns collection of existing users only.- Specified by:
findUsersByIds
in interfaceUserModel
- Parameters:
userIds
- user ids- Returns:
- collection of found users
-
getGuestUser
@NotNull public UserEx getGuestUser()
Description copied from interface:UserModel
Returns guest user- Specified by:
getGuestUser
in interfaceUserModel
- Specified by:
getGuestUser
in interfaceUserModelEx
- Returns:
- guest user
-
getSuperUser
@NotNull public UserEx getSuperUser()
Description copied from interface:UserModel
Returns Super user- Specified by:
getSuperUser
in interfaceUserModel
- Returns:
- Super user
-
createPermissionsRestrictedUser
public UserEx createPermissionsRestrictedUser(@NotNull UserEx delegate, @NotNull PermissionsHolder permissionsRestrictor)
- Specified by:
createPermissionsRestrictedUser
in interfaceUserModelEx
-
isGuestUser
public boolean isGuestUser(@NotNull User user)
Description copied from interface:UserModel
Returns true if the specified user is guest- Specified by:
isGuestUser
in interfaceUserModel
- Parameters:
user
- user to check- Returns:
- true if user is guest
-
isSuperUser
public boolean isSuperUser(@NotNull User user)
Description copied from interface:UserModel
Returns true if the specified user is Super user- Specified by:
isSuperUser
in interfaceUserModel
- Parameters:
user
- user to check- Returns:
- true if user is Super user
-
isSpecialUser
public boolean isSpecialUser(@NotNull User user)
Description copied from interface:UserModelEx
Returns true if user is guest or root.- Specified by:
isSpecialUser
in 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:UserModel
Searches for a user account with specified realm and username- Specified by:
findUserAccount
in interfaceUserModel
- Specified by:
findUserAccount
in 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:UserModel
Searches for a user account with specified realm, username and password- Specified by:
findUserAccount
in 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:UserModel
Returns all of the registered users- Specified by:
getAllUsers
in interfaceUserModel
- Returns:
- all of the registered users
-
getNumberOfRegisteredUsers
public int getNumberOfRegisteredUsers()
Description copied from interface:UserModel
Returns number of users currently registered in the system.- Specified by:
getNumberOfRegisteredUsers
in interfaceUserModel
- Returns:
- number of currently registered users
-
findUsersByPropertyValue
public UserSet<SUser> findUsersByPropertyValue(PropertyKey propertyKey, @Nullable String propertyValue, boolean caseSensitive)
Description copied from interface:UserModel
Returns UserSet of users having specified property in the profile. UserSet collection will be sorted by account name.- Specified by:
findUsersByPropertyValue
in 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:UserModelEx
Returns UserSet of users having specified attribute.- Specified by:
findUsersByAttributeValue
in 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:UserModel
Looks 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:
findUserByUsername
in 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:
createUserAccount
in interfaceUserModelEx
- Throws:
DuplicateUserAccountException
MaxNumberOfUserAccountsReachedException
-
createUserAccount
public SUser createUserAccount(String realm, String username) throws DuplicateUserAccountException, MaxNumberOfUserAccountsReachedException
Description copied from interface:UserModel
Creates a new user.- Specified by:
createUserAccount
in 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:UserModelEx
Checks whether a user account with specified username exists. If such user found then DuplicateUserAccountException is thrown.- Specified by:
checkUserAccountExists
in interfaceUserModelEx
- Throws:
DuplicateUserAccountException
-
updateUserAccount
public void updateUserAccount(long userId, @NotNull String username, String name, String email) throws UserNotFoundException, DuplicateUserAccountException
Description copied from interface:UserUpdate
Updates user with specified id and sets his/her username and name.- Specified by:
updateUserAccount
in 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 UserNotFoundException
Description copied from interface:RolesUpdate
Adds a role with specified scope to an entity with specified id.- Specified by:
addRole
in 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 UserNotFoundException
Description copied from interface:RolesUpdate
Removes role with specified scope from the entity with specified id.- Specified by:
removeRole
in 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:RolesUpdate
Removes the specified role from the entity with specified id. The role is removed from all of the scopes.- Specified by:
removeRole
in interfaceRolesUpdate<Long>
- Parameters:
userId
- idrole
- role to remove
-
removeRoles
public void removeRoles(@NotNull Long userId, @NotNull RoleScope roleScope) throws UserNotFoundException
Description copied from interface:RolesUpdate
Removes all roles with specified scope from the entity with specified id.- Specified by:
removeRoles
in interfaceRolesUpdate<Long>
- Parameters:
userId
- idroleScope
- scope of the role- Throws:
UserNotFoundException
-
removeRole
public void removeRole(@NotNull Role role)
Description copied from interface:RolesUpdate
Removes the specified role for all roles holders.- Specified by:
removeRole
in interfaceRolesUpdate<Long>
- Parameters:
role
- role to remove
-
setProperties
public void setProperties(@NotNull Long userId, @NotNull Map<? extends PropertyKey,String> properties) throws UserNotFoundException
- Specified by:
setProperties
in interfacePropertyUpdater<Long>
- Throws:
UserNotFoundException
-
setProperty
public void setProperty(@NotNull Long userId, @NotNull PropertyKey key, String value) throws UserNotFoundException
- Specified by:
setProperty
in interfacePropertyUpdater<Long>
- Throws:
UserNotFoundException
-
deleteProperty
public void deleteProperty(@NotNull Long userId, @NotNull PropertyKey key) throws UserNotFoundException
- Specified by:
deleteProperty
in interfacePropertyUpdater<Long>
- Throws:
UserNotFoundException
-
setPassword
public void setPassword(long userId, String password) throws UserNotFoundException
- Specified by:
setPassword
in interfaceUserUpdate
- Throws:
UserNotFoundException
-
generateSalt
@NotNull public static String generateSalt()
-
atLeastOneUserAccountRegistered
public boolean atLeastOneUserAccountRegistered()
Description copied from interface:UserModelEx
Returns true if at least one user account exists.- Specified by:
atLeastOneUserAccountRegistered
in interfaceUserModelEx
- Returns:
- see above
-
createRolesResultSetProcessor
public static GenericQuery.ResultSetProcessor<Map<RoleScope,Set<Role>>> createRolesResultSetProcessor(@NotNull RolesManager rolesManager)
-
-