Search in sources :

Example 6 with PermissionBackendException

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();
}
Also used : AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CacheInfo(com.google.gerrit.server.config.ListCaches.CacheInfo) ThreadSummaryInfo(com.google.gerrit.server.config.GetSummary.ThreadSummaryInfo) JvmSummaryInfo(com.google.gerrit.server.config.GetSummary.JvmSummaryInfo) MemSummaryInfo(com.google.gerrit.server.config.GetSummary.MemSummaryInfo) TaskSummaryInfo(com.google.gerrit.server.config.GetSummary.TaskSummaryInfo) SummaryInfo(com.google.gerrit.server.config.GetSummary.SummaryInfo) ConfigResource(com.google.gerrit.server.config.ConfigResource)

Example 7 with PermissionBackendException

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);
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 8 with PermissionBackendException

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");
        }
    }
}
Also used : TaskResource(com.google.gerrit.server.config.TaskResource) AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ConfigResource(com.google.gerrit.server.config.ConfigResource)

Example 9 with PermissionBackendException

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;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Project(com.google.gerrit.reviewdb.client.Project) AccessCheckInfo(com.google.gerrit.extensions.api.config.AccessCheckInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Example 10 with PermissionBackendException

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;
    }
}
Also used : IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) JavaException(com.googlecode.prolog_cafe.exceptions.JavaException) IllegalTypeException(com.googlecode.prolog_cafe.exceptions.IllegalTypeException) CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) ChangeData(com.google.gerrit.server.query.change.ChangeData) PInstantiationException(com.googlecode.prolog_cafe.exceptions.PInstantiationException) SystemException(com.googlecode.prolog_cafe.exceptions.SystemException) OrmException(com.google.gwtorm.server.OrmException) LabelType(com.google.gerrit.common.data.LabelType) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) LabelPermission(com.google.gerrit.server.permissions.LabelPermission)

Aggregations

PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)23 IOException (java.io.IOException)13 AuthException (com.google.gerrit.extensions.restapi.AuthException)12 OrmException (com.google.gwtorm.server.OrmException)12 Project (com.google.gerrit.reviewdb.client.Project)10 CurrentUser (com.google.gerrit.server.CurrentUser)7 ChangeData (com.google.gerrit.server.query.change.ChangeData)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)6 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)6 Change (com.google.gerrit.reviewdb.client.Change)6 ArrayList (java.util.ArrayList)6 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)5 HashSet (java.util.HashSet)5 MoreObjects (com.google.common.base.MoreObjects)4 Strings (com.google.common.base.Strings)4 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)4 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)4 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)4 Inject (com.google.inject.Inject)4 Provider (com.google.inject.Provider)4