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());
}
}
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;
}
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));
}
use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.
the class GroupListTest method byUUID.
@Test
public void byUUID() throws Exception {
AccountGroup.UUID uuid = new AccountGroup.UUID("d96b998f8a66ff433af50befb975d0e2bb6e0999");
GroupReference groupReference = groupList.byUUID(uuid);
assertEquals(uuid, groupReference.getUUID());
assertEquals("Non-Interactive Users", groupReference.getName());
}
use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.
the class GroupListTest method put.
@Test
public void put() {
AccountGroup.UUID uuid = new AccountGroup.UUID("abc");
GroupReference groupReference = new GroupReference(uuid, "Hutzliputz");
groupList.put(uuid, groupReference);
assertEquals(3, groupList.references().size());
GroupReference found = groupList.byUUID(uuid);
assertEquals(groupReference, found);
}
Aggregations