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;
}
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));
}
}
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);
}
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);
}
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);
}
Aggregations