Deactivating user in Java

Hi everybody,

I am looking for a way to deactivate a user from a Bitbucket Server app. In Jira I would know how to do it:

  • retrieving the user
  • Creating an ImmutableUser object (from embedded crowd)based on the existing user
  • setting the activated flag to false
  • Updating the user with the UserManager

But the updateUser method from BitBucket Usermanager does not accept a user object. Does the BitBucket SDK provide a different method, which allows deactivating users from the code?
Regards,
Alexander

Hi @alexander.kueken,

I’m trying to go through all the Java APIs, I’d like to confirm if the UserManager that you’re referring to is this? I’m trying to see if the ImmutableUser and the User you’re trying to play around has the same parent or what not, like implements or extends some sort of User or Principal class. I’m really curious how to do this. I’m looking at the UserAdminService and UserService of the Bitbucket Server API.

Thanks!

Cheers,
Anne Calantog

Hi Anne,

I mixed up UserService and UserManager. Under Jira I would solve it like this:

import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor

...

User updateUser
UserService.UpdateUserValidationResult updateUserValidationResult

user = ... // get your user

updateUser = ImmutableUser.newUser(user).active(false).toUser()
updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
	userService.updateUser(updateUserValidationResult)
}

But in Bitbucket, the UserService only accept username, displayname and e-mail address in UserAdminService, or displayname and e-mail address in UserService.

Regards,
Alexander