Added GroupMembership for group membership checks.
This replaces existing uses of a Set to determine membership and will make it possible to integrate with group systems that do not allow efficient enumentation of memberships. Change-Id: Iba9842ca1a355fc100fb4a02d7954d89032cdba0
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Implementations of GroupMembership provide methods to test
|
||||
* the presence of a user in a particular group.
|
||||
*/
|
||||
public interface GroupMembership {
|
||||
|
||||
public static final GroupMembership EMPTY =
|
||||
new ListGroupMembership(Collections.<AccountGroup.UUID>emptySet());
|
||||
|
||||
/**
|
||||
* Returns {@code true} when the user this object was created for is a member
|
||||
* of the specified group.
|
||||
*/
|
||||
boolean contains(AccountGroup.UUID groupId);
|
||||
|
||||
/**
|
||||
* Returns {@code true} when the user this object was created for is a member
|
||||
* of any of the specified group.
|
||||
*/
|
||||
boolean containsAnyOf(Iterable<AccountGroup.UUID> groupIds);
|
||||
|
||||
/**
|
||||
* Returns the set of groups that can be determined by the implementation.
|
||||
* This may not return all groups the {@link #contains(AccountGroup.UUID)}
|
||||
* would return {@code true} for, but will at least contain all top level
|
||||
* groups. This restriction stems from the API of some group systems, which
|
||||
* make it expensive to enumate the members of a group.
|
||||
*/
|
||||
Set<AccountGroup.UUID> getKnownGroups();
|
||||
}
|
||||
Reference in New Issue
Block a user