Search in sources :

Example 1 with Context

use of com.google.gerrit.sshd.SshScope.Context in project gerrit by GerritCodeReview.

the class SuExec method start.

@Override
public void start(Environment env) throws IOException {
    try {
        checkCanRunAs();
        parseCommandLine();
        final Context ctx = callingContext.subContext(newSession(), join(args));
        final Context old = sshScope.set(ctx);
        try {
            final BaseCommand cmd = dispatcher.get();
            cmd.setArguments(args.toArray(new String[args.size()]));
            provideStateTo(cmd);
            atomicCmd.set(cmd);
            cmd.start(env);
        } finally {
            sshScope.set(old);
        }
    } catch (UnloggedFailure e) {
        String msg = e.getMessage();
        if (!msg.endsWith("\n")) {
            msg += "\n";
        }
        err.write(msg.getBytes(UTF_8));
        err.flush();
        onExit(1);
    }
}
Also used : Context(com.google.gerrit.sshd.SshScope.Context)

Example 2 with Context

use of com.google.gerrit.sshd.SshScope.Context in project gerrit by GerritCodeReview.

the class SshLog method onExecute.

void onExecute(DispatchCommand dcmd, int exitValue, SshSession sshSession) {
    final Context ctx = context.get();
    ctx.finished = TimeUtil.nowMs();
    String cmd = extractWhat(dcmd);
    final LoggingEvent event = log(cmd);
    event.setProperty(P_WAIT, (ctx.started - ctx.created) + "ms");
    event.setProperty(P_EXEC, (ctx.finished - ctx.started) + "ms");
    final String status;
    switch(exitValue) {
        case BaseCommand.STATUS_CANCEL:
            status = "killed";
            break;
        case BaseCommand.STATUS_NOT_FOUND:
            status = "not-found";
            break;
        case BaseCommand.STATUS_NOT_ADMIN:
            status = "not-admin";
            break;
        default:
            status = String.valueOf(exitValue);
            break;
    }
    event.setProperty(P_STATUS, status);
    String peerAgent = sshSession.getPeerAgent();
    if (peerAgent != null) {
        event.setProperty(P_AGENT, peerAgent);
    }
    if (async != null) {
        async.append(event);
    }
    audit(context.get(), status, dcmd);
}
Also used : Context(com.google.gerrit.sshd.SshScope.Context) LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Example 3 with Context

use of com.google.gerrit.sshd.SshScope.Context in project gerrit by GerritCodeReview.

the class AbstractGitCommand method start.

@Override
public void start(final Environment env) {
    Context ctx = context.subContext(newSession(), context.getCommandLine());
    final Context old = sshScope.set(ctx);
    try {
        startThread(new ProjectCommandRunnable() {

            @Override
            public void executeParseCommand() throws Exception {
                parseCommandLine();
            }

            @Override
            public void run() throws Exception {
                AbstractGitCommand.this.service();
            }

            @Override
            public Project.NameKey getProjectName() {
                Project project = projectControl.getProjectState().getProject();
                return project.getNameKey();
            }
        });
    } finally {
        sshScope.set(old);
    }
}
Also used : Context(com.google.gerrit.sshd.SshScope.Context) Project(com.google.gerrit.reviewdb.client.Project) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException)

Example 4 with Context

use of com.google.gerrit.sshd.SshScope.Context in project gerrit by GerritCodeReview.

the class SshUtil method success.

public static boolean success(final String username, final ServerSession session, final SshScope sshScope, final SshLog sshLog, final SshSession sd, final CurrentUser user) {
    if (sd.getUser() == null) {
        sd.authenticationSuccess(username, user);
        // If this is the first time we've authenticated this
        // session, record a login event in the log and add
        // a close listener to record a logout event.
        //
        Context ctx = sshScope.newContext(null, sd, null);
        Context old = sshScope.set(ctx);
        try {
            sshLog.onLogin();
        } finally {
            sshScope.set(old);
        }
        session.addCloseFutureListener(new SshFutureListener<CloseFuture>() {

            @Override
            public void operationComplete(CloseFuture future) {
                final Context ctx = sshScope.newContext(null, sd, null);
                final Context old = sshScope.set(ctx);
                try {
                    sshLog.onLogout();
                } finally {
                    sshScope.set(old);
                }
            }
        });
    }
    return true;
}
Also used : Context(com.google.gerrit.sshd.SshScope.Context) CloseFuture(org.apache.sshd.common.future.CloseFuture)

Aggregations

Context (com.google.gerrit.sshd.SshScope.Context)4 Project (com.google.gerrit.reviewdb.client.Project)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 IOException (java.io.IOException)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 CloseFuture (org.apache.sshd.common.future.CloseFuture)1 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)1