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

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 ?

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Asked yesterday in Data Center

Hi! I'm Cameron Deatsch, enterprise enthusiast and Head of Server at Atlassian. AMA!

Hey team! I'm Cameron Deatsch, Head of Server at Atlassian. At our European Summit just a few weeks ago, I spoke about the latest regarding our Server and Data center products and o...

19,423 views 4 4
View question

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you