How do I find out current logged in user?

Abhijit Jadeja November 17, 2012

I am trying to write a plugin and I would like to know how to get User object for the currently logged in user.

In the past I have used couple of differnt user managers and two separate methods but I'd like to know if there is any specific way atlassian recommends.

	public ProjectVersionManager(VersionService versionService,
			UserManager um,  com.atlassian.jira.user.util.UserManager um1,ReleaseService service) {
		this.versionService = versionService;
		this.releaseService = service;
		this.um = um;
		this.um1=um1;
	}

	public void updateProjectVersion(long id, String name) {
		String username = um.getRemoteUsername();
		User user = um1.getUser(username);
		VersionResult v = versionService.getVersionById(
				user, id);
}

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

16 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2012

Use this:

ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

Or as thats now deprecated

ComponentAccessor.getJiraAuthenticationContext().getUser()
Abhijit Jadeja November 21, 2012

Thanks Jobin. This works.

MB
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 14, 2013

Just to comment on this.

getLoggedInUser() is now deprecated. This question deals with the new way of getting the logged in user.

0 votes
aparajita kulkarni July 24, 2013

Thank you abhijit,

Ya now i gone through the below link, and got some idea how to write or implement code.

https://developer.atlassian.com/display/DOCS/Control+access+with+SAL

Your link also helped me in understanding database and issue related things. Thank you

0 votes
aparajita kulkarni July 17, 2013

Hi Abhijit,

Can u please tell me where to write this code and how to implement. Because currently my requirement is I need following details of user to be retrieved and I want to pass that information in webitem link.

Can you please help me as soon as possible.

Regards,

Aparajita

Abhijit Jadeja July 23, 2013

Aparajita,

Not sure how to pass it to web item link. But any class can use what Jobin's solution suggests. You need a class defined in the plugin and that class can access getLoggedInuser method described by Jobin.

I am sure you have looked up documentation but you can find useful information on how to write a plugin here:

https://developer.atlassian.com/display/JIRADEV/JIRA+Developer+Documentation

0 votes
danielwester
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2012

If your action is implementing JiraWebActionsupport - then http://docs.atlassian.com/jira/latest/com/atlassian/jira/web/action/JiraWebActionSupport.html#getLoggedInUser() is the easier one.

Abhijit Jadeja November 21, 2012

This works for the Webwork Action class. I was looking for something that uses the REST service.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events