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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user