How can I access the currently logged in user inside of a servlet?

Hello,

I am trying to figure out how I can get the currently logged in user from a Servlet. In my servlet I have running a Web Application, and all is working well however I can’t seem to figure out how to get info about the currently logged in user. There doesn’t appear to be any meaningful user tokens stored in LocalStorage, SessionStorage or Cookies (at least none that looked like they could be usable to get that info) and I wouldn’t know how to pass the JiraAuthenticationContext into the running application inside the servlet, or pass any data at all for that matter (not sure that’s even possible) and I can’t find anything in the Jira API on how to pull the currently logged in user, either. I figured maybe there was a way to access it via AJS but so far it doesn’t appear so.

I’m kind of baffled that something as trivial as having access to the logged in user is such a difficult thing to achieve in Jira Plugins.

If anyone has any suggestions It would be greatly appreciated.

You can get access to exposed services like JiraAuthenticationContext by importing them using Spring config: https://developer.atlassian.com/server/framework/atlassian-sdk/spring-java-config/

Alternatively, if you prefer auto-wiring them to properties or class constructor parameters, you can use Spring Scanner: Bitbucket

4 Likes