Refactor the SSH session state

We want to split the session state apart from the actual connection
so we can implement a "set uid" feature later, where the user
running a command may not match the original authentication.

Change-Id: I0c9d31b4f5f04849e1c4a171243f0f376056c2c8
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-01-16 14:01:42 -08:00
parent 0302d07f1f
commit 4039675ad5
15 changed files with 417 additions and 264 deletions

View File

@@ -14,7 +14,7 @@
package com.google.gerrit.sshd;
import com.google.gerrit.sshd.SshScopes.Context;
import com.google.gerrit.sshd.SshScope.Context;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -59,7 +59,6 @@ class CommandFactoryProvider implements Provider<CommandFactory> {
private OutputStream out;
private OutputStream err;
private ExitCallback exit;
private ServerSession session;
private Context ctx;
private DispatchCommand cmd;
private boolean logged;
@@ -85,16 +84,13 @@ class CommandFactoryProvider implements Provider<CommandFactory> {
}
public void setSession(final ServerSession session) {
this.session = session;
this.ctx = new Context(session.getAttribute(SshSession.KEY));
}
public void start(final Environment env) throws IOException {
synchronized (this) {
final Context old = SshScopes.current.get();
final Context old = SshScope.set(ctx);
try {
ctx = new Context(session);
SshScopes.current.set(ctx);
cmd = dispatcher.get();
cmd.setCommandLine(commandLine);
cmd.setInputStream(in);
@@ -115,7 +111,7 @@ class CommandFactoryProvider implements Provider<CommandFactory> {
});
cmd.start(env);
} finally {
SshScopes.current.set(old);
SshScope.set(old);
}
}
}
@@ -150,15 +146,14 @@ class CommandFactoryProvider implements Provider<CommandFactory> {
public void destroy() {
synchronized (this) {
if (cmd != null) {
final Context old = SshScopes.current.get();
final Context old = SshScope.set(ctx);
try {
SshScopes.current.set(ctx);
cmd.destroy();
log(BaseCommand.STATUS_CANCEL);
} finally {
ctx = null;
cmd = null;
SshScopes.current.set(old);
SshScope.set(old);
}
}
}