Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Sooxin January 14, 2021

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 Champion
January 14, 2021

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 Champion
January 14, 2021

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 Champion
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

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 Champion
February 3, 2021

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

Suggest an answer

Log in or Sign up to answer