本文整理汇总了Java中com.google.gerrit.extensions.restapi.AuthException类的典型用法代码示例。如果您正苦于以下问题:Java AuthException类的具体用法?Java AuthException怎么用?Java AuthException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthException类属于com.google.gerrit.extensions.restapi包,在下文中一共展示了AuthException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
}
示例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();
}
示例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());
}
示例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());
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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));
}
}
}
示例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());
}
示例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);
}
示例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");
}