// The LDAP group does not have a DN. Determine if the UUID is used.
toResolve.add(groupUUID);
} else {
toDelete.add(groupId);
namesToDelete.add(name);
GroupReference ref = groupReference(dn);
ldapUUIDMap.put(groupUUID, ref);
}
}
} catch (NamingException e) {
throw new RuntimeException(e);
} finally {
rs.close();
}
} finally {
stmt.close();
}
if (toDelete.isEmpty() && toResolve.isEmpty()) {
return; // No ldap groups. Nothing to do.
}
ui.message("Update LDAP groups to be GroupReferences.");
// Update the groupOwnerUUID for LDAP groups to point to the new UUID.
List<AccountGroup> toUpdate = Lists.newArrayList();
Set<AccountGroup.UUID> resolveToUpdate = Sets.newHashSet();
Map<AccountGroup.UUID, AccountGroup> resolveGroups = Maps.newHashMap();
for (AccountGroup g : db.accountGroups().all()) {
if (ldapUUIDMap.containsKey(g.getGroupUUID())) {
continue; // Ignore the LDAP groups with a valid DN.
} else if (toResolve.contains(g.getGroupUUID())) {
resolveGroups.put(g.getGroupUUID(), g); // Keep the ones to resolve.
continue;
}
GroupReference ref = ldapUUIDMap.get(g.getOwnerGroupUUID());
if (ref != null) {
// Update the owner group UUID to the new ldap UUID scheme.
g.setOwnerGroupUUID(ref.getUUID());
toUpdate.add(g);
} else if (toResolve.contains(g.getOwnerGroupUUID())) {
// The unresolved group is used as an owner.
// Add to the list of LDAP groups to be made INTERNAL.
resolveToUpdate.add(g.getOwnerGroupUUID());
}
}
toResolve.removeAll(resolveToUpdate);
// Update project.config group references to use the new LDAP GroupReference
for (Project.NameKey name : mgr.list()) {
Repository git;
try {
git = mgr.openRepository(name);
} catch (RepositoryNotFoundException e) {
throw new OrmException(e);
} catch (IOException e) {
throw new OrmException(e);
}
try {
MetaDataUpdate md =
new MetaDataUpdate(GitReferenceUpdated.DISABLED, name, git);
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
ProjectConfig config = ProjectConfig.read(md);
// Update the existing refences to the new reference.
boolean updated = false;
for (Map.Entry<AccountGroup.UUID, GroupReference> entry: ldapUUIDMap.entrySet()) {
GroupReference ref = config.getGroup(entry.getKey());
if (ref != null) {
updated = true;
ref.setName(entry.getValue().getName());
ref.setUUID(entry.getValue().getUUID());
config.resolve(ref);
}
}
// Determine if a toResolve group is used and should be made INTERNAL.