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


Java PermissionDeniedException类代码示例

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


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

示例1: run

import com.google.gerrit.common.errors.PermissionDeniedException; //导入依赖的package包/类
@Override
protected void run() throws Failure {
  try {
    checkPermission();

    final CiQueryShell shell = factory.create(in, out);
    shell.setOutputFormat(format);
    if (query != null) {
      shell.execute(query);
    } else {
      shell.run();
    }
  } catch (PermissionDeniedException err) {
    throw new UnloggedFailure("fatal: " + err.getMessage());
  }
}
 
开发者ID:davido,项目名称:gerrit-ci-plugin,代码行数:17,代码来源:CiAdminQueryShell.java

示例2: updateProjectConfig

import com.google.gerrit.common.errors.PermissionDeniedException; //导入依赖的package包/类
protected abstract T updateProjectConfig(
ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
throws IOException, NoSuchProjectException, ConfigInvalidException, OrmException,
    PermissionDeniedException, PermissionBackendException;
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:5,代码来源:ProjectAccessHandler.java

示例3: apply

import com.google.gerrit.common.errors.PermissionDeniedException; //导入依赖的package包/类
@Override
public Response<ChangeInfo> apply(ProjectResource rsrc, ProjectAccessInput input)
    throws PermissionBackendException, PermissionDeniedException, IOException,
        ConfigInvalidException, OrmException, InvalidNameException, UpdateException,
        RestApiException {
  PermissionBackend.ForProject forProject =
      permissionBackend.user(rsrc.getUser()).project(rsrc.getNameKey());
  if (!check(forProject, ProjectPermission.READ_CONFIG)) {
    throw new PermissionDeniedException(RefNames.REFS_CONFIG + " not visible");
  }
  if (!check(forProject, ProjectPermission.WRITE_CONFIG)) {
    try {
      forProject.ref(RefNames.REFS_CONFIG).check(RefPermission.CREATE_CHANGE);
    } catch (AuthException denied) {
      throw new PermissionDeniedException("cannot create change for " + RefNames.REFS_CONFIG);
    }
  }

  MetaDataUpdate.User metaDataUpdateUser = metaDataUpdateFactory.get();
  List<AccessSection> removals = setAccess.getAccessSections(input.remove);
  List<AccessSection> additions = setAccess.getAccessSections(input.add);

  Project.NameKey newParentProjectName =
      input.parent == null ? null : new Project.NameKey(input.parent);

  try (MetaDataUpdate md = metaDataUpdateUser.create(rsrc.getNameKey())) {
    ProjectConfig config = ProjectConfig.read(md);

    setAccess.validateChanges(config, removals, additions);
    setAccess.applyChanges(config, removals, additions);
    try {
      setAccess.setParentName(
          rsrc.getUser().asIdentifiedUser(),
          config,
          rsrc.getNameKey(),
          newParentProjectName,
          false);
    } catch (AuthException e) {
      throw new IllegalStateException(e);
    }

    md.setMessage("Review access change");
    md.setInsertChangeId(true);
    Change.Id changeId = new Change.Id(seq.nextChangeId());
    RevCommit commit =
        config.commitToNewRef(
            md, new PatchSet.Id(changeId, Change.INITIAL_PATCH_SET_ID).toRefName());

    try (ObjectInserter objInserter = md.getRepository().newObjectInserter();
        ObjectReader objReader = objInserter.newReader();
        RevWalk rw = new RevWalk(objReader);
        BatchUpdate bu =
            updateFactory.create(db.get(), rsrc.getNameKey(), rsrc.getUser(), TimeUtil.nowTs())) {
      bu.setRepository(md.getRepository(), rw, objInserter);
      ChangeInserter ins = newInserter(changeId, commit);
      bu.insertChange(ins);
      bu.execute();
      return Response.created(jsonFactory.noOptions().format(ins.getChange()));
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:62,代码来源:CreateAccessChange.java

示例4: checkPermission

import com.google.gerrit.common.errors.PermissionDeniedException; //导入依赖的package包/类
/**
 * Assert that the current user is permitted to perform raw queries.
 * <p>
 * As the @RequireCapability guards at various entry points of internal
 * commands implicitly add administrators (which we want to avoid), we also
 * check permissions within QueryShell and grant access only to those who
 * canPerformRawQuery, regardless of whether they are administrators or not.
 *
 * @throws PermissionDeniedException
 */
private void checkPermission() throws PermissionDeniedException {
  if (!currentUser.getCapabilities().canAccessDatabase()) {
    throw new PermissionDeniedException(String.format(
        "%s does not have \"Access Database\" capability.",
        currentUser.getUserName()));
  }
}
 
开发者ID:davido,项目名称:gerrit-ci-plugin,代码行数:18,代码来源:CiAdminQueryShell.java


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