Class MockGroupManager

java.lang.Object
com.atlassian.jira.security.groups.MockGroupManager
All Implemented Interfaces:
GroupManager

public class MockGroupManager extends Object implements GroupManager
Since:
v4.3
  • Constructor Details

    • MockGroupManager

      public MockGroupManager()
    • MockGroupManager

      public MockGroupManager(com.atlassian.crowd.embedded.api.CrowdService crowdService)
  • Method Details

    • getAllGroups

      public Collection<com.atlassian.crowd.embedded.api.Group> getAllGroups()
      Description copied from interface: GroupManager
      Get all groups.
      Specified by:
      getAllGroups in interface GroupManager
      Returns:
      Collection of all Groups.
    • groupExists

      public boolean groupExists(String groupName)
      Description copied from interface: GroupManager
      Returns true if the given group name exists.
      Specified by:
      groupExists in interface GroupManager
      Parameters:
      groupName - The group name.
      Returns:
      true if the given group name exists.
    • groupExists

      public boolean groupExists(@Nonnull com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: GroupManager
      Returns true if the given group exists.
      Specified by:
      groupExists in interface GroupManager
      Parameters:
      group - The group.
      Returns:
      true if the given group exists.
    • createGroup

      public com.atlassian.crowd.embedded.api.Group createGroup(String groupName)
      Description copied from interface: GroupManager
      Create a group with the given name.
      Specified by:
      createGroup in interface GroupManager
      Parameters:
      groupName - The group name.
      Returns:
      the newly created Group.
    • throwExceptionOnCreateGroup

      public <T extends Exception> void throwExceptionOnCreateGroup(String groupName, Exception cause)
    • getGroup

      public com.atlassian.crowd.embedded.api.Group getGroup(String groupName)
      Description copied from interface: GroupManager
      Returns the Group for this groupName, else null if no such Group exists.
      Specified by:
      getGroup in interface GroupManager
      Parameters:
      groupName - The group name.
      Returns:
      The Group for this groupName, else null if no such Group exists.
    • getGroupEvenWhenUnknown

      public com.atlassian.crowd.embedded.api.Group getGroupEvenWhenUnknown(String groupName)
      Description copied from interface: GroupManager
      Returns the Group for this groupName, if no such Group exists then a proxy unknown immutable Group object is returned.
      Specified by:
      getGroupEvenWhenUnknown in interface GroupManager
      Parameters:
      groupName - The group name.
      Returns:
      The Group for this groupName.
    • getGroupObject

      public com.atlassian.crowd.embedded.api.Group getGroupObject(String groupName)
      Description copied from interface: GroupManager
      Returns the Group for this groupName, else null if no such Group exists.

      Legacy synonym for GroupManager.getGroup(String).

      Specified by:
      getGroupObject in interface GroupManager
      Parameters:
      groupName - The group name.
      Returns:
      The Group for this groupName, else null if no such Group exists.
      See Also:
    • isUserInGroup

      public boolean isUserInGroup(@Nullable String username, @Nullable String groupName)
      Description copied from interface: GroupManager
      Returns true if the user is a member of the group.

      Note that if the username or groupname is null, then it will return false.

      Performance note: If you have a full user object, then calling one of the other isUserInGroup() methods directly is more efficient.

      Specified by:
      isUserInGroup in interface GroupManager
      Parameters:
      username - user to inspect.
      groupName - group to inspect.
      Returns:
      true if and only if the user is a direct or indirect (nested) member of the group.
      See Also:
    • isUserInGroup

      public boolean isUserInGroup(@Nullable ApplicationUser user, @Nullable com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: GroupManager
      Returns true if the user is a member of the group.

      Note that if the User or Group object is null, then it will return false. This was done to retain consistency with the old OSUser behaviour of User.inGroup() and Group.containsUser()

      Specified by:
      isUserInGroup in interface GroupManager
      Parameters:
      user - user to inspect.
      group - group to inspect.
      Returns:
      true if and only if the user is a direct or indirect (nested) member of the group.
    • isUserInGroup

      public boolean isUserInGroup(@Nullable ApplicationUser user, @Nullable String groupName)
      Description copied from interface: GroupManager
      Returns true if the user is a member of the named group.

      If you already have the user object, then this method is faster than the alternative of passing in the username because it saves on an unnecessary user lookup to find the correct User Directory.

      Specified by:
      isUserInGroup in interface GroupManager
      Parameters:
      user - user to inspect.
      groupName - group to inspect.
      Returns:
      true if and only if the user is a direct or indirect (nested) member of the group.
    • isUserInGroups

      public boolean isUserInGroups(@Nullable ApplicationUser user, @Nullable Set<String> groupNames)
      Description copied from interface: GroupManager
      Returns true if the user is a member of at least one of the named groups.
      Specified by:
      isUserInGroups in interface GroupManager
      Parameters:
      user - user to inspect.
      groupNames - groups to inspect.
      Returns:
      true if and only if the user is a direct or indirect (nested) member of the groups.
    • getUsersInGroup

      public Collection<ApplicationUser> getUsersInGroup(String groupName)
      Description copied from interface: GroupManager
      Returns all the users in a group.
      Specified by:
      getUsersInGroup in interface GroupManager
      Parameters:
      groupName - The group
      Returns:
      all the users that belongs to the group.
    • getUsersInGroup

      public Collection<ApplicationUser> getUsersInGroup(String groupName, Boolean includeInactive)
      Description copied from interface: GroupManager
      Returns all the users in a group. Allows for additional filtering by the active flag of a user.
      Specified by:
      getUsersInGroup in interface GroupManager
      Parameters:
      groupName - The group
      includeInactive - if set to true inactive users will be returned as well
      Returns:
      all the users that belongs to the group.
    • getUsersInGroup

      public Page<ApplicationUser> getUsersInGroup(String groupName, Boolean active, PageRequest pageRequest)
      Description copied from interface: GroupManager
      Returns a page with users in a group. Users are sorted by name in ascending order.
      Specified by:
      getUsersInGroup in interface GroupManager
      Parameters:
      groupName - name of the group for which users are returned
      active - if set to true inactive users will be returned as well
      pageRequest - parameters of the page to return
      Returns:
      page with the users
    • getUsersInGroup

      public Collection<ApplicationUser> getUsersInGroup(com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: GroupManager
      Returns all the users in a group. This will include nested group members.
      Specified by:
      getUsersInGroup in interface GroupManager
      Parameters:
      group - The group
      Returns:
      all the users that belongs to the group.
    • getUsersInGroupCount

      public int getUsersInGroupCount(com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: GroupManager
      Returns a count of all active users in a group. This will include nested group members.
      Specified by:
      getUsersInGroupCount in interface GroupManager
      Parameters:
      group - The group
      Returns:
      a count of all the users that belongs to the group.
    • getUsersInGroupCount

      public int getUsersInGroupCount(String groupName)
      Description copied from interface: GroupManager
      Returns a count of all active users in a group. This will include nested group members.
      Specified by:
      getUsersInGroupCount in interface GroupManager
      Parameters:
      groupName - The group name
      Returns:
      a count of all the users that belongs to the group.
    • getNamesOfDirectMembersOfGroups

      public List<String> getNamesOfDirectMembersOfGroups(Collection<String> groupNames, int limit)
      Description copied from interface: GroupManager
      Returns a list of all active user names that are direct members in at least one of the supplied groups.
      Specified by:
      getNamesOfDirectMembersOfGroups in interface GroupManager
      Parameters:
      groupNames - A collection of group names to find direct members of
      limit - A maximum number of names to return
      Returns:
      a list of user names
    • filterUsersInAllGroupsDirect

      public Collection<String> filterUsersInAllGroupsDirect(Collection<String> userNames, Collection<String> groupNames)
      Description copied from interface: GroupManager
      Returns a collection of user names for the users that are direct members of every one of the supplied groups.
      Specified by:
      filterUsersInAllGroupsDirect in interface GroupManager
      Parameters:
      userNames - A collection of user names
      groupNames - A collection of groups
      Returns:
      a collection of user names
    • getUserNamesInGroup

      public Collection<String> getUserNamesInGroup(com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: GroupManager
      Returns the names of all the users in a group. This will include nested group members.
      Specified by:
      getUserNamesInGroup in interface GroupManager
      Parameters:
      group - The group
      Returns:
      all the users that belongs to the group.
    • getUserNamesInGroups

      public Collection<String> getUserNamesInGroups(Collection<com.atlassian.crowd.embedded.api.Group> groups)
      Description copied from interface: GroupManager
      Returns the names of all the users in a collection of groups. This will include nested group members.
      Specified by:
      getUserNamesInGroups in interface GroupManager
      Parameters:
      groups - The collection of groups
      Returns:
      all the users that belongs to the group.
    • getUserNamesInGroup

      public Collection<String> getUserNamesInGroup(String groupName)
      Description copied from interface: GroupManager
      Returns the names of all the users in a group. This will include nested group members.
      Specified by:
      getUserNamesInGroup in interface GroupManager
      Parameters:
      groupName - The group
      Returns:
      all the users that belongs to the group.
    • getDirectUsersInGroup

      public Collection<ApplicationUser> getDirectUsersInGroup(com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: GroupManager
      Returns all the users that are direct members of the group. This will NOT include nested group members.
      Specified by:
      getDirectUsersInGroup in interface GroupManager
      Parameters:
      group - The group
      Returns:
      all the users that belongs to the group.
    • getGroupsForUser

      public Collection<com.atlassian.crowd.embedded.api.Group> getGroupsForUser(String userName)
      Description copied from interface: GroupManager
      Returns all the groups that the given user belongs to.
      Specified by:
      getGroupsForUser in interface GroupManager
      Parameters:
      userName - The user
      Returns:
      all the groups that the given user belongs to.
      See Also:
    • getGroupsForUser

      public Collection<com.atlassian.crowd.embedded.api.Group> getGroupsForUser(ApplicationUser user)
      Description copied from interface: GroupManager
      Returns all the groups that the given user belongs to.
      Specified by:
      getGroupsForUser in interface GroupManager
      Parameters:
      user - The user
      Returns:
      all the groups that the given user belongs to.
      See Also:
    • getGroupNamesForUser

      public Collection<String> getGroupNamesForUser(String userName)
      Description copied from interface: GroupManager
      Returns the names of all the groups that the given user belongs to.
      Specified by:
      getGroupNamesForUser in interface GroupManager
      Parameters:
      userName - The user
      Returns:
      all the groups that the given user belongs to.
      See Also:
    • getGroupNamesForUser

      public Collection<String> getGroupNamesForUser(@Nonnull ApplicationUser user)
      Description copied from interface: GroupManager
      Returns the names of all the groups that the given user belongs to.
      Specified by:
      getGroupNamesForUser in interface GroupManager
      Parameters:
      user - The user
      Returns:
      all the groups that the given user belongs to.
      See Also:
    • addUserToGroup

      public void addUserToGroup(ApplicationUser user, com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: GroupManager
      Adds a user as a member of a group.
      Specified by:
      addUserToGroup in interface GroupManager
      Parameters:
      user - The user that will become a member of the group.
      group - The group that will gain a new member.
    • getConnectUsers

      @Deprecated public Set<ApplicationUser> getConnectUsers()
      Deprecated.
      Description copied from interface: GroupManager
      Returns all the connect app users. This will return an empty Set in JIRA Server as connect plugins are only supported in JIRA Cloud. This result does not filter out inactive users.
      Specified by:
      getConnectUsers in interface GroupManager
      Returns:
      all the connect app users.
    • addGroup

      public com.atlassian.crowd.embedded.api.Group addGroup(String groupName)
    • addGroup

      public MockGroupManager addGroup(com.atlassian.crowd.embedded.api.Group group)
    • addMember

      public void addMember(String groupName, String userName)
    • setUserMembership

      public MockGroupManager setUserMembership(ApplicationUser user, com.atlassian.crowd.embedded.api.Group... groups)
    • getAllGroupNames

      public Collection<String> getAllGroupNames()
      Description copied from interface: GroupManager
      Returns the names of all groups or an empty collection if there are no groups.
      Specified by:
      getAllGroupNames in interface GroupManager
      Returns:
      all the groups.