How do I merge duplicate users?

Andi Zhou July 23, 2021

I have setup JIRA hosted in Linux server (On Prem), connected to an external Microsoft Active Directory LDAP and now my client has moved the instance to AWS cloud, connected to same Microsoft Active Directory with SAML authentication or MFA.

However, the username format is not same. The on prem instance is using the AD enterprise username as username while the AWS is using the AD email as username. After using the Configuration Manager tool/plugin to capture a snapshot from the on prem instance and deploy to the AWS instance, same user is having two accounts. Also, content ownership, issue association and permissions are not being migrated to the new username.

Using "Charlie Atlassian" as the example user, in the original directory his username is "catlassian", but in the new directory it will be "charlie.atlassian@domainname.com". I want to make sure that once I have migrated projects from the on prem instance to AWS instance, I want Charlie's username should merge to the aws username format, therefore Charlie should only have one username. Also, I want content ownership, issue association and permissions from on prem instance migrated to the new username in aws. I have written the below script using Scriptrunner and I am getting “user already exist with same user name” error message.

import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService

def userManager = ComponentAccessor.userManager
def userService = ComponentAccessor.getComponent(UserService)
def userSearchService = ComponentAccessor.getComponent(UserSearchService)

[
'testusername',

// add more as required by separating them in a comma (,)
].each { username ->
//def username = userSearchService.findUsersByEmail(userEmail.toString()).iterator().next().getKey()
def user = userManager.getUserByName(username)
if (!user) {
log.warn "Could not find user ${username}"
return
}

def updatedUser = userService.newUserBuilder(user).name("PavanKumar.Chityala@dhs.arkansas.gov").build()

def updateUserValidationResult = userService.validateUpdateUser(updatedUser)

if (updateUserValidationResult.isValid()) {
log.warn "Updating user ${username}"
userService.updateUser(updateUserValidationResult)
} else {
log.warn "Update of ${user.name} failed: ${updateUserValidationResult.errorCollection.errors.entrySet().join(',')}\n"
}
}

Merging user error.JPG

Above error in the picture above is what I get when I run the code snippet I have

Ideally I want the script to identify duplicate users with the same email address, merge the users and make the emails their username. Based on my research, simply adding the new directory then disabling the original directory will not transfer over issue associations.

 

1 answer

0 votes
Benjamin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 23, 2021

@Andi Zhou 

 

Done something like this a while back. Since you are using configuration manager, you can modify the snapshot by swapping our the users to the users you want. But first, you need to create a mapping table to figure which users are map to those particular e-mail address and then apply script to swap. Then when you deploy the snapshot, the new users will take into account with the username as e-mail addresses.

 

Hope this helps.

Andi Zhou July 26, 2021

Thanks for the reply Benjamin! Did that method carry over the issue associations?

Benjamin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2021

You welcome. As I recall, yes. The newly mapped users will replace the previous users of those associated tickets.

Philemon Nkafu August 25, 2021

@Benjamin 

Am having a similar task and would appreciate you expanding further.

Are you suggesting that once the snapshot has  been captured, the usernames can be changed in the snapshot before deploying to the target instance? 

Or  are you suggesting that the users be identified and the script ran in the source instance to modify the identified users before the snapshot is captured?

Please help Newbies understand the best approach here.

Thanks 

Benjamin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 29, 2021

Hi @Philemon Nkafu ,

 

Ideally, you should have a table of where those users would be mapped.

 

capture a snapshot. Then open the file and make the modification with either a script or a tool of choice. Then close the snapshot and then deploy it at the destination.

 

-Ben

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events