当前位置: 首页>>代码示例>>Java>>正文


Java PermissionRule类代码示例

本文整理汇总了Java中com.google.gerrit.common.data.PermissionRule的典型用法代码示例。如果您正苦于以下问题:Java PermissionRule类的具体用法?Java PermissionRule怎么用?Java PermissionRule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PermissionRule类属于com.google.gerrit.common.data包,在下文中一共展示了PermissionRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: grant

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
protected void grant(
    Project.NameKey project,
    String ref,
    String permission,
    boolean force,
    AccountGroup.UUID groupUUID)
    throws RepositoryNotFoundException, IOException, ConfigInvalidException {
  try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
    md.setMessage(String.format("Grant %s on %s", permission, ref));
    ProjectConfig config = ProjectConfig.read(md);
    AccessSection s = config.getAccessSection(ref, true);
    Permission p = s.getPermission(permission, true);
    PermissionRule rule = Util.newRule(config, groupUUID);
    rule.setForce(force);
    p.add(rule);
    config.commit(md);
    projectCache.evict(config.getProject());
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:20,代码来源:AbstractDaemonTest.java

示例2: grantLabel

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
protected void grantLabel(
    String label,
    int min,
    int max,
    Project.NameKey project,
    String ref,
    boolean force,
    AccountGroup.UUID groupUUID,
    boolean exclusive)
    throws RepositoryNotFoundException, IOException, ConfigInvalidException {
  String permission = Permission.LABEL + label;
  try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
    md.setMessage(String.format("Grant %s on %s", permission, ref));
    ProjectConfig config = ProjectConfig.read(md);
    AccessSection s = config.getAccessSection(ref, true);
    Permission p = s.getPermission(permission, true);
    p.setExclusiveGroup(exclusive);
    PermissionRule rule = Util.newRule(config, groupUUID);
    rule.setForce(force);
    rule.setMin(min);
    rule.setMax(max);
    p.add(rule);
    config.commit(md);
    projectCache.evict(config.getProject());
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:AbstractDaemonTest.java

示例3: configureContributorAgreement

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
protected ContributorAgreement configureContributorAgreement(boolean autoVerify)
    throws Exception {
  ContributorAgreement ca;
  if (autoVerify) {
    String g = createGroup("cla-test-group");
    GroupApi groupApi = gApi.groups().id(g);
    groupApi.description("CLA test group");
    InternalGroup caGroup =
        groupCache.get(new AccountGroup.UUID(groupApi.detail().id)).orElse(null);
    GroupReference groupRef = new GroupReference(caGroup.getGroupUUID(), caGroup.getName());
    PermissionRule rule = new PermissionRule(groupRef);
    rule.setAction(PermissionRule.Action.ALLOW);
    ca = new ContributorAgreement("cla-test");
    ca.setAutoVerify(groupRef);
    ca.setAccepted(ImmutableList.of(rule));
  } else {
    ca = new ContributorAgreement("cla-test-no-auto-verify");
  }
  ca.setDescription("description");
  ca.setAgreementUrl("agreement-url");

  ProjectConfig cfg = projectCache.checkedGet(allProjects).getConfig();
  cfg.replace(ca);
  saveProjectConfig(allProjects, cfg);
  return ca;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:AbstractDaemonTest.java

示例4: addAdministratorsAsReviewers

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
private void addAdministratorsAsReviewers(ChangeResource rsrc) {
  List<PermissionRule> adminRules =
      projectCache
          .getAllProjects()
          .getConfig()
          .getAccessSection(AccessSection.GLOBAL_CAPABILITIES)
          .getPermission(GlobalCapability.ADMINISTRATE_SERVER)
          .getRules();
  for (PermissionRule r : adminRules) {
    try {
      AddReviewerInput input = new AddReviewerInput();
      input.reviewer = r.getGroup().getUUID().get();
      reviewersProvider.get().apply(rsrc, input);
    } catch (Exception e) {
      // ignore
      Throwables.throwIfUnchecked(e);
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:20,代码来源:ReviewProjectAccess.java

示例5: buildGroupInfo

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
private Map<AccountGroup.UUID, GroupInfo> buildGroupInfo(List<AccessSection> local) {
  Map<AccountGroup.UUID, GroupInfo> infos = new HashMap<>();
  for (AccessSection section : local) {
    for (Permission permission : section.getPermissions()) {
      for (PermissionRule rule : permission.getRules()) {
        if (rule.getGroup() != null) {
          AccountGroup.UUID uuid = rule.getGroup().getUUID();
          if (uuid != null && !infos.containsKey(uuid)) {
            GroupDescription.Basic group = groupBackend.get(uuid);
            infos.put(uuid, group != null ? new GroupInfo(group) : null);
          }
        }
      }
    }
  }
  return Maps.filterEntries(infos, in -> in.getValue() != null);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:ProjectAccessFactory.java

示例6: access

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
/** Rules for the given permission, or the empty list. */
private List<PermissionRule> access(String permissionName, boolean isChangeOwner) {
  List<PermissionRule> rules = effective.get(permissionName);
  if (rules != null) {
    return rules;
  }

  rules = relevant.getPermission(permissionName);

  List<PermissionRule> mine = new ArrayList<>(rules.size());
  for (PermissionRule rule : rules) {
    if (projectControl.match(rule, isChangeOwner)) {
      mine.add(rule);
    }
  }

  if (mine.isEmpty()) {
    mine = Collections.emptyList();
  }
  effective.put(permissionName, mine);
  return mine;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:RefControl.java

示例7: canPerformOnAnyRef

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
private boolean canPerformOnAnyRef(String permissionName) {
  for (SectionMatcher matcher : access()) {
    AccessSection section = matcher.section;
    Permission permission = section.getPermission(permissionName);
    if (permission == null) {
      continue;
    }

    for (PermissionRule rule : permission.getRules()) {
      if (rule.isBlock() || rule.isDeny() || !match(rule)) {
        continue;
      }

      // Being in a group that was granted this permission is only an
      // approximation.  There might be overrides and doNotInherit
      // that would render this to be false.
      //
      if (controlForRef(section.getName()).canPerform(permissionName)) {
        return true;
      }
      break;
    }
  }

  return false;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:ProjectControl.java

示例8: createAccessSection

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
private AccessSectionInfo createAccessSection(
    Map<AccountGroup.UUID, GroupInfo> groups, AccessSection section) throws OrmException {
  AccessSectionInfo accessSectionInfo = new AccessSectionInfo();
  accessSectionInfo.permissions = new HashMap<>();
  for (Permission p : section.getPermissions()) {
    PermissionInfo pInfo = new PermissionInfo(p.getLabel(), p.getExclusiveGroup() ? true : null);
    pInfo.rules = new HashMap<>();
    for (PermissionRule r : p.getRules()) {
      PermissionRuleInfo info =
          new PermissionRuleInfo(ACTION_TYPE.get(r.getAction()), r.getForce());
      if (r.hasRange()) {
        info.max = r.getMax();
        info.min = r.getMin();
      }
      AccountGroup.UUID group = r.getGroup().getUUID();
      if (group != null) {
        pInfo.rules.put(group.get(), info);
        loadGroup(groups, group);
      }
    }
    accessSectionInfo.permissions.put(p.getName(), pInfo);
  }
  return accessSectionInfo;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:GetAccess.java

示例9: remove

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
public void remove(AccessSection section, Permission permission, PermissionRule rule) {
  if (rule == null) {
    remove(section, permission);
  } else if (section != null && permission != null) {
    AccessSection a = accessSections.get(section.getName());
    if (a == null) {
      return;
    }
    Permission p = a.getPermission(permission.getName());
    if (p == null) {
      return;
    }
    p.remove(rule);
    if (p.getRules().isEmpty()) {
      a.remove(permission);
    }
    if (a.getPermissions().isEmpty()) {
      remove(a);
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:ProjectConfig.java

示例10: saveContributorAgreements

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
private void saveContributorAgreements(Config rc, Set<AccountGroup.UUID> keepGroups) {
  for (ContributorAgreement ca : sort(contributorAgreements.values())) {
    set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_DESCRIPTION, ca.getDescription());
    set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AGREEMENT_URL, ca.getAgreementUrl());

    if (ca.getAutoVerify() != null) {
      if (ca.getAutoVerify().getUUID() != null) {
        keepGroups.add(ca.getAutoVerify().getUUID());
      }
      String autoVerify = new PermissionRule(ca.getAutoVerify()).asString(false);
      set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AUTO_VERIFY, autoVerify);
    } else {
      rc.unset(CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AUTO_VERIFY);
    }

    rc.setStringList(
        CONTRIBUTOR_AGREEMENT,
        ca.getName(),
        KEY_ACCEPTED,
        ruleToStringList(ca.getAccepted(), keepGroups));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:ProjectConfig.java

示例11: mergeAdmin

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
private static List<PermissionRule> mergeAdmin(
    Set<GroupReference> admins, List<PermissionRule> rules) {
  if (admins.isEmpty()) {
    return rules;
  }

  List<PermissionRule> r = new ArrayList<>(admins.size() + rules.size());
  for (GroupReference g : admins) {
    r.add(new PermissionRule(g));
  }
  for (PermissionRule rule : rules) {
    if (!admins.contains(rule.getGroup())) {
      r.add(rule);
    }
  }
  return r;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:CapabilityCollection.java

示例12: toRange

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
private static PermissionRange toRange(String permissionName, List<PermissionRule> ruleList) {
  int min = 0;
  int max = 0;
  if (ruleList.isEmpty()) {
    PermissionRange.WithDefaults defaultRange = GlobalCapability.getRange(permissionName);
    if (defaultRange != null) {
      min = defaultRange.getDefaultMin();
      max = defaultRange.getDefaultMax();
    }
  } else {
    for (PermissionRule rule : ruleList) {
      min = Math.min(min, rule.getMin());
      max = Math.max(max, rule.getMax());
    }
  }
  return new PermissionRange(permissionName, min, max);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:AccountLimits.java

示例13: AdministrateServerGroupsProvider

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
@Inject
public AdministrateServerGroupsProvider(
    GroupBackend groupBackend,
    @GerritServerConfig Config config,
    ThreadLocalRequestContext threadContext,
    ServerRequestContext serverCtx) {
  RequestContext ctx = threadContext.setContext(serverCtx);
  try {
    ImmutableSet.Builder<GroupReference> builder = ImmutableSet.builder();
    for (String value : config.getStringList("capability", null, "administrateServer")) {
      PermissionRule rule = PermissionRule.fromString(value, false);
      String name = rule.getGroup().getName();
      GroupReference g = GroupBackends.findBestSuggestion(groupBackend, name);
      if (g != null) {
        builder.add(g);
      } else {
        Logger log = LoggerFactory.getLogger(getClass());
        log.warn("Group \"{}\" not available, skipping.", name);
      }
    }
    groups = builder.build();
  } finally {
    threadContext.setContext(ctx);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:AdministrateServerGroupsProvider.java

示例14: removeForceFromPermission

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
public void removeForceFromPermission(String name) {
  for (String subsection : config.getSubsections(ACCESS)) {
    Set<String> names = config.getNames(ACCESS, subsection);
    if (names.contains(name)) {
      List<String> values =
          Arrays.stream(config.getStringList(ACCESS, subsection, name))
              .map(
                  r -> {
                    PermissionRule rule = PermissionRule.fromString(r, false);
                    if (rule.getForce()) {
                      rule.setForce(false);
                      updated = true;
                    }
                    return rule.asString(false);
                  })
              .collect(toList());
      config.setStringList(ACCESS, subsection, name, values);
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:ProjectConfigSchemaUpdate.java

示例15: grant

import com.google.gerrit.common.data.PermissionRule; //导入依赖的package包/类
public static void grant(
    ProjectConfig config,
    AccessSection section,
    String permission,
    boolean force,
    Boolean exclusive,
    GroupReference... groupList) {
  Permission p = section.getPermission(permission, true);
  if (exclusive != null) {
    p.setExclusiveGroup(exclusive);
  }
  for (GroupReference group : groupList) {
    if (group != null) {
      PermissionRule r = rule(config, group);
      r.setForce(force);
      p.add(r);
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:20,代码来源:AclUtil.java


注:本文中的com.google.gerrit.common.data.PermissionRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。