use of com.google.gerrit.server.permissions.PermissionBackendException in project gerrit by GerritCodeReview.
the class ShowCaches method run.
@Override
protected void run() throws UnloggedFailure {
nw = columns - 50;
Date now = new Date();
stdout.format("%-25s %-20s now %16s\n", "Gerrit Code Review", Version.getVersion() != null ? Version.getVersion() : "", new SimpleDateFormat("HH:mm:ss zzz").format(now));
stdout.format("%-25s %-20s uptime %16s\n", "", "", uptime(now.getTime() - serverStarted));
stdout.print('\n');
stdout.print(//
String.format(//
"%1s %-" + nw + "s|%-21s| %-5s |%-9s|\n", //
"", //
"Name", //
"Entries", //
"AvgGet", //
"Hit Ratio"));
stdout.print(//
String.format(//
"%1s %-" + nw + "s|%6s %6s %7s| %-5s |%-4s %-4s|\n", //
"", //
"", //
"Mem", //
"Disk", //
"Space", //
"", //
"Mem", //
"Disk"));
stdout.print("--");
for (int i = 0; i < nw; i++) {
stdout.print('-');
}
stdout.print("+---------------------+---------+---------+\n");
Collection<CacheInfo> caches = getCaches();
printMemoryCoreCaches(caches);
printMemoryPluginCaches(caches);
printDiskCaches(caches);
stdout.print('\n');
boolean showJvm;
try {
permissionBackend.user(self).check(GlobalPermission.MAINTAIN_SERVER);
showJvm = true;
} catch (AuthException | PermissionBackendException e) {
// Silently ignore and do not display detailed JVM information.
showJvm = false;
}
if (showJvm) {
sshSummary();
SummaryInfo summary = getSummary.setGc(gc).setJvm(showJVM).apply(new ConfigResource());
taskSummary(summary.taskSummary);
memSummary(summary.memSummary);
threadSummary(summary.threadSummary);
if (showJVM && summary.jvmSummary != null) {
jvmSummary(summary.jvmSummary);
}
}
stdout.flush();
}
use of com.google.gerrit.server.permissions.PermissionBackendException in project gerrit by GerritCodeReview.
the class CreateProjectCommand method run.
@Override
protected void run() throws Failure {
try {
if (!suggestParent) {
if (projectName == null) {
throw die("Project name is required.");
}
ProjectInput input = new ProjectInput();
input.name = projectName;
if (ownerIds != null) {
input.owners = Lists.transform(ownerIds, AccountGroup.UUID::get);
}
if (newParent != null) {
input.parent = newParent.getProject().getName();
}
input.permissionsOnly = permissionsOnly;
input.description = projectDescription;
input.submitType = submitType;
input.useContributorAgreements = contributorAgreements;
input.useSignedOffBy = signedOffBy;
input.useContentMerge = contentMerge;
input.requireChangeId = requireChangeID;
input.createNewChangeForAllNotInTarget = createNewChangeForAllNotInTarget;
input.branches = branch;
input.createEmptyCommit = createEmptyCommit;
input.maxObjectSizeLimit = maxObjectSizeLimit;
if (pluginConfigValues != null) {
input.pluginConfigValues = parsePluginConfigValues(pluginConfigValues);
}
gApi.projects().create(input);
} else {
for (Project.NameKey parent : suggestParentCandidates.getNameKeys()) {
stdout.print(parent.get() + '\n');
}
}
} catch (RestApiException err) {
throw die(err);
} catch (PermissionBackendException err) {
throw new Failure(1, "permissions unavailable", err);
}
}
use of com.google.gerrit.server.permissions.PermissionBackendException in project gerrit by GerritCodeReview.
the class KillCommand method run.
@Override
protected void run() {
ConfigResource cfgRsrc = new ConfigResource();
for (String id : taskIds) {
try {
TaskResource taskRsrc = tasksCollection.parse(cfgRsrc, IdString.fromDecoded(id));
deleteTask.apply(taskRsrc, null);
} catch (AuthException | ResourceNotFoundException | PermissionBackendException e) {
stderr.print("kill: " + id + ": No such task\n");
}
}
}
use of com.google.gerrit.server.permissions.PermissionBackendException in project gerrit by GerritCodeReview.
the class CheckAccess method apply.
@Override
public AccessCheckInfo apply(ConfigResource unused, AccessCheckInput input) throws OrmException, PermissionBackendException, RestApiException, IOException {
permissionBackend.user(currentUser.get()).check(GlobalPermission.ADMINISTRATE_SERVER);
if (input == null) {
throw new BadRequestException("input is required");
}
if (Strings.isNullOrEmpty(input.account)) {
throw new BadRequestException("input requires 'account'");
}
if (Strings.isNullOrEmpty(input.project)) {
throw new BadRequestException("input requires 'project'");
}
Account match = accountResolver.find(db.get(), input.account);
if (match == null) {
throw new BadRequestException(String.format("cannot find account %s", input.account));
}
AccessCheckInfo info = new AccessCheckInfo();
Project.NameKey key = new Project.NameKey(input.project);
if (projectCache.get(key) == null) {
info.message = String.format("project %s does not exist", key);
info.status = HttpServletResponse.SC_NOT_FOUND;
return info;
}
IdentifiedUser user = userFactory.create(match.getId());
try {
permissionBackend.user(user).project(key).check(ProjectPermission.ACCESS);
} catch (AuthException | PermissionBackendException e) {
info.message = String.format("user %s (%s) cannot see project %s", user.getNameEmail(), user.getAccount().getId(), key);
info.status = HttpServletResponse.SC_FORBIDDEN;
return info;
}
if (!Strings.isNullOrEmpty(input.ref)) {
try {
permissionBackend.user(user).ref(new Branch.NameKey(key, input.ref)).check(RefPermission.READ);
} catch (AuthException | PermissionBackendException e) {
info.status = HttpServletResponse.SC_FORBIDDEN;
info.message = String.format("user %s (%s) cannot see ref %s in project %s", user.getNameEmail(), user.getAccount().getId(), input.ref, key);
return info;
}
}
info.status = HttpServletResponse.SC_OK;
return info;
}
use of com.google.gerrit.server.permissions.PermissionBackendException in project gerrit by GerritCodeReview.
the class PRED__check_user_label_3 method exec.
@Override
public Operation exec(Prolog engine) throws PrologException {
engine.setB0();
Term a1 = arg1.dereference();
Term a2 = arg2.dereference();
Term a3 = arg3.dereference();
if (a1 instanceof VariableTerm) {
throw new PInstantiationException(this, 1);
}
if (!(a1 instanceof SymbolTerm)) {
throw new IllegalTypeException(this, 1, "atom", a1);
}
String label = a1.name();
if (a2 instanceof VariableTerm) {
throw new PInstantiationException(this, 2);
}
if (!(a2 instanceof JavaObjectTerm) || !a2.convertible(CurrentUser.class)) {
throw new IllegalTypeException(this, 2, "CurrentUser)", a2);
}
CurrentUser user = (CurrentUser) ((JavaObjectTerm) a2).object();
if (a3 instanceof VariableTerm) {
throw new PInstantiationException(this, 3);
}
if (!(a3 instanceof IntegerTerm)) {
throw new IllegalTypeException(this, 3, "integer", a3);
}
short val = (short) ((IntegerTerm) a3).intValue();
try {
ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
LabelType type = cd.getLabelTypes().byLabel(label);
if (type == null) {
return engine.fail();
}
StoredValues.PERMISSION_BACKEND.get(engine).user(user).change(cd).check(new LabelPermission.WithValue(type, val));
return cont;
} catch (OrmException err) {
throw new JavaException(this, 1, err);
} catch (AuthException err) {
return engine.fail();
} catch (PermissionBackendException err) {
SystemException se = new SystemException(err.getMessage());
se.initCause(err);
throw se;
}
}
Aggregations