• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AuthException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: apply

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Override
public Response<EditInfo> apply(FixResource fixResource, Void nothing)
    throws AuthException, OrmException, ResourceConflictException, IOException,
        ResourceNotFoundException, PermissionBackendException {
  RevisionResource revisionResource = fixResource.getRevisionResource();
  Project.NameKey project = revisionResource.getProject();
  ProjectState projectState = projectCache.checkedGet(project);
  PatchSet patchSet = revisionResource.getPatchSet();
  ObjectId patchSetCommitId = ObjectId.fromString(patchSet.getRevision().get());

  try (Repository repository = gitRepositoryManager.openRepository(project)) {
    List<TreeModification> treeModifications =
        fixReplacementInterpreter.toTreeModifications(
            repository, projectState, patchSetCommitId, fixResource.getFixReplacements());
    ChangeEdit changeEdit =
        changeEditModifier.combineWithModifiedPatchSetTree(
            repository, revisionResource.getNotes(), patchSet, treeModifications);
    return Response.ok(changeEditJson.toEditInfo(changeEdit, false));
  } catch (InvalidChangeOperationException e) {
    throw new ResourceConflictException(e.getMessage());
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:ApplyFix.java


示例2: rebaseNotAllowedWithoutPushPermission

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Test
public void rebaseNotAllowedWithoutPushPermission() throws Exception {
  // Create two changes both with the same parent
  PushOneCommit.Result r = createChange();
  testRepo.reset("HEAD~1");
  PushOneCommit.Result r2 = createChange();

  // Approve and submit the first change
  RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
  revision.review(ReviewInput.approve());
  revision.submit();

  grant(project, "refs/heads/master", Permission.REBASE, false, REGISTERED_USERS);
  block("refs/for/*", Permission.PUSH, REGISTERED_USERS);

  // Rebase the second
  String changeId = r2.getChangeId();
  setApiUser(user);
  exception.expect(AuthException.class);
  exception.expectMessage("rebase not permitted");
  gApi.changes().id(changeId).rebase();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:ChangeIT.java


示例3: apply

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Override
public Object apply(AccountResource rsrc) throws AuthException, PermissionBackendException {
  PermissionBackend.WithUser perm = permissionBackend.user(self);
  if (self.get() != rsrc.getUser()) {
    perm.check(GlobalPermission.ADMINISTRATE_SERVER);
    perm = permissionBackend.user(rsrc.getUser());
  }

  Map<String, Object> have = new LinkedHashMap<>();
  for (GlobalOrPluginPermission p : perm.test(permissionsToTest())) {
    have.put(p.permissionName(), true);
  }

  AccountLimits limits = limitsFactory.create(rsrc.getUser());
  addRanges(have, limits);
  addPriority(have, limits);

  return OutputFormat.JSON
      .newGson()
      .toJsonTree(have, new TypeToken<Map<String, Object>>() {}.getType());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:GetCapabilities.java


示例4: createEditWithoutPushPatchSetPermission

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Test
public void createEditWithoutPushPatchSetPermission() throws Exception {
  // Create new project with clean permissions
  Project.NameKey p = createProject("addPatchSetEdit");
  // Clone repository as user
  TestRepository<InMemoryRepository> userTestRepo = cloneProject(p, user);

  // Block default permission
  block(p, "refs/for/*", Permission.ADD_PATCH_SET, REGISTERED_USERS);

  // Create change as user
  PushOneCommit push = pushFactory.create(db, user.getIdent(), userTestRepo);
  PushOneCommit.Result r1 = push.to("refs/for/master");
  r1.assertOkStatus();

  // Try to create edit as admin
  exception.expect(AuthException.class);
  createEmptyEditFor(r1.getChangeId());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:20,代码来源:ChangeEditIT.java


示例5: isParentAccessible

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
private boolean isParentAccessible(
    Map<Project.NameKey, Boolean> checked, PermissionBackend.WithUser perm, ProjectState p)
    throws PermissionBackendException {
  Project.NameKey name = p.getNameKey();
  Boolean b = checked.get(name);
  if (b == null) {
    try {
      perm.project(name).check(ProjectPermission.ACCESS);
      b = true;
    } catch (AuthException denied) {
      b = false;
    }
    checked.put(name, b);
  }
  return b;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:ListProjects.java


示例6: setParentName

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
public void setParentName(
    IdentifiedUser identifiedUser,
    ProjectConfig config,
    Project.NameKey projectName,
    Project.NameKey newParentProjectName,
    boolean checkAdmin)
    throws ResourceConflictException, AuthException, PermissionBackendException,
        BadRequestException {
  if (newParentProjectName != null
      && !config.getProject().getNameKey().equals(allProjects)
      && !config.getProject().getParent(allProjects).equals(newParentProjectName)) {
    try {
      setParent
          .get()
          .validateParentUpdate(
              projectName, identifiedUser, newParentProjectName.get(), checkAdmin);
    } catch (UnprocessableEntityException e) {
      throw new ResourceConflictException(e.getMessage(), e);
    }
    config.getProject().setParentName(newParentProjectName);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:SetAccessUtil.java


示例7: apply

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Override
public Response<String> apply(ConfigResource rsrc, Input input)
    throws AuthException, BadRequestException, UnprocessableEntityException,
        PermissionBackendException {
  if (input == null || input.operation == null) {
    throw new BadRequestException("operation must be specified");
  }

  switch (input.operation) {
    case FLUSH_ALL:
      if (input.caches != null) {
        throw new BadRequestException(
            "specifying caches is not allowed for operation 'FLUSH_ALL'");
      }
      flushAll();
      return Response.ok("");
    case FLUSH:
      if (input.caches == null || input.caches.isEmpty()) {
        throw new BadRequestException("caches must be specified for operation 'FLUSH'");
      }
      flush(input.caches);
      return Response.ok("");
    default:
      throw new BadRequestException("unsupported operation: " + input.operation);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:PostCaches.java


示例8: rebaseNotAllowedForOwnerWithoutPushPermission

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Test
public void rebaseNotAllowedForOwnerWithoutPushPermission() throws Exception {
  // Create two changes both with the same parent
  PushOneCommit.Result r = createChange();
  testRepo.reset("HEAD~1");
  PushOneCommit.Result r2 = createChange();

  // Approve and submit the first change
  RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
  revision.review(ReviewInput.approve());
  revision.submit();

  block("refs/for/*", Permission.PUSH, REGISTERED_USERS);

  // Rebase the second
  String changeId = r2.getChangeId();
  exception.expect(AuthException.class);
  exception.expectMessage("rebase not permitted");
  gApi.changes().id(changeId).rebase();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:ChangeIT.java


示例9: apply

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Override
public GeneralPreferencesInfo apply(AccountResource rsrc, GeneralPreferencesInfo i)
    throws AuthException, BadRequestException, IOException, ConfigInvalidException,
        PermissionBackendException {
  if (self.get() != rsrc.getUser()) {
    permissionBackend.user(self).check(GlobalPermission.MODIFY_ACCOUNT);
  }

  checkDownloadScheme(i.downloadScheme);
  Account.Id id = rsrc.getUser().getAccountId();
  GeneralPreferencesInfo n = loader.merge(id, i);

  n.changeTable = i.changeTable;
  n.my = i.my;
  n.urlAliases = i.urlAliases;

  writeToGit(id, n);

  return cache.get(id).getAccount().getGeneralPreferencesInfo();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:SetPreferences.java


示例10: onBehalfOf

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
private IdentifiedUser onBehalfOf(RevisionResource rsrc, SubmitInput in)
    throws AuthException, UnprocessableEntityException, OrmException, PermissionBackendException,
        IOException, ConfigInvalidException {
  PermissionBackend.ForChange perm = rsrc.permissions().database(dbProvider);
  perm.check(ChangePermission.SUBMIT);
  perm.check(ChangePermission.SUBMIT_AS);

  CurrentUser caller = rsrc.getUser();
  IdentifiedUser submitter = accounts.parseOnBehalfOf(caller, in.onBehalfOf);
  try {
    perm.user(submitter).check(ChangePermission.READ);
  } catch (AuthException e) {
    throw new UnprocessableEntityException(
        String.format("on_behalf_of account %s cannot see change", submitter.getAccountId()));
  }
  return submitter;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:Submit.java


示例11: apply

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Override
public OAuthTokenInfo apply(AccountResource rsrc)
    throws AuthException, ResourceNotFoundException {
  if (self.get() != rsrc.getUser()) {
    throw new AuthException("not allowed to get access token");
  }
  Account a = rsrc.getUser().getAccount();
  OAuthToken accessToken = tokenCache.get(a.getId());
  if (accessToken == null) {
    throw new ResourceNotFoundException();
  }
  OAuthTokenInfo accessTokenInfo = new OAuthTokenInfo();
  accessTokenInfo.username = a.getUserName();
  accessTokenInfo.resourceHost = getHostName(canonicalWebUrlProvider.get());
  accessTokenInfo.accessToken = accessToken.getToken();
  accessTokenInfo.providerId = accessToken.getProviderId();
  accessTokenInfo.expiresAt = Long.toString(accessToken.getExpiresAt());
  accessTokenInfo.type = BEARER_TYPE;
  return accessTokenInfo;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:GetOAuthToken.java


示例12: byChange

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
/**
 * Retrieve edit for a change and the given user.
 *
 * <p>At most one change edit can exist per user and change.
 *
 * @param notes change notes of change to retrieve change edits for.
 * @param user user to retrieve edits as.
 * @return edit for this change for this user, if present.
 * @throws AuthException if this is not a logged-in user.
 * @throws IOException if an error occurs.
 */
public Optional<ChangeEdit> byChange(ChangeNotes notes, CurrentUser user)
    throws AuthException, IOException {
  if (!user.isIdentifiedUser()) {
    throw new AuthException("Authentication required");
  }
  IdentifiedUser u = user.asIdentifiedUser();
  Change change = notes.getChange();
  try (Repository repo = gitManager.openRepository(change.getProject())) {
    int n = change.currentPatchSetId().get();
    String[] refNames = new String[n];
    for (int i = n; i > 0; i--) {
      refNames[i - 1] =
          RefNames.refsEdit(u.getAccountId(), change.getId(), new PatchSet.Id(change.getId(), i));
    }
    Ref ref = repo.getRefDatabase().firstExactRef(refNames);
    if (ref == null) {
      return Optional.empty();
    }
    try (RevWalk rw = new RevWalk(repo)) {
      RevCommit commit = rw.parseCommit(ref.getObjectId());
      PatchSet basePs = getBasePatchSet(notes, ref);
      return Optional.of(new ChangeEdit(change, ref.getName(), commit, basePs));
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:37,代码来源:ChangeEditUtil.java


示例13: createEdit

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
/**
 * Creates a new change edit.
 *
 * @param repository the affected Git repository
 * @param notes the {@link ChangeNotes} of the change for which the change edit should be created
 * @throws AuthException if the user isn't authenticated or not allowed to use change edits
 * @throws InvalidChangeOperationException if a change edit already existed for the change
 * @throws PermissionBackendException
 */
public void createEdit(Repository repository, ChangeNotes notes)
    throws AuthException, IOException, InvalidChangeOperationException, OrmException,
        PermissionBackendException {
  assertCanEdit(notes);

  Optional<ChangeEdit> changeEdit = lookupChangeEdit(notes);
  if (changeEdit.isPresent()) {
    throw new InvalidChangeOperationException(
        String.format("A change edit already exists for change %s", notes.getChangeId()));
  }

  PatchSet currentPatchSet = lookupCurrentPatchSet(notes);
  ObjectId patchSetCommitId = getPatchSetCommitId(currentPatchSet);
  createEdit(repository, notes, currentPatchSet, patchSetCommitId, TimeUtil.nowTs());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:ChangeEditModifier.java


示例14: rebaseEdit

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
/**
 * Rebase change edit on latest patch set
 *
 * @param repository the affected Git repository
 * @param notes the {@link ChangeNotes} of the change whose change edit should be rebased
 * @throws AuthException if the user isn't authenticated or not allowed to use change edits
 * @throws InvalidChangeOperationException if a change edit doesn't exist for the specified
 *     change, the change edit is already based on the latest patch set, or the change represents
 *     the root commit
 * @throws MergeConflictException if rebase fails due to merge conflicts
 * @throws PermissionBackendException
 */
public void rebaseEdit(Repository repository, ChangeNotes notes)
    throws AuthException, InvalidChangeOperationException, IOException, OrmException,
        MergeConflictException, PermissionBackendException {
  assertCanEdit(notes);

  Optional<ChangeEdit> optionalChangeEdit = lookupChangeEdit(notes);
  if (!optionalChangeEdit.isPresent()) {
    throw new InvalidChangeOperationException(
        String.format("No change edit exists for change %s", notes.getChangeId()));
  }
  ChangeEdit changeEdit = optionalChangeEdit.get();

  PatchSet currentPatchSet = lookupCurrentPatchSet(notes);
  if (isBasedOn(changeEdit, currentPatchSet)) {
    throw new InvalidChangeOperationException(
        String.format(
            "Change edit for change %s is already based on latest patch set %s",
            notes.getChangeId(), currentPatchSet.getId()));
  }

  rebase(repository, changeEdit, currentPatchSet);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:35,代码来源:ChangeEditModifier.java


示例15: submitWithHiddenBranchInSameTopic

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Test
public void submitWithHiddenBranchInSameTopic() throws Exception {
  assume().that(isSubmitWholeTopicEnabled()).isTrue();
  PushOneCommit.Result visible = createChange("refs/for/master/" + name("topic"));
  Change.Id num = visible.getChange().getId();

  createBranch(new Branch.NameKey(project, "hidden"));
  PushOneCommit.Result hidden = createChange("refs/for/hidden/" + name("topic"));
  approve(hidden.getChangeId());
  blockRead("refs/heads/hidden");

  submit(
      visible.getChangeId(),
      new SubmitInput(),
      AuthException.class,
      "A change to be submitted with " + num + " is not visible");
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:AbstractSubmit.java


示例16: modifyTree

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
private void modifyTree(
    Repository repository, ChangeNotes notes, TreeModification treeModification)
    throws AuthException, IOException, OrmException, InvalidChangeOperationException,
        PermissionBackendException {
  assertCanEdit(notes);

  Optional<ChangeEdit> optionalChangeEdit = lookupChangeEdit(notes);
  PatchSet basePatchSet = getBasePatchSet(optionalChangeEdit, notes);
  RevCommit basePatchSetCommit = lookupCommit(repository, basePatchSet);
  RevCommit baseCommit =
      optionalChangeEdit.map(ChangeEdit::getEditCommit).orElse(basePatchSetCommit);

  ObjectId newTreeId = createNewTree(repository, baseCommit, ImmutableList.of(treeModification));

  String commitMessage = baseCommit.getFullMessage();
  Timestamp nowTimestamp = TimeUtil.nowTs();
  ObjectId newEditCommit =
      createCommit(repository, basePatchSetCommit, newTreeId, commitMessage, nowTimestamp);

  if (optionalChangeEdit.isPresent()) {
    updateEdit(repository, optionalChangeEdit.get(), newEditCommit, nowTimestamp);
  } else {
    createEdit(repository, notes, basePatchSet, newEditCommit, nowTimestamp);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:ChangeEditModifier.java


示例17: parse

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Override
public CacheResource parse(ConfigResource parent, IdString id)
    throws AuthException, ResourceNotFoundException, PermissionBackendException {
  permissionBackend.user(self).check(GlobalPermission.VIEW_CACHES);

  String cacheName = id.get();
  String pluginName = "gerrit";
  int i = cacheName.lastIndexOf('-');
  if (i != -1) {
    pluginName = cacheName.substring(0, i);
    cacheName = cacheName.length() > i + 1 ? cacheName.substring(i + 1) : "";
  }

  Provider<Cache<?, ?>> cacheProvider = cacheMap.byPlugin(pluginName).get(cacheName);
  if (cacheProvider == null) {
    throw new ResourceNotFoundException(id);
  }
  return new CacheResource(pluginName, cacheName, cacheProvider);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:20,代码来源:CachesCollection.java


示例18: visibleEdit

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
private boolean visibleEdit(String name) {
  Change.Id id = Change.Id.fromEditRefPart(name);
  // Initialize if it wasn't yet
  if (visibleChanges == null) {
    visible(id);
  }
  if (id == null) {
    return false;
  }
  if (userEditPrefix != null && name.startsWith(userEditPrefix) && visible(id)) {
    return true;
  }
  if (visibleChanges.containsKey(id)) {
    try {
      // Default to READ_PRIVATE_CHANGES as there is no special permission for reading edits.
      perm.ref(visibleChanges.get(id).get()).check(RefPermission.READ_PRIVATE_CHANGES);
      return true;
    } catch (PermissionBackendException | AuthException e) {
      return false;
    }
  }
  return false;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:24,代码来源:VisibleRefFilter.java


示例19: moveChangeWithCurrentPatchSetLocked

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Test
public void moveChangeWithCurrentPatchSetLocked() throws Exception {
  // Move change that is locked
  PushOneCommit.Result r = createChange();
  Branch.NameKey newBranch = new Branch.NameKey(r.getChange().change().getProject(), "moveTest");
  createBranch(newBranch);

  ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
  LabelType patchSetLock = Util.patchSetLock();
  cfg.getLabelSections().put(patchSetLock.getName(), patchSetLock);
  AccountGroup.UUID registeredUsers = systemGroupBackend.getGroup(REGISTERED_USERS).getUUID();
  Util.allow(
      cfg, Permission.forLabel(patchSetLock.getName()), 0, 1, registeredUsers, "refs/heads/*");
  saveProjectConfig(cfg);
  grant(project, "refs/heads/*", Permission.LABEL + "Patch-Set-Lock");
  revision(r).review(new ReviewInput().label("Patch-Set-Lock", 1));

  exception.expect(AuthException.class);
  exception.expectMessage("move not permitted");
  move(r.getChangeId(), newBranch.get());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:MoveChangeIT.java


示例20: deleteNewChangeOfAnotherUserWithDeleteOwnChangesPermission

import com.google.gerrit.extensions.restapi.AuthException; //导入依赖的package包/类
@Test
public void deleteNewChangeOfAnotherUserWithDeleteOwnChangesPermission() throws Exception {
  allow("refs/*", Permission.DELETE_OWN_CHANGES, REGISTERED_USERS);

  try {
    PushOneCommit.Result changeResult = createChange();
    String changeId = changeResult.getChangeId();

    setApiUser(user);
    exception.expect(AuthException.class);
    exception.expectMessage("delete not permitted");
    gApi.changes().id(changeId).delete();
  } finally {
    removePermission(project, "refs/*", Permission.DELETE_OWN_CHANGES);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:ChangeIT.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RunConfigurationExtension类代码示例发布时间:2022-05-22
下一篇:
Java LogLevel类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap