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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Confluence Scriptrunner: Copy users from space permissions to the local group

Hi guys,

due to poor architecture when one of my customer started their implementation, they ended in situation with one space and 400+ users INDIVIDUALLY assigned with same permissions.

Now I am in front of "copying" this configuration. 

Need new space, with same permission setup.

I am looking for solution in ScriptRunner to:

  1. Get all users listed in permissions
  2. Get their keys 
  3. Insert them into local group (could be hardcoded, one time action)

I am advanced in Jira ScriptRunner, but kind of newbie in Confluence version.

Confluence 7.4.0

ScriptRunner 6.2.0-p5


1 answer

1 accepted

Hi Tomáš!! 

I've added an example script here which should solve the issue you are facing! 

It will iterate through the permissions of a specified space, extract all users with individual view permissions to that space and add them a group of your choosing! 

Once you've got your group set up, you can use the example here to provide the required permissions for this group to your new space.

I hope this helps but let me know if you have any further questions. :) 

Kind regards, 

Hi Lee! Thank you for this, I will try that ASAP :-) 

Will let you know, instance is 10000+ automotive users so I have to test it carefully.

Hi Lee!

Your script is working. I just little bit extend the conditions and made automatic split into 4 types of groups based on permission combinations.

Thanks for guiding me!


@Lee Wonnacott _Adaptavist_ 

Hi Lee!

I extended the script and getting errors like this:

2021-02-05 15:47:37,792 ERROR [common.UserScriptEndpoint]: ************************************************************************************* 2021-02-05 15:47:37,812 ERROR [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: com.sun.proxy.$Proxy119.addMembership() is applicable for argument types: (ArrayList, com.atlassian.confluence.user.ConfluenceUserImpl_$$_jvstb74_3) values: [[ConfluenceUserImpl{name='DZCMDH9', key=8a5935844efbe4a1014f88ebfb970008}, ...], ...] Possible solutions: addMembership(com.atlassian.user.Group, com.atlassian.user.User), hasMembership(com.atlassian.user.Group, com.atlassian.user.User) at Script160$_run_closure4.doCall(Script160.groovy:58) at

The script itself is:

Any ideas what is wrong?

import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.GroupManager

def spacePermissionManager = ComponentLocator.getComponent(SpacePermissionManager)
def spaceManager = ComponentLocator.getComponent(SpaceManager)
def groupManager = ComponentLocator.getComponent(GroupManager)

def groupReadOnly = groupManager.getGroup("cem_conf_read_only")
def groupReadWrite = groupManager.getGroup("cem_conf_read_write")
def groupRestriction = groupManager.getGroup("cem_conf_restrictions")
def groupSpaceOwner = groupManager.getGroup("cem_conf_space_owner")
def groupSpaceAdmin = groupManager.getGroup("cem_conf_space_admin")

def spacePermissions = []
def sourceSpace = spaceManager.getSpace("CMS")

def usersReadOnly = []
def usersReadWrite = []
def usersRestriction = []
def usersSpaceOwner = []
def usersSpaceAdmin = []

spacePermissions = sourceSpace.getPermissions()

spacePermissions.each{ permission ->
if (permission.getUserSubject() && permission.getType() == "VIEWSPACE")
if (permission.getUserSubject() && permission.getType() == "EDITSPACE")
if (permission.getUserSubject() && permission.getType() == "SETPAGEPERMISSIONS")
if (permission.getUserSubject() && permission.getType() == "EXPORTSPACE")
if (permission.getUserSubject() && permission.getType() == "SETSPACEPERMISSIONS")

usersReadOnly.each{ user ->
groupManager.addMembership(groupReadOnly, user)
usersReadWrite.each{ user ->
groupManager.addMembership(groupReadWrite, user)
usersRestriction.each{ user ->
groupManager.addMembership(usersRestriction, user)
usersSpaceOwner.each{ user ->
groupManager.addMembership(usersSpaceOwner, user)
usersSpaceAdmin.each{ user ->
groupManager.addMembership(usersSpaceAdmin, user)

Nevermind. I can see typo now. :-D 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

156 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you