The basic management of Confluence Space permissions is quite trivial. However if you spend any time on the internet looking for a solution, you’ll find yourself going in circles, or starting to believe that Space permissions management is only possible via the front-end.
There are essentially two ways in which an Atlassian product may be programmatically managed. It may be done via the REST API, or you may use a plugin such a ScriptRunner that allows you to write Groovy scripts that make use of internal Atlassian classes and methods.
There is currently no obvious or easy way to use the REST API to make permissions changes to a Confluence Space on Confluence Server. Please note that this is different that permissions management of individual Confluence pages.
Instead what we need to do is look backwards, to the JSON RPC system that Atlassian used to use.
What I like about these RPC calls is that I can call them using CURL, or I can access the library through the ScriptRunner Console. Here’s the basic code:
import com.atlassian.confluence.rpc.soap.services.SpacesSoapService
import com.atlassian.sal.api.component.ComponentLocator
def addSpacePermission = ComponentLocator.getComponent(SpacesSoapService)
def String[] permissions = ["EDITSPACE"]
def String remoteEntity = "<UserOrGroup>"
def String spaceKey = "<spaceKey>"
addSpacePermission.addPermissionsToSpace(permissions, remoteEntity, spaceKey)
//Add permission to the target space: array of permissions, the user or group to be added, and the target space key
Notice that we’re importing the SOAP services library. The only other library we need to import is the Component Locator.
After importing the libraries, we need to tell the Component Locator to retrieve the Soap Services functionality. By defining this, we can then call the methods of the SOAP Service.
Finally, we feed the variables to the method. Please note that the method only accepts an array as the first argument; you can’t goose it and use a string.
You can also call the RPC API from within a script, using CURL.
curl --user <username>:<password> -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{
"jsonrpc" : "2.0", "method" : "addPermissionToSpace", "params" : ["<Permission Types>"], "<User Or Group>", "<Space Key>"], "id": 7 }' <Confluence URL>/rpc/json-rpc/confluence/service-v2?os_authType=basic
It really is that simple. Hopefully Atlassian will update the REST API to allow for Space permissions management in the near future.
Leave a Reply