use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class ThreadLocalRequestContext method module.
public static Module module() {
return new AbstractModule() {
@Override
protected void configure() {
bind(ThreadLocalRequestContext.class);
bind(RequestContext.class).annotatedWith(Names.named(FALLBACK)).to(FallbackRequestContext.class);
}
@Provides
RequestContext provideRequestContext(@Named(FALLBACK) RequestContext fallback) {
return MoreObjects.firstNonNull(local.get(), fallback);
}
@Provides
CurrentUser provideCurrentUser(RequestContext ctx) {
return ctx.getUser();
}
@Provides
IdentifiedUser provideCurrentUser(CurrentUser user) {
if (user.isIdentifiedUser()) {
return user.asIdentifiedUser();
}
throw new ProvisionException(NotSignedInException.MESSAGE, new NotSignedInException());
}
@Provides
ReviewDb provideReviewDb(RequestContext ctx) {
return ctx.getReviewDbProvider().get();
}
};
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class PRED_current_user_2 method createUser.
public Term createUser(Prolog engine, Term key) {
if (!(key instanceof StructureTerm) || key.arity() != 1 || !((StructureTerm) key).functor().equals(user)) {
throw new IllegalTypeException(this, 1, "user(int)", key);
}
Term idTerm = key.arg(0);
CurrentUser user;
if (idTerm instanceof IntegerTerm) {
Map<Account.Id, IdentifiedUser> cache = StoredValues.USERS.get(engine);
Account.Id accountId = new Account.Id(((IntegerTerm) idTerm).intValue());
user = cache.get(accountId);
if (user == null) {
IdentifiedUser.GenericFactory userFactory = userFactory(engine);
IdentifiedUser who = userFactory.create(accountId);
cache.put(accountId, who);
user = who;
}
} else if (idTerm.equals(anonymous)) {
user = StoredValues.ANONYMOUS_USER.get(engine);
} else {
throw new IllegalTypeException(this, 1, "user(int)", key);
}
return new JavaObjectTerm(user);
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class AccountsCollection method parseIdOnBehalfOf.
private IdentifiedUser parseIdOnBehalfOf(@Nullable CurrentUser caller, String id) throws AuthException, OrmException {
if (id.equals("self")) {
CurrentUser user = self.get();
if (user.isIdentifiedUser()) {
return user.asIdentifiedUser();
} else if (user instanceof AnonymousUser) {
throw new AuthException("Authentication required");
} else {
return null;
}
}
Account match = resolver.find(db.get(), id);
if (match == null) {
return null;
}
CurrentUser realUser = caller != null ? caller.getRealUser() : null;
return userFactory.runAs(null, match.getId(), realUser);
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class ChangeQueryBuilder method watchedby.
@Operator
public Predicate<ChangeData> watchedby(String who) throws QueryParseException, OrmException {
Set<Account.Id> m = parseAccount(who);
List<IsWatchedByPredicate> p = Lists.newArrayListWithCapacity(m.size());
Account.Id callerId;
try {
CurrentUser caller = args.self.get();
callerId = caller.isIdentifiedUser() ? caller.getAccountId() : null;
} catch (ProvisionException e) {
callerId = null;
}
for (Account.Id id : m) {
// Each child IsWatchedByPredicate includes a visibility filter for the
// corresponding user, to ensure that predicate subtree only returns
// changes visible to that user. The exception is if one of the users is
// the caller of this method, in which case visibility is already being
// checked at the top level.
p.add(new IsWatchedByPredicate(args.asUser(id), !id.equals(callerId)));
}
return Predicate.or(p);
}
Aggregations