Search in sources :

Example 1 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class GroupOperationsImpl method createNewGroup.

private AccountGroup.UUID createNewGroup(TestGroupCreation groupCreation) throws ConfigInvalidException, IOException {
    InternalGroupCreation internalGroupCreation = toInternalGroupCreation(groupCreation);
    GroupDelta groupDelta = toGroupDelta(groupCreation);
    InternalGroup internalGroup = groupsUpdate.createGroup(internalGroupCreation, groupDelta);
    return internalGroup.getGroupUUID();
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 2 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class ServiceUserClassifierImpl method isServiceUser.

@Override
public boolean isServiceUser(Account.Id user) {
    Optional<InternalGroup> maybeGroup = groupCache.get(AccountGroup.nameKey(SERVICE_USERS));
    if (!maybeGroup.isPresent()) {
        return false;
    }
    List<AccountGroup.UUID> toTraverse = new ArrayList<>();
    toTraverse.add(maybeGroup.get().getGroupUUID());
    Set<AccountGroup.UUID> seen = new HashSet<>();
    while (!toTraverse.isEmpty()) {
        InternalGroup currentGroup = groupCache.get(toTraverse.remove(0)).orElseThrow(() -> new IllegalStateException("invalid subgroup"));
        if (seen.contains(currentGroup.getGroupUUID())) {
            logger.atFine().log("Skipping %s because it's a cyclic subgroup", currentGroup.getGroupUUID());
            continue;
        }
        seen.add(currentGroup.getGroupUUID());
        if (currentGroup.getMembers().contains(user)) {
            // The user is a member of the 'Service Users' group or a subgroup.
            return true;
        }
        boolean hasExternalSubgroup = currentGroup.getSubgroups().stream().anyMatch(g -> !internalGroupBackend.handles(g));
        if (hasExternalSubgroup) {
            // memberships.
            return identifiedUserFactory.create(user).getEffectiveGroups().contains(maybeGroup.get().getGroupUUID());
        }
        toTraverse.addAll(currentGroup.getSubgroups());
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) InternalGroup(com.google.gerrit.entities.InternalGroup) HashSet(java.util.HashSet)

Example 3 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method group.

protected InternalGroup group(String groupName) {
    InternalGroup group = groupCache.get(AccountGroup.nameKey(groupName)).orElse(null);
    assertWithMessage(groupName).that(group).isNotNull();
    return group;
}
Also used : InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 4 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method groupRef.

protected GroupReference groupRef(String groupName) {
    InternalGroup group = groupCache.get(AccountGroup.nameKey(groupName)).orElse(null);
    assertThat(group).isNotNull();
    return GroupReference.create(group.getGroupUUID(), group.getName());
}
Also used : InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 5 with InternalGroup

use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method group.

protected InternalGroup group(AccountGroup.UUID groupUuid) {
    InternalGroup group = groupCache.get(groupUuid).orElse(null);
    assertWithMessage(groupUuid.get()).that(group).isNotNull();
    return group;
}
Also used : InternalGroup(com.google.gerrit.entities.InternalGroup)

Aggregations

InternalGroup (com.google.gerrit.entities.InternalGroup)41 AccountGroup (com.google.gerrit.entities.AccountGroup)18 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)6 AccountGroupMemberAudit (com.google.gerrit.entities.AccountGroupMemberAudit)5 GroupReference (com.google.gerrit.entities.GroupReference)5 Account (com.google.gerrit.entities.Account)4 AccountGroupByIdAudit (com.google.gerrit.entities.AccountGroupByIdAudit)4 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)4 Instant (java.time.Instant)4 GroupDescription (com.google.gerrit.entities.GroupDescription)3 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)3 InternalGroupDescription (com.google.gerrit.server.group.InternalGroupDescription)3 GroupDelta (com.google.gerrit.server.group.db.GroupDelta)3 HashSet (java.util.HashSet)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)2 TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)2 IOException (java.io.IOException)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2