Package com.google.gerrit.common.data

Examples of com.google.gerrit.common.data.GroupReference


        have.add(permission.getName().toLowerCase());

        boolean needRange = GlobalCapability.hasRange(permission.getName());
        List<String> rules = new ArrayList<String>();
        for (PermissionRule rule : sort(permission.getRules())) {
          GroupReference group = rule.getGroup();
          if (group.getUUID() != null) {
            keepGroups.add(group.getUUID());
          }
          rules.add(rule.asString(needRange));
        }
        rc.setStringList(CAPABILITY, null, permission.getName(), rules);
      }
      for (String varName : rc.getNames(CAPABILITY)) {
        if (GlobalCapability.isCapability(varName)
            && !have.contains(varName.toLowerCase())) {
          rc.unset(CAPABILITY, null, varName);
        }
      }
    } else {
      rc.unsetSection(CAPABILITY, null);
    }

    for (AccessSection as : sort(accessSections.values())) {
      String refName = as.getName();
      if (AccessSection.GLOBAL_CAPABILITIES.equals(refName)) {
        continue;
      }

      StringBuilder doNotInherit = new StringBuilder();
      for (Permission perm : sort(as.getPermissions())) {
        if (perm.getExclusiveGroup()) {
          if (0 < doNotInherit.length()) {
            doNotInherit.append(' ');
          }
          doNotInherit.append(perm.getName());
        }
      }
      if (0 < doNotInherit.length()) {
        rc.setString(ACCESS, refName, KEY_GROUP_PERMISSIONS, doNotInherit.toString());
      } else {
        rc.unset(ACCESS, refName, KEY_GROUP_PERMISSIONS);
      }

      Set<String> have = new HashSet<String>();
      for (Permission permission : sort(as.getPermissions())) {
        have.add(permission.getName().toLowerCase());

        boolean needRange = permission.isLabel();
        List<String> rules = new ArrayList<String>();
        for (PermissionRule rule : sort(permission.getRules())) {
          GroupReference group = rule.getGroup();
          if (group.getUUID() != null) {
            keepGroups.add(group.getUUID());
          }
          rules.add(rule.asString(needRange));
        }
        rc.setStringList(ACCESS, refName, permission.getName(), rules);
      }
View Full Code Here


            // 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.
View Full Code Here

    String cn = name.get(name.size() - 1);
    int index = cn.indexOf('=');
    if (index >= 0) {
      cn = cn.substring(index + 1);
    }
    return new GroupReference(new AccountGroup.UUID("ldap:" + dn), "ldap/" + cn);
  }
View Full Code Here

      @GerritServerConfig Config config, String section,
      String subsection, String name) {
    String[] groupNames = config.getStringList(section, subsection, name);
    ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder();
    for (String n : groupNames) {
      GroupReference g = GroupBackends.findBestSuggestion(groupBackend, n);
      if (g == null) {
        log.warn("Group \"{0}\" not in database, skipping.", n);
      } else {
        builder.add(g.getUUID());
      }
    }
    groupIds = builder.build();
  }
View Full Code Here

        .getPermission(permissionName, true) //
        .setExclusiveGroup(true);
  }

  private PermissionRule newRule(ProjectConfig project, AccountGroup.UUID groupUUID) {
    GroupReference group = new GroupReference(groupUUID, groupUUID.get());
    group = project.resolve(group);

    return new PermissionRule(group);
  }
View Full Code Here

    normal.getStyle().setDisplay(Display.BLOCK);
  }

  @Override
  public void setValue(PermissionRule value) {
    GroupReference ref = value.getGroup();

    boolean link;
    if (ref.getUUID() != null && AccountGroup.isInternalGroup(ref.getUUID())) {
      groupNameLink.setText(ref.getName());
      groupNameLink.setTargetHistoryToken(Dispatcher.toGroup(ref.getUUID()));
      link = true;
    } else {
      groupNameSpan.setInnerText(ref.getName());
      groupNameSpan.setTitle(ref.getUUID() != null ? ref.getUUID().get() : "");
      link = false;
    }

    deletedGroupName.setInnerText(ref.getName());
    groupNameLink.setVisible(link);
    UIObject.setVisible(groupNameSpan, !link);
  }
View Full Code Here

    });
  }

  @UiHandler("addRule")
  void onAddGroupByClick(ClickEvent event) {
    GroupReference ref = groupToAdd.getValue();
    if (ref != null) {
      addGroup(ref);
    } else {
      groupToAdd.setFocus(true);
    }
View Full Code Here

    }
  }

  @UiHandler("groupToAdd")
  void onAddGroupByEnter(SelectionEvent<GroupReference> event) {
    GroupReference ref = event.getSelectedItem();
    if (ref != null) {
      addGroup(ref);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.gerrit.common.data.GroupReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.