Search in sources :

Example 11 with GroupReference

use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.

the class GroupList method resolve.

public GroupReference resolve(GroupReference group) {
    if (group != null) {
        if (group.getUUID() == null || group.getUUID().get() == null) {
            // results, nor return null the set from #uuids.
            return group;
        }
        GroupReference ref = byUUID.get(group.getUUID());
        if (ref != null) {
            return ref;
        }
        byUUID.put(group.getUUID(), group);
    }
    return group;
}
Also used : GroupReference(com.google.gerrit.common.data.GroupReference)

Example 12 with GroupReference

use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.

the class GroupList method parse.

public static GroupList parse(Project.NameKey project, String text, ValidationError.Sink errors) throws IOException {
    List<Row> rows = parse(text, FILE_NAME, TRIM, TRIM, errors);
    Map<AccountGroup.UUID, GroupReference> groupsByUUID = new HashMap<>(rows.size());
    for (Row row : rows) {
        if (row.left == null) {
            log.warn("null field in group list for {}:\n{}", project, text);
            continue;
        }
        AccountGroup.UUID uuid = new AccountGroup.UUID(row.left);
        String name = row.right;
        GroupReference ref = new GroupReference(uuid, name);
        groupsByUUID.put(uuid, ref);
    }
    return new GroupList(groupsByUUID);
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) HashMap(java.util.HashMap) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 13 with GroupReference

use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.

the class ProjectAccessHandler method lookupGroup.

private void lookupGroup(PermissionRule rule) throws NoSuchGroupException {
    GroupReference ref = rule.getGroup();
    if (ref.getUUID() == null) {
        final GroupReference group = GroupBackends.findBestSuggestion(groupBackend, ref.getName());
        if (group == null) {
            throw new NoSuchGroupException(ref.getName());
        }
        ref.setUUID(group.getUUID());
    }
}
Also used : GroupReference(com.google.gerrit.common.data.GroupReference) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 14 with GroupReference

use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.

the class LdapGroupBackend method suggestLdap.

private Set<GroupReference> suggestLdap(String name) {
    if (name.isEmpty()) {
        return Collections.emptySet();
    }
    Set<GroupReference> out = Sets.newTreeSet(GROUP_REF_NAME_COMPARATOR);
    try {
        DirContext ctx = helper.open();
        try {
            // Do exact lookups until there are at least 3 characters.
            name = Rdn.escapeValue(name) + ((name.length() >= 3) ? "*" : "");
            LdapSchema schema = helper.getSchema(ctx);
            ParameterizedString filter = ParameterizedString.asis(schema.groupPattern.replace(GROUPNAME, name).toString());
            Set<String> returnAttrs = new HashSet<>(schema.groupName.getParameterNames());
            Map<String, String> params = Collections.emptyMap();
            for (String groupBase : schema.groupBases) {
                LdapQuery query = new LdapQuery(groupBase, schema.groupScope, filter, returnAttrs);
                for (LdapQuery.Result res : query.query(ctx, params)) {
                    out.add(groupReference(schema.groupName, res));
                }
            }
        } finally {
            try {
                ctx.close();
            } catch (NamingException e) {
                log.warn("Cannot close LDAP query handle", e);
            }
        }
    } catch (NamingException | LoginException e) {
        log.warn("Cannot query LDAP for groups matching requested name", e);
    }
    return out;
}
Also used : DirContext(javax.naming.directory.DirContext) ParameterizedString(com.google.gerrit.common.data.ParameterizedString) ParameterizedString(com.google.gerrit.common.data.ParameterizedString) LdapSchema(com.google.gerrit.server.auth.ldap.Helper.LdapSchema) LoginException(javax.security.auth.login.LoginException) NamingException(javax.naming.NamingException) GroupReference(com.google.gerrit.common.data.GroupReference) HashSet(java.util.HashSet)

Example 15 with GroupReference

use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.

the class GroupListTest method references.

@Test
public void references() throws Exception {
    Collection<GroupReference> result = groupList.references();
    assertEquals(2, result.size());
    AccountGroup.UUID uuid = new AccountGroup.UUID("ebe31c01aec2c9ac3b3c03e87a47450829ff4310");
    GroupReference expected = new GroupReference(uuid, "Administrators");
    assertTrue(result.contains(expected));
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupReference(com.google.gerrit.common.data.GroupReference) Test(org.junit.Test)

Aggregations

GroupReference (com.google.gerrit.common.data.GroupReference)41 PermissionRule (com.google.gerrit.common.data.PermissionRule)11 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)9 AccessSection (com.google.gerrit.common.data.AccessSection)6 Permission (com.google.gerrit.common.data.Permission)6 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)6 IOException (java.io.IOException)6 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)5 OrmException (com.google.gwtorm.server.OrmException)5 Test (org.junit.Test)5 GroupDescription (com.google.gerrit.common.data.GroupDescription)4 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)4 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)3 Project (com.google.gerrit.reviewdb.client.Project)3 PluginConfig (com.google.gerrit.server.config.PluginConfig)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Config (org.eclipse.jgit.lib.Config)3 Repository (org.eclipse.jgit.lib.Repository)3