Line data Source code
1 : // Copyright (C) 2012 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.account; 16 : 17 : import com.google.gerrit.entities.AccountGroup; 18 : import java.util.Collections; 19 : import java.util.Set; 20 : 21 : /** 22 : * Represents the set of groups that a single user is part of. 23 : * 24 : * <p>Different accounts systems (eg. LDAP, gerrit groups) provide concrete implementations. 25 : */ 26 : public interface GroupMembership { 27 37 : GroupMembership EMPTY = new ListGroupMembership(Collections.emptySet()); 28 : 29 : /** 30 : * Returns {@code true} when the user this object was created for is a member of the specified 31 : * group. 32 : */ 33 : boolean contains(AccountGroup.UUID groupId); 34 : 35 : /** 36 : * Returns {@code true} when the user this object was created for is a member of any of the 37 : * specified group. 38 : */ 39 : boolean containsAnyOf(Iterable<AccountGroup.UUID> groupIds); 40 : 41 : /** 42 : * Returns a set containing an input member of {@code contains(id)} is true. 43 : * 44 : * <p>This is batch form of contains that returns specific group information. Implementors may 45 : * implement the method as: 46 : * 47 : * <pre> 48 : * Set<AccountGroup.UUID> r = new HashSet<>(); 49 : * for (AccountGroup.UUID id : groupIds) 50 : * if (contains(id)) r.add(id); 51 : * </pre> 52 : */ 53 : Set<AccountGroup.UUID> intersection(Iterable<AccountGroup.UUID> groupIds); 54 : 55 : /** 56 : * Returns the set of groups that can be determined by the implementation. This may not return all 57 : * groups the {@link #contains(AccountGroup.UUID)} would return {@code true} for, but will at 58 : * least contain all top level groups. This restriction stems from the API of some group systems, 59 : * which make it expensive to enumerate the members of a group. 60 : */ 61 : Set<AccountGroup.UUID> getKnownGroups(); 62 : }