Package jetbrains.buildServer.users.impl
Class SecuredUserModel
- java.lang.Object
-
- jetbrains.buildServer.users.impl.SecuredUserModel
-
- All Implemented Interfaces:
PropertyUpdater<Long>
,RolesUpdate<Long>
,UserModel
,UserModelEx
,UserUpdate
,org.springframework.beans.factory.InitializingBean
public class SecuredUserModel extends Object implements UserModelEx, UserUpdate, org.springframework.beans.factory.InitializingBean
Created by Evgeniy.Koshkin.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jetbrains.buildServer.users.UserModelEx
UserModelEx.SORT_BY
-
-
Constructor Summary
Constructors Constructor Description SecuredUserModel(EventDispatcher<UserModelListener> dispatcher, SecurityContextEx securityContext)
-
Method Summary
All 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 id, RoleScope roleScope, Role role)
Adds a role with specified scope to an entity with specified id.void
afterPropertiesSet()
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)
SUser
createUserAccount(String realm, String username)
Creates a new user.SUser
createUserAccount(NewUserAccount newUserAccount)
void
deleteProperty(Long id, PropertyKey propertyKey)
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)
UserSet<SUser>
getAllUsers()
Returns all of the registered usersUserModelEx
getDelegate()
UserEx
getGuestUser()
Returns guest userint
getNumberOfRegisteredUsers()
Returns number of users currently registered in the system.SUser
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.boolean
isSuperUser(User user)
Returns true if the specified user is Super uservoid
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 id, Role role)
Removes the specified role from the entity with specified id.void
removeRole(Long id, 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 id, RoleScope roleScope)
Removes all roles with specified scope from the entity with specified id.void
removeUserAccount(long userId)
Removes user account from database.void
setBuildTypesOrder(long userId, String projectId, UserImpl.BuildTypesOrder buildTypesOrder)
Sets order of build typesvoid
setDelegate(UserModelImpl delegate)
void
setLicenseKeysManager(LicenseKeysManager licKeysManager)
void
setPassword(long userId, String password)
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 id, Map<? extends PropertyKey,String> properties)
void
setProperty(Long id, PropertyKey prop, String value)
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
-
SecuredUserModel
public SecuredUserModel(@NotNull EventDispatcher<UserModelListener> dispatcher, @NotNull SecurityContextEx securityContext)
-
-
Method Detail
-
setDelegate
public void setDelegate(@NotNull UserModelImpl delegate)
-
getDelegate
@NotNull public UserModelEx getDelegate()
-
findUsers
public List<UserEx> findUsers(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
-
createUserAccount
public SUser createUserAccount(String realm, String username) throws DuplicateUserAccountException, MaxNumberOfUserAccountsReachedException, EmptyUsernameException
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 reachedEmptyUsernameException
- if username is an empty string
-
createUserAccount
@NotNull public SUser createUserAccount(@NotNull NewUserAccount newUserAccount) throws DuplicateUserAccountException, MaxNumberOfUserAccountsReachedException
- Specified by:
createUserAccount
in interfaceUserModelEx
- Throws:
DuplicateUserAccountException
MaxNumberOfUserAccountsReachedException
-
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
-
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
-
findUsersByPropertyValue
public UserSet<SUser> findUsersByPropertyValue(PropertyKey propertyKey, 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, 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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
setLicenseKeysManager
public void setLicenseKeysManager(@NotNull LicenseKeysManager licKeysManager)
- Specified by:
setLicenseKeysManager
in interfaceUserModelEx
-
createPermissionsRestrictedUser
public UserEx createPermissionsRestrictedUser(@NotNull UserEx delegate, @NotNull PermissionsHolder permissionsRestrictor)
- Specified by:
createPermissionsRestrictedUser
in interfaceUserModelEx
-
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:
-
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
-
addListener
public void addListener(UserModelListenerEx listener)
- Specified by:
addListener
in interfaceUserModelEx
-
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
-
getSuperUser
@NotNull public SUser getSuperUser()
Description copied from interface:UserModel
Returns Super user- Specified by:
getSuperUser
in interfaceUserModel
- Returns:
- Super user
-
afterPropertiesSet
public void afterPropertiesSet() throws Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
setProperties
public void setProperties(@NotNull Long id, @NotNull Map<? extends PropertyKey,String> properties)
- Specified by:
setProperties
in interfacePropertyUpdater<Long>
-
setProperty
public void setProperty(@NotNull Long id, @NotNull PropertyKey prop, String value)
- Specified by:
setProperty
in interfacePropertyUpdater<Long>
-
deleteProperty
public void deleteProperty(@NotNull Long id, @NotNull PropertyKey propertyKey)
- Specified by:
deleteProperty
in interfacePropertyUpdater<Long>
-
addRole
public void addRole(@NotNull Long id, @NotNull RoleScope roleScope, @NotNull Role role)
Description copied from interface:RolesUpdate
Adds a role with specified scope to an entity with specified id.- Specified by:
addRole
in interfaceRolesUpdate<Long>
- Parameters:
id
- uidroleScope
- scope of the rolerole
- role
-
removeRole
public void removeRole(@NotNull Long id, @NotNull RoleScope roleScope, @NotNull Role role)
Description copied from interface:RolesUpdate
Removes role with specified scope from the entity with specified id.- Specified by:
removeRole
in interfaceRolesUpdate<Long>
- Parameters:
id
- idroleScope
- scope of the rolerole
- role
-
removeRole
public void removeRole(@NotNull Long id, @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:
id
- idrole
- role to remove
-
removeRoles
public void removeRoles(@NotNull Long id, @NotNull RoleScope roleScope)
Description copied from interface:RolesUpdate
Removes all roles with specified scope from the entity with specified id.- Specified by:
removeRoles
in interfaceRolesUpdate<Long>
- Parameters:
id
- idroleScope
- scope of the role
-
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
-
updateUserAccount
public void updateUserAccount(long userId, String username, String name, String email) throws UserNotFoundException, DuplicateUserAccountException, EmptyUsernameException
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 userEmptyUsernameException
- if username is an empty string
-
setPassword
public void setPassword(long userId, String password) throws UserNotFoundException
- Specified by:
setPassword
in interfaceUserUpdate
- Throws:
UserNotFoundException
-
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, 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
-
-