Search in sources :

Example 26 with InternalGroup

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

the class AccountGroupUUIDHandler method parseArguments.

@Override
public final int parseArguments(Parameters params) throws CmdLineException {
    final String n = params.getParameter(0);
    AccountGroup.UUID uuid = AccountGroup.uuid(n);
    if (groupBackend.handles(uuid)) {
        GroupDescription.Basic d = groupBackend.get(uuid);
        if (d != null) {
            setter.addValue(uuid);
            return 1;
        }
    }
    // Might be a numeric AccountGroup.Id. -> Internal group.
    if (n.matches("^[1-9][0-9]*$")) {
        try {
            AccountGroup.Id groupId = AccountGroup.Id.parse(n);
            Optional<InternalGroup> groupInternal = groupCache.get(groupId);
            if (groupInternal.isPresent()) {
                uuid = new InternalGroupDescription(groupInternal.get()).getGroupUUID();
                setter.addValue(uuid);
                return 1;
            }
        } catch (IllegalArgumentException e) {
        // Ignored
        }
    }
    GroupReference group = GroupBackends.findExactSuggestion(groupBackend, n);
    if (group == null) {
        throw new CmdLineException(owner, localizable("Group \"%s\" does not exist"), n);
    }
    setter.addValue(group.getUUID());
    return 1;
}
Also used : GroupDescription(com.google.gerrit.entities.GroupDescription) InternalGroupDescription(com.google.gerrit.server.group.InternalGroupDescription) InternalGroupDescription(com.google.gerrit.server.group.InternalGroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference) CmdLineException(org.kohsuke.args4j.CmdLineException) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 27 with InternalGroup

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

the class AbstractDaemonTest method assertGroupDoesNotExist.

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

Example 28 with InternalGroup

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

the class LuceneGroupIndex method add.

@Override
void add(Document doc, Values<InternalGroup> values) {
    // Add separate DocValues field for the field that is needed for sorting.
    FieldDef<InternalGroup, ?> f = values.getField();
    if (f == UUID) {
        String value = (String) getOnlyElement(values.getValues());
        doc.add(new SortedDocValuesField(UUID_SORT_FIELD, new BytesRef(value)));
    }
    super.add(doc, values);
}
Also used : SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) BytesRef(org.apache.lucene.util.BytesRef) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 29 with InternalGroup

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

the class GroupsOnInit method addGroupMemberInNoteDb.

private void addGroupMemberInNoteDb(Repository repository, AccountGroup.UUID groupUuid, Account account) throws IOException, ConfigInvalidException, NoSuchGroupException {
    GroupConfig groupConfig = GroupConfig.loadForGroup(allUsers, repository, groupUuid);
    InternalGroup group = groupConfig.getLoadedGroup().orElseThrow(() -> new NoSuchGroupException(groupUuid));
    GroupDelta groupDelta = getMemberAdditionDelta(account);
    AuditLogFormatter auditLogFormatter = getAuditLogFormatter(account);
    groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
    commit(repository, groupConfig, group.getCreatedOn());
}
Also used : GroupConfig(com.google.gerrit.server.group.db.GroupConfig) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) AuditLogFormatter(com.google.gerrit.server.group.db.AuditLogFormatter) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 30 with InternalGroup

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

the class InitAdminUser method postRun.

@Override
public void postRun() throws Exception {
    if (!accounts.hasAnyAccount()) {
        welcome();
    }
    AuthType authType = flags.cfg.getEnum(AuthType.values(), "auth", null, "type", null);
    if (authType != AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
        return;
    }
    if (!accounts.hasAnyAccount()) {
        ui.header("Gerrit Administrator");
        if (ui.yesno(true, "Create administrator user")) {
            Account.Id id = Account.id(sequencesOnInit.nextAccountId());
            String username = ui.readString("admin", "username");
            String name = ui.readString("Administrator", "name");
            String httpPassword = ui.readString("secret", "HTTP password");
            AccountSshKey sshKey = readSshKey(id);
            String email = readEmail(sshKey);
            List<ExternalId> extIds = new ArrayList<>(2);
            extIds.add(externalIdFactory.createUsername(username, id, httpPassword));
            if (email != null) {
                extIds.add(externalIdFactory.createEmail(id, email));
            }
            externalIds.insert("Add external IDs for initial admin user", extIds);
            Account persistedAccount = accounts.insert(Account.builder(id, TimeUtil.now()).setFullName(name).setPreferredEmail(email));
            // Only two groups should exist at this point in time and hence iterating over all of them
            // is cheap.
            Optional<GroupReference> adminGroupReference = groupsOnInit.getAllGroupReferences().filter(group -> group.getName().equals("Administrators")).findAny();
            if (!adminGroupReference.isPresent()) {
                throw new NoSuchGroupException("Administrators");
            }
            GroupReference adminGroup = adminGroupReference.get();
            groupsOnInit.addGroupMember(adminGroup.getUUID(), persistedAccount);
            if (sshKey != null) {
                VersionedAuthorizedKeysOnInit authorizedKeys = authorizedKeysFactory.create(id).load();
                authorizedKeys.addKey(sshKey.sshPublicKey());
                authorizedKeys.save("Add SSH key for initial admin user\n");
            }
            AccountState as = AccountState.forAccount(persistedAccount, extIds);
            for (AccountIndex accountIndex : accountIndexCollection.getWriteIndexes()) {
                accountIndex.replace(as);
            }
            InternalGroup adminInternalGroup = groupsOnInit.getExistingGroup(adminGroup);
            for (GroupIndex groupIndex : groupIndexCollection.getWriteIndexes()) {
                groupIndex.replace(adminInternalGroup);
            }
        }
    }
}
Also used : InternalGroup(com.google.gerrit.entities.InternalGroup) AuthType(com.google.gerrit.extensions.client.AuthType) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) Inject(com.google.inject.Inject) GroupIndexCollection(com.google.gerrit.server.index.group.GroupIndexCollection) InitStep(com.google.gerrit.pgm.init.api.InitStep) EmailValidator(org.apache.commons.validator.routines.EmailValidator) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) AccountIndex(com.google.gerrit.server.index.account.AccountIndex) ExternalIdFactory(com.google.gerrit.server.account.externalids.ExternalIdFactory) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) Path(java.nio.file.Path) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Account(com.google.gerrit.entities.Account) AccountIndexCollection(com.google.gerrit.server.index.account.AccountIndexCollection) IOException(java.io.IOException) GroupReference(com.google.gerrit.entities.GroupReference) List(java.util.List) AccountSshKey(com.google.gerrit.server.account.AccountSshKey) Paths(java.nio.file.Paths) Optional(java.util.Optional) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) GroupIndex(com.google.gerrit.server.index.group.GroupIndex) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) AccountState(com.google.gerrit.server.account.AccountState) SequencesOnInit(com.google.gerrit.pgm.init.api.SequencesOnInit) InitFlags(com.google.gerrit.pgm.init.api.InitFlags) Account(com.google.gerrit.entities.Account) AccountIndex(com.google.gerrit.server.index.account.AccountIndex) AccountSshKey(com.google.gerrit.server.account.AccountSshKey) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ArrayList(java.util.ArrayList) AccountState(com.google.gerrit.server.account.AccountState) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) InternalGroup(com.google.gerrit.entities.InternalGroup) GroupIndex(com.google.gerrit.server.index.group.GroupIndex) AuthType(com.google.gerrit.extensions.client.AuthType) GroupReference(com.google.gerrit.entities.GroupReference)

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