Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Get all users in custom Macro or Plugion

Felix Hammann August 15, 2012

Hi all,

I'm new in "Atlassian development". I want to realise a very simple task: Receive all Confluence user in my Confluence Macro and list them (I know, there already exists a similar pre-installed macro, but I want to extend my macro later). I have searched for many hours until now... wihtout success. Is there any example/tutorial etc. on the web? Has anybody a hint / an example for me how to realise this task? Unfortunately I have no starting point, which classes might I use?

Thank you very much for help (and sorry for my english, its not the best...),

Felix

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Oli S
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 15, 2012

You coukd use the UsserAccessor component.

UserAccessor userAccessor= (UserAccessor )ContainerManager.getInstance().getContainerContext().getComponent("userAccessor");

Pager<User> users = userAccessor.getUsers();
Pager<String> userNames = userAccessor.getUserNames();

In a usermacro youn could do:

#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($userAccessor= $containerContext.getComponent('userAccessor'))
#set($users = $userAccessor.getUsers())

Hope this helps :-)

Felix Hammann August 15, 2012

Hi, thank you very, very much. That was exactly the approach I have looked for :-)

Royce Wong
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.
February 7, 2015

How do you know you you need com.atlassian.spring.container.ContainerManager to create an instance of com.atlassian.confluence.user.UserAccessor is beyond me, :) For reference this is how you do it using APIs: {code} userAccessor = (UserAccessor) ContainerManager.getInstance().getContainerContext().getComponent(UserAccessor.class); {code} Do you know how to create an instance of com.atlassian.user.GroupManager? I tried serveral ways but no luck. I need to to use with com.atlassian.confluence.user.UserAccessor's method getMembers(com.atlassian.user.Group group). Thanks.

TAGS
AUG Leaders

Atlassian Community Events