How to get current logged-in user in MailListener.java (for Jira version 7.0.10) ?

Andrew L June 16, 2017

I need to modify MailListener.java (for Jira version 7.0.10) to NOT send out email if the current logged-in user is <some-userid>.

Here's the code snippet of MailListener.java :

...........
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
..............

private static final ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(); 

......

 @EventListener
 public void handleIssueEventBundle(final IssueEventBundle bundle) {
   
  if (currentUser == null) {
      log.error("Cannot determine current logged-in user");  // <<<<--------- this error shows up in the log
      return;
     }
  if (currentUser.getUsername().equals(specialUser)) {
      log.debug("1. Ignore sending email notification because user=[" + currentUser.getUsername() + "]");
      return;
     }

   issueEventBundleMailHandler.handle(bundle);
}

 

In the atlassian-jira.log, i see:

   [c.a.j.e.listeners.mail.MailListener] Cannot determine current logged-in user

What is the correct way to get the current logged-in user in MailListener.java ?

 

 

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2023

Hi @Andrew L ,

I don't understand what is mailListener, both mail handlers and listeners are executed by system and not by a specific user. This should be reason why you can't retrieve the current ulogged user.

Fabio

Suggest an answer

Log in or Sign up to answer