Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

How to manage/disable user by Java API in Jira/Bitbucket/Confluence server

Sooxin January 14, 2021 edited

Hi everyone,

 

I'm developing a  plugin to manage Jira/Confluence/Bitbucket user. I need use related Java APIs to add/remove user into/from group and disable/enable user. 

I've found some Java APIs such as:

  1. com.atlassian.jira.user.util.UserUtil#removeUserFromGroup for jira membership
  2. com.atlassian.user.GroupManager#removeMembership for confluence membership

 

But could anyone help tell Java APIs or examples about below cases? 

Java API For Jira:

  • Enable/disable Jira User

Java API For Confluence: 

  •  Enable/disable Confluence user

Java API For Bitbucket

  • Add/remove user from specific group
  • Enable/disable Bitbucket User

 

Thanks a lot.

 

 

 

 

 

2 answers

2 accepted

1 vote
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2021 edited

Hi @Sooxin I have something for Jira:

ApplicationUser user = ...your active user...

ApplicationUser updatedUser = userService.newUserBuilder(user).active(false).build();// where userService is instance of this - com.atlassian.jira.bc.user.UserService
UserService.UpdateUserValidationResult validationResult = userService.validateUpdateUser(updatedUser);
if (validationResult.isValid()) {
userService.updateUser(validationResult);
} else {
log.error("Deactivation of user failed:" + validationResult.getErrorCollection());
}

 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2021 edited

FOr Confluence, following service looks interesting:

https://docs.atlassian.com/atlassian-confluence/6.6.0/com/atlassian/confluence/user/DisabledUserManager.html

 

For Bitbucket, this service looks nice, but I can't find a method/service which disables a user :(

https://docs.atlassian.com/bitbucket-server/javadoc/7.9.0/api/com/atlassian/bitbucket/user/UserAdminService.html

Sooxin January 16, 2021

Wow, thank you @Martin Bayer _MoroSystems_ s_r_o__ . It must be helpful, I'll test it next week. 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 16, 2021

@Sooxin ok, let me know if anything is not working or if you find out how to manage it in the Bitbucket :)

0 votes
Answer accepted
Sooxin February 3, 2021 edited

Thanks to @Martin Bayer _MoroSystems_ s_r_o__ , after researching and testing, I think below APIs are helpful:

jira

  • com.atlassian.jira.user.util.UserUtil#removeUserFromGroup
  • com.atlassian.jira.user.util.UserUtil#addUserToGroup

Confluence

  • com.atlassian.user.GroupManager#addMembership
  • com.atlassian.user.GroupManager#removeMembership
  • com.atlassian.confluence.user.DisabledUserManager#disableUser
  • com.atlassian.confluence.user.DisabledUserManager#enableUser

Bitbucket

  • com.atlassian.bitbucket.user.UserAdminService#addUserToGroups
  • com.atlassian.bitbucket.user.UserAdminService#removeUserFromGroup

However, it seems Bitbucket APIs listed above requires some "strange" privileges, My cron in plugin cannot call it successfully. Finally, as an alternative, I wrote a API client by retrofit to call the restful APIs.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2021

Thank you @Sooxin for your feedback... good job :)

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, ace, atlassian community event, donation, girls who code, women in tech, malala fund, plan international, kudos, community badge, badge, atlassian badge, International Women’s month, International Women’s Day, women's month, women's day

10 for Change at Atlassian Community Events

Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!

Join an Atlassian Community Event!
AUG Leaders

Upcoming Jira Events