Fix SSH based CurrentUser to know what the database is

When we ask for the CurrentUser or IdentifiedUser in an SSH request we
kept pulling back some oddity off the SshSession that didn't have a
request scoped Provider<ReviewDb>.  This meant that we couldn't get
access to database backed entities like the starred changes of the
user.

Recreate the identity object on the fly when its first asked for
within the command request scope.  This way the Provider<ReviewDb> can
be bound and used as expected.

Change-Id: I141e9bf20a52596cfbbf859aa14403ceba164e73
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-07-19 07:10:11 -07:00
parent 6a4ff33e80
commit a39a7d922d
2 changed files with 14 additions and 3 deletions

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.sshd;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -22,14 +23,20 @@ import com.google.inject.Singleton;
@Singleton
class SshCurrentUserProvider implements Provider<CurrentUser> {
private final Provider<SshSession> session;
private final Provider<IdentifiedUser> identifiedProvider;
@Inject
SshCurrentUserProvider(final Provider<SshSession> s) {
SshCurrentUserProvider(Provider<SshSession> s, Provider<IdentifiedUser> p) {
session = s;
identifiedProvider = p;
}
@Override
public CurrentUser get() {
final CurrentUser user = session.get().getCurrentUser();
if (user instanceof IdentifiedUser) {
return identifiedProvider.get();
}
return session.get().getCurrentUser();
}
}

View File

@@ -25,17 +25,21 @@ import com.google.inject.Singleton;
@Singleton
class SshIdentifiedUserProvider implements Provider<IdentifiedUser> {
private final Provider<SshSession> session;
private final IdentifiedUser.RequestFactory factory;
@Inject
SshIdentifiedUserProvider(final Provider<SshSession> s) {
SshIdentifiedUserProvider(Provider<SshSession> s,
IdentifiedUser.RequestFactory f) {
session = s;
factory = f;
}
@Override
public IdentifiedUser get() {
final CurrentUser user = session.get().getCurrentUser();
if (user instanceof IdentifiedUser) {
return (IdentifiedUser) user;
return factory.create(user.getAccessPath(), //
((IdentifiedUser) user).getAccountId());
}
throw new ProvisionException(NotSignedInException.MESSAGE,
new NotSignedInException());