Class UserGroupImpl

  • All Implemented Interfaces:
    Comparable<UserGroup>, SUserGroup, UserGroup, UserGroupEx, Loggable, NotificationRulesHolder, AuthorityHolder, RolesHolder, RolesHolderEx, PropertyHolder, SPropertyHolder
    Direct Known Subclasses:
    AllUsersGroup

    public class UserGroupImpl
    extends Proxyfied<UserGroupEx>
    implements UserGroupEx
    User group implementation. Thread-safe.

    Caveat (for future development): this class and UserGroupManagerImpl use read-write locks for thread-safety. Unfortunately, sometimes nested locks are required (for instance, in setName(String)). Hence a proper care should be exercised to avoid dead-locks.

    I use the following convention: in case of nested locking USERGROUP_LOCK should be locked first.

    If you wish to add a new property to user groups (like subgroups, or notification rules, etc), and you want to cache it, make sure that:

    • the data is loaded from DB in UserGroupImpl(java.lang.String, java.lang.String, java.lang.String, jetbrains.buildServer.groups.UserGroupManager, jetbrains.buildServer.users.UserModel, jetbrains.buildServer.users.impl.RolesConverter, jetbrains.buildServer.serverSide.SecurityContextEx, jetbrains.buildServer.serverSide.auth.RolesManager, jetbrains.buildServer.notification.UserGroupNotificationRulesManager, jetbrains.buildServer.groups.impl.UserGroupUpdater, jetbrains.buildServer.groups.impl.UserGroupRoleUpdater, jetbrains.buildServer.groups.impl.UserGroupUserUpdater, jetbrains.buildServer.groups.impl.UserGroupSubgroupUpdater, jetbrains.buildServer.groups.impl.UserGroupPropertyLoader, jetbrains.buildServer.groups.impl.UserGroupPropertyUpdater, jetbrains.buildServer.serverSide.ProjectManagerEx, jetbrains.buildServer.serverSide.audit.AuditLogFactory, jetbrains.buildServer.groups.impl.UserGroupsCrossNodesEvents, jetbrains.buildServer.util.EventDispatcher<jetbrains.buildServer.groups.UserGroupListener>) c'tor;
    • the data is removed from DB in dispose().
    Otherwise you'll have special effects when the build server is reloaded, or when a user group is deleted, and then created again with same key.
    Author:
    Maxim Podkolzine (maxim.podkolzine@jetbrains.com)
    • Method Detail

      • getKey

        @NotNull
        public String getKey()
        General user group data.
        Specified by:
        getKey in interface UserGroup
        Returns:
        group key
      • getName

        @NotNull
        public String getName()
        Description copied from interface: UserGroup
        Returns a displayable name of this group. The name is unique among all groups, but in contrast with group key is modifiable.
        Specified by:
        getName in interface UserGroup
        Returns:
        group name
      • setName

        public void setName​(@NotNull
                            String name)
                     throws UserGroupException
        Description copied from interface: SUserGroup
        Sets the group name.

        Note: group name must be unique among all user groups. If name already exists, an exception is thrown.

        The name cannot be empty and cannot exceed 255 characters.

        Specified by:
        setName in interface SUserGroup
        Parameters:
        name - the new group name
        Throws:
        UserGroupException - if name already exists, or is empty, or is too long
        See Also:
        UserGroup.getName()
      • getDescription

        @NotNull
        public String getDescription()
        Description copied from interface: UserGroup
        Returns a description of this group.
        Specified by:
        getDescription in interface UserGroup
        Returns:
        group description
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • removeSubgroup

        @Secured("MANAGE_USERGROUP")
        public void removeSubgroup​(@NotNull
                                   UserGroup group)
        Description copied from interface: SUserGroup
        Removes a direct subgroup. Does nothing if the subgroup is included indirectly.
        Specified by:
        removeSubgroup in interface SUserGroup
        Parameters:
        group - a subgroup to remove
      • addParent

        public void addParent​(@NotNull
                              UserGroup parent)
        Description copied from interface: UserGroupEx
        Adds the parent group.

        Do not call this method directly! It should be consistent with addSubgroup.

        Specified by:
        addParent in interface UserGroupEx
        Parameters:
        parent - the parent to add
      • removeParent

        public void removeParent​(@NotNull
                                 UserGroup parent)
        Description copied from interface: UserGroupEx
        Removes the parent group.

        Do not call this method directly! It should be consistent with removeSubgroup.

        Specified by:
        removeParent in interface UserGroupEx
        Parameters:
        parent - the parent to remove
      • hasParents

        public boolean hasParents()
        Description copied from interface: UserGroupEx
        Returns whether this group has parent groups. Using this method is faster than !getParentGroups().isEmpty()
        Specified by:
        hasParents in interface UserGroupEx
        Returns:
        true if this group has parent groups
      • addUser

        public void addUser​(@NotNull
                            User user)
        Users.
        Specified by:
        addUser in interface SUserGroup
        Parameters:
        user - the user to add
      • removeUser

        public void removeUser​(@NotNull
                               User user)
                        throws UserGroupException
        Description copied from interface: SUserGroup
        Removes a user from this group. Does nothing if the user is not included into this group directly.

        The user isn't allowed to remove himself from any group.

        Specified by:
        removeUser in interface SUserGroup
        Parameters:
        user - a user to remove
        Throws:
        UserGroupException - if user is the authority holder, trying to remove himself
      • containsUserDirectly

        public boolean containsUserDirectly​(@NotNull
                                            User user)
        Specified by:
        containsUserDirectly in interface UserGroup
        Parameters:
        user - user to check
        Returns:
        true if this group contains user directly (user is returned by getDirectUsers)
      • getUsersNumber

        public int getUsersNumber()
        Description copied from interface: UserGroupEx
        Returns the number of (direct) users in this group. Much more effective than getDirectUsers().size().
        Specified by:
        getUsersNumber in interface UserGroupEx
        Returns:
        the number of users in the group
      • getPropertyValue

        @Nullable
        public String getPropertyValue​(PropertyKey propertyKey)
        Properties.
        Specified by:
        getPropertyValue in interface PropertyHolder
        Parameters:
        propertyKey - value of the property with specified key
        Returns:
        value of the property with specified key
      • getBooleanProperty

        public boolean getBooleanProperty​(PropertyKey propertyKey)
        Description copied from interface: PropertyHolder
        Returns value of the boolean property
        Specified by:
        getBooleanProperty in interface PropertyHolder
        Parameters:
        propertyKey - property key
        Returns:
        value
      • setProperties

        public boolean setProperties​(@NotNull
                                     Map<? extends PropertyKey,​String> properties)
        Description copied from interface: SPropertyHolder
        Updates the specified properties. Only those properties will be updated which keys are specified in the properties map. All other properties will be left intact.
        Specified by:
        setProperties in interface SPropertyHolder
        Parameters:
        properties - properties
        Returns:
        true if at least one property was changed, false otherwise
      • setProperty

        public boolean setProperty​(@NotNull
                                   PropertyKey propertyKey,
                                   String value)
        Description copied from interface: SPropertyHolder
        Sets a property with specified key and value.
        Specified by:
        setProperty in interface SPropertyHolder
        Parameters:
        propertyKey - property key
        value - value of the property
        Returns:
        true if the property value was actually changed, false otherwise
      • deleteProperty

        public boolean deleteProperty​(@NotNull
                                      PropertyKey propertyKey)
        Description copied from interface: SPropertyHolder
        Deletes a property with specified key.
        Specified by:
        deleteProperty in interface SPropertyHolder
        Parameters:
        propertyKey - property key
        Returns:
        true if the property was actually deleted, false otherwise
      • setGroupProperties

        public void setGroupProperties​(@NotNull
                                       Map<? extends PropertyKey,​String> properties)
                                throws UserGroupException
        Description copied from interface: SUserGroup
        Updates properties of this group. Only those properties will be updated which keys are specified in the properties map. All other properties will be left intact.
        Specified by:
        setGroupProperties in interface SUserGroup
        Parameters:
        properties - properties
        Throws:
        UserGroupException - if specified group no longer exists
      • getUnfilteredScopes

        @NotNull
        public Collection<RoleScope> getUnfilteredScopes()
        Specified by:
        getUnfilteredScopes in interface RolesHolderEx
        Returns:
        unfiltered role scopes for this roles holder, unfiltered scopes include scopes for projects current user from security context does not have access too
      • getUnfilteredRoles

        @NotNull
        public Map<RoleScope,​Collection<Role>> getUnfilteredRoles()
        Specified by:
        getUnfilteredRoles in interface RolesHolderEx
        Returns:
        unfiltered map of role for this roles holder, unfiltered map include roles for projects current user from security context does not have access too
      • addRole

        public void addRole​(@NotNull
                            RoleScope scope,
                            @NotNull
                            Role role)
        Description copied from interface: RolesHolder
        Adds role with specified scope
        Specified by:
        addRole in interface RolesHolder
        Parameters:
        scope - scope of the role
        role - role
      • removeRole

        public void removeRole​(@NotNull
                               RoleScope scope,
                               @NotNull
                               Role role)
        Description copied from interface: RolesHolder
        Removes role with specified scope
        Specified by:
        removeRole in interface RolesHolder
        Parameters:
        scope - scope of the role
        role - role
      • removeRole

        public void removeRole​(@NotNull
                               Role role)
        Description copied from interface: RolesHolder
        Removes specified role. If the role is associated with several scopes all of these roles will be removed.
        Specified by:
        removeRole in interface RolesHolder
        Parameters:
        role - role to remove
      • removeRoles

        public void removeRoles​(@NotNull
                                RoleScope scope)
        Description copied from interface: RolesHolder
        Removes all of the roles having the specified scope.
        Specified by:
        removeRoles in interface RolesHolder
        Parameters:
        scope - scope of the role
      • isSystemAdministratorRoleGranted

        public boolean isSystemAdministratorRoleGranted()
        Description copied from interface: RolesHolder
        Returns true if this roles holder contains system administrator role granted directly or inherited via parent holders. Same as:
        isSystemAdministratorRoleGrantedDirectly() || isSystemAdministratorRoleInherited()
        Specified by:
        isSystemAdministratorRoleGranted in interface RolesHolder
        Returns:
        see above.
      • isSystemAdministratorRoleGrantedDirectly

        public boolean isSystemAdministratorRoleGrantedDirectly()
        Description copied from interface: RolesHolder
        Returns true if this roles holder contains system administrator role granted directly.
        Specified by:
        isSystemAdministratorRoleGrantedDirectly in interface RolesHolder
        Returns:
        see above.
      • isSystemAdministratorRoleInherited

        public boolean isSystemAdministratorRoleInherited()
        Description copied from interface: RolesHolder
        Returns true if one of the parents (transitively) of this roles holder contains system administrator role.
        Specified by:
        isSystemAdministratorRoleInherited in interface RolesHolder
        Returns:
        see above
      • isPermissionGrantedGlobally

        public boolean isPermissionGrantedGlobally​(@NotNull
                                                   Permission permission)
        Authority.
        Specified by:
        isPermissionGrantedGlobally in interface AuthorityHolder
        Parameters:
        permission - permission to check
        Returns:
        true or false
      • getGlobalPermissions

        @NotNull
        public Permissions getGlobalPermissions()
        Description copied from interface: AuthorityHolder
        Returns all granted non-project related permissions and all project-related permissions granted globally
        Specified by:
        getGlobalPermissions in interface AuthorityHolder
        Returns:
        see above
      • getProjectsPermissions

        @NotNull
        public Map<String,​Permissions> getProjectsPermissions()
        Description copied from interface: AuthorityHolder
        Returns map of project-related permissions that were granted for a particular project. Project internal id is used as the key.
        Specified by:
        getProjectsPermissions in interface AuthorityHolder
        Returns:
        map of project permissions
      • isPermissionGrantedForProject

        public boolean isPermissionGrantedForProject​(@NotNull
                                                     String projectId,
                                                     @NotNull
                                                     Permission permission)
        Description copied from interface: AuthorityHolder
        Returns true if permission is granted for a project, i.e. the result is true if there is a project related permission granted globally or for specified project
        Specified by:
        isPermissionGrantedForProject in interface AuthorityHolder
        Parameters:
        projectId - project internal id
        permission - permission to check
        Returns:
        see above
      • isPermissionGrantedForAnyProject

        public boolean isPermissionGrantedForAnyProject​(@NotNull
                                                        Permission permission)
        Description copied from interface: AuthorityHolder
        Returns true if specified permission is granted for at least one project
        Specified by:
        isPermissionGrantedForAnyProject in interface AuthorityHolder
        Parameters:
        permission - permission to check
        Returns:
        see above
      • getPermissionsGrantedForProject

        @NotNull
        public Permissions getPermissionsGrantedForProject​(@NotNull
                                                           String projectId)
        Description copied from interface: AuthorityHolder
        Returns all permissions granted for particular project. These include permissions granted specifically for the specified project and granted global project-related permissions (i.e. permissions supporting project association Permission.isProjectAssociationSupported()).
        Specified by:
        getPermissionsGrantedForProject in interface AuthorityHolder
        Parameters:
        projectId - project internal id
        Returns:
        all granted permissions for particular project
      • getPermissionsGrantedForAllProjects

        @NotNull
        public Permissions getPermissionsGrantedForAllProjects​(@NotNull
                                                               Collection<String> projectIds)
        Description copied from interface: AuthorityHolder
        Returns all permissions granted for all projects from the collection. These include permissions granted specifically for the specified projects and granted global project-related permissions (i.e. permissions supporting project association Permission.isProjectAssociationSupported()).
        Specified by:
        getPermissionsGrantedForAllProjects in interface AuthorityHolder
        Parameters:
        projectIds - collection of project internal ids
        Returns:
        all granted permissions for all projects
      • getPermissionsGrantedForAnyOfProjects

        @NotNull
        public Permissions getPermissionsGrantedForAnyOfProjects​(@NotNull
                                                                 Collection<String> projectIds)
        Description copied from interface: AuthorityHolder
        Returns union of permissions granted for projects from the collection. These include permissions granted specifically for the specified projects and granted global project-related permissions (i.e. permissions supporting project association Permission.isProjectAssociationSupported()).
        Specified by:
        getPermissionsGrantedForAnyOfProjects in interface AuthorityHolder
        Parameters:
        projectIds - collection of project internal ids
        Returns:
        all granted permissions for all projects
      • getAssociatedUser

        @Nullable
        public User getAssociatedUser()
        Description copied from interface: AuthorityHolder
        Returns the user object associated with the principal.
        Specified by:
        getAssociatedUser in interface AuthorityHolder
        Returns:
        may be null if the authority holder is not a user.
      • hasAllPermissionsOf

        public boolean hasAllPermissionsOf​(@NotNull
                                           AuthorityHolder authorityHolder)
        Description copied from interface: AuthorityHolder
        Returns true if this authority holder has all permissions of another authority holder.
        Specified by:
        hasAllPermissionsOf in interface AuthorityHolder
        Returns:
        see above
      • calculatePermissions

        public void calculatePermissions​(@NotNull
                                         BitSet globalPerms,
                                         @NotNull
                                         Map<String,​Permissions> projectPerms)
        Description copied from interface: UserGroupEx
        Calculates the permissions of this user group and fills globalPerms and projectPerms with results.
        Specified by:
        calculatePermissions in interface UserGroupEx
        Parameters:
        globalPerms - will contain global permissions
        projectPerms - will contain project permissions
      • isAllUsersGroup

        public boolean isAllUsersGroup()
        Description copied from interface: UserGroupEx
        Returns true, if the specified group is the all-users group.
        Specified by:
        isAllUsersGroup in interface UserGroupEx
        Returns:
        true if the specified group is the all-users group, false otherwise
      • updateInfo

        public void updateInfo()
        Description copied from interface: UserGroupEx
        Reload main group info (name and description) from the database
        Specified by:
        updateInfo in interface UserGroupEx
      • updateProperties

        public void updateProperties()
        Description copied from interface: UserGroupEx
        Reload group properties from the database
        Specified by:
        updateProperties in interface UserGroupEx
      • updateUsers

        public void updateUsers()
        Description copied from interface: UserGroupEx
        Reload group users from the database
        Specified by:
        updateUsers in interface UserGroupEx
      • updateRoles

        public void updateRoles()
        Description copied from interface: UserGroupEx
        Reload group roles from the database
        Specified by:
        updateRoles in interface UserGroupEx
      • updateSubgroups

        public void updateSubgroups()
        Description copied from interface: UserGroupEx
        Reload group direct subgroups from the database
        Specified by:
        updateSubgroups in interface UserGroupEx
      • resetRoles

        public void resetRoles()
        Description copied from interface: UserGroupEx
        Resets internal roles cache
        Specified by:
        resetRoles in interface UserGroupEx
      • applyOrder

        public void applyOrder​(@NotNull
                               String notifierType,
                               @NotNull
                               long[] ruleIds)
        Description copied from interface: NotificationRulesHolder
        Sorts the notification rules in the specified order.
        Specified by:
        applyOrder in interface NotificationRulesHolder
        Parameters:
        notifierType - type of the notifier
        ruleIds - ids of the rules in the required order
      • describe

        @NotNull
        public String describe​(boolean verbose)
        Specified by:
        describe in interface Loggable
        Parameters:
        verbose - verbosity of object description
        Returns:
        description of this object. If verbose is true, description should have mode details.
      • cleanupGroup

        public void cleanupGroup()
        Description copied from interface: UserGroupEx
        Removes from the group users, which were removed on the server
        Specified by:
        cleanupGroup in interface UserGroupEx