Search in sources :

Example 16 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class ChangeResource method getETag.

@Override
public String getETag() {
    CurrentUser user = control.getUser();
    Hasher h = Hashing.md5().newHasher();
    if (user.isIdentifiedUser()) {
        h.putString(starredChangesUtil.getObjectId(user.getAccountId(), getId()).name(), UTF_8);
    }
    prepareETag(h, user);
    return h.hash().toString();
}
Also used : Hasher(com.google.common.hash.Hasher) CurrentUser(com.google.gerrit.server.CurrentUser)

Example 17 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class Abandon method abandon.

public Change abandon(BatchUpdate.Factory updateFactory, ChangeControl control, String msgTxt, NotifyHandling notifyHandling, ListMultimap<RecipientType, Account.Id> accountsToNotify) throws RestApiException, UpdateException {
    CurrentUser user = control.getUser();
    Account account = user.isIdentifiedUser() ? user.asIdentifiedUser().getAccount() : null;
    AbandonOp op = abandonOpFactory.create(account, msgTxt, notifyHandling, accountsToNotify);
    try (BatchUpdate u = updateFactory.create(dbProvider.get(), control.getProject().getNameKey(), control.getUser(), TimeUtil.nowTs())) {
        u.addOp(control.getId(), op).execute();
    }
    return op.getChange();
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) CurrentUser(com.google.gerrit.server.CurrentUser) AbandonOp(com.google.gerrit.server.git.AbandonOp) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 18 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class PRED_current_user_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    CurrentUser curUser = StoredValues.CURRENT_USER.getOrNull(engine);
    if (curUser == null) {
        throw new EvaluationException("Current user not available in this rule type");
    }
    Term resultTerm;
    if (curUser.isIdentifiedUser()) {
        Account.Id id = curUser.getAccountId();
        resultTerm = new IntegerTerm(id.get());
    } else if (curUser instanceof AnonymousUser) {
        resultTerm = anonymous;
    } else if (curUser instanceof PeerDaemonUser) {
        resultTerm = peerDaemon;
    } else {
        throw new EvaluationException("Unknown user type");
    }
    if (!a1.unify(new StructureTerm(user, resultTerm), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) CurrentUser(com.google.gerrit.server.CurrentUser) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) AnonymousUser(com.google.gerrit.server.AnonymousUser) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) EvaluationException(com.googlecode.prolog_cafe.exceptions.EvaluationException) PeerDaemonUser(com.google.gerrit.server.PeerDaemonUser)

Example 19 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class LabelNormalizerTest method setUpInjector.

@Before
public void setUpInjector() throws Exception {
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    lifecycle.start();
    db = schemaFactory.open();
    schemaCreator.create(db);
    userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    user = userFactory.create(userId);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
    configureProject();
    setUpChange();
}
Also used : CurrentUser(com.google.gerrit.server.CurrentUser) Injector(com.google.inject.Injector) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) Provider(com.google.inject.Provider) Before(org.junit.Before)

Example 20 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class SshLog method audit.

private void audit(Context ctx, Object result, String cmd, ListMultimap<String, ?> params) {
    String sessionId;
    CurrentUser currentUser;
    long created;
    if (ctx == null) {
        sessionId = null;
        currentUser = null;
        created = TimeUtil.nowMs();
    } else {
        SshSession session = ctx.getSession();
        sessionId = IdGenerator.format(session.getSessionId());
        currentUser = session.getUser();
        created = ctx.created;
    }
    auditService.dispatch(new SshAuditEvent(sessionId, currentUser, cmd, created, params, result));
}
Also used : SshAuditEvent(com.google.gerrit.audit.SshAuditEvent) CurrentUser(com.google.gerrit.server.CurrentUser)

Aggregations

CurrentUser (com.google.gerrit.server.CurrentUser)44 Account (com.google.gerrit.reviewdb.client.Account)14 AuthException (com.google.gerrit.extensions.restapi.AuthException)11 Provider (com.google.inject.Provider)8 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)7 Change (com.google.gerrit.reviewdb.client.Change)6 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)6 Project (com.google.gerrit.reviewdb.client.Project)6 RequestContext (com.google.gerrit.server.util.RequestContext)6 ThreadLocalRequestContext (com.google.gerrit.server.util.ThreadLocalRequestContext)6 InMemoryModule (com.google.gerrit.testutil.InMemoryModule)6 OrmException (com.google.gwtorm.server.OrmException)6 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)5 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)5 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)5 HashMap (java.util.HashMap)5 LabelType (com.google.gerrit.common.data.LabelType)4 LifecycleManager (com.google.gerrit.lifecycle.LifecycleManager)4 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)4 ChangeControl (com.google.gerrit.server.project.ChangeControl)4