Search in sources :

Example 21 with CurrentUser

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

the class SshLog method log.

private LoggingEvent log(final String msg) {
    final SshSession sd = session.get();
    final CurrentUser user = sd.getUser();
    final LoggingEvent event = new //
    LoggingEvent(// fqnOfCategoryClass
    Logger.class.getName(), // logger
    log, // when
    TimeUtil.nowMs(), // level
    Level.INFO, // message text
    msg, // thread name
    "SSHD", // exception information
    null, // current NDC string
    null, // caller location
    null, // MDC properties
    null);
    event.setProperty(P_SESSION, id(sd.getSessionId()));
    String userName = "-";
    String accountId = "-";
    if (user != null && user.isIdentifiedUser()) {
        IdentifiedUser u = user.asIdentifiedUser();
        userName = u.getAccount().getUserName();
        accountId = "a/" + u.getAccountId().toString();
    } else if (user instanceof PeerDaemonUser) {
        userName = PeerDaemonUser.USER_NAME;
    }
    event.setProperty(P_USER_NAME, userName);
    event.setProperty(P_ACCOUNT_ID, accountId);
    return event;
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) CurrentUser(com.google.gerrit.server.CurrentUser) Logger(org.apache.log4j.Logger) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) PeerDaemonUser(com.google.gerrit.server.PeerDaemonUser)

Example 22 with CurrentUser

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

the class HttpLogoutServlet method doGet.

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse rsp) throws IOException {
    final String sid = webSession.get().getSessionId();
    final CurrentUser currentUser = webSession.get().getUser();
    final String what = "sign out";
    final long when = TimeUtil.nowMs();
    try {
        doLogout(req, rsp);
    } finally {
        audit.dispatch(new AuditEvent(sid, currentUser, what, when, null, null));
    }
}
Also used : CurrentUser(com.google.gerrit.server.CurrentUser) AuditEvent(com.google.gerrit.audit.AuditEvent)

Example 23 with CurrentUser

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

the class GetUserFilter method doFilter.

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
    CurrentUser user = userProvider.get();
    if (user != null && user.isIdentifiedUser()) {
        IdentifiedUser who = user.asIdentifiedUser();
        if (who.getUserName() != null && !who.getUserName().isEmpty()) {
            req.setAttribute(REQ_ATTR_KEY, who.getUserName());
        } else {
            req.setAttribute(REQ_ATTR_KEY, "a/" + who.getAccountId());
        }
    }
    chain.doFilter(req, resp);
}
Also used : CurrentUser(com.google.gerrit.server.CurrentUser) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Example 24 with CurrentUser

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

the class GroupsCollection method parse.

@Override
public GroupResource parse(TopLevelResource parent, IdString id) throws AuthException, ResourceNotFoundException {
    final CurrentUser user = self.get();
    if (user instanceof AnonymousUser) {
        throw new AuthException("Authentication required");
    } else if (!(user.isIdentifiedUser())) {
        throw new ResourceNotFoundException(id);
    }
    GroupDescription.Basic group = parseId(id.get());
    if (group == null) {
        throw new ResourceNotFoundException(id.get());
    }
    GroupControl ctl = groupControlFactory.controlFor(group);
    if (!ctl.isVisible()) {
        throw new ResourceNotFoundException(id);
    }
    return new GroupResource(ctl);
}
Also used : GroupDescription(com.google.gerrit.common.data.GroupDescription) GroupControl(com.google.gerrit.server.account.GroupControl) CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) AnonymousUser(com.google.gerrit.server.AnonymousUser) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 25 with CurrentUser

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

the class CommitMessageOutputTest method realUser.

@Test
public void realUser() throws Exception {
    Change c = newChange();
    CurrentUser ownerAsOtherUser = userFactory.runAs(null, otherUserId, changeOwner);
    ChangeUpdate update = newUpdate(c, ownerAsOtherUser);
    update.setChangeMessage("Message on behalf of other user");
    update.commit();
    RevCommit commit = parseCommit(update.getResult());
    PersonIdent author = commit.getAuthorIdent();
    assertThat(author.getName()).isEqualTo("Other Account");
    assertThat(author.getEmailAddress()).isEqualTo("2@gerrit");
    assertBodyEquals("Update patch set 1\n" + "\n" + "Message on behalf of other user\n" + "\n" + "Patch-set: 1\n" + "Real-user: Change Owner <1@gerrit>\n", commit);
}
Also used : CurrentUser(com.google.gerrit.server.CurrentUser) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Change(com.google.gerrit.reviewdb.client.Change) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

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