How to use SpacePermissionContext

I’m trying to set the permission on a space, using the non-deprecated method for doing so, but I´m unsure how to do so.

I create a SpacePermission object which works fine, when using the deprecated method, if I try to use the same SpacePermission together with a default SpacePermissionContext object I get an error (Cannot invoke method savePermission() on null object) which leads me to believe that I´m not creating the SpacePermissionContext correctly.

What am I doing wrong?

import com.atlassian.confluence.spaces.Space
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.spaces.SpaceManager
SpacePermissionManager spacePermissionManager = ComponentLocator.getComponent(SpacePermissionManager)
SpacePermissionSaverInternal spacePermissionSaveManagerInternal = ComponentLocator.getComponent(SpacePermissionSaverInternal)
SpacePermissionSaver spacePermissionSaveManager = ComponentLocator.getComponent(SpacePermissionSaver)
SpaceManager spaceManager = ComponentLocator.getComponent(SpaceManager)

Space space = spaceManager.getSpace("GATTS") 

SpacePermission spacePM = new SpacePermission("COMMENT", space, "all-internal-users")
//spacePM = spacePM.createGroupSpacePermission("COMMENT", spaceManager.getSpace("GATTS") , "all-internal-users")

SpacePermissionContext context = SpacePermissionContext.createDefault()

spacePermissionSaveManagerInternal.savePermission(spacePM, context) //Cannot invoke method savePermission() on null object
//spacePermissionManager.savePermission(spacePM) //this works

1 Like

Hello @anders.lantz,

In creating SpacePermissionContext, try this one if it works for you

SpacePermissionContext context = SpacePermissionContext.builder().build()


Hi @anders.lantz,

I got the same problem, and it’s ComponentLocator.getComponent(SpacePermissionManager) that is returning null. Use space.addPermission instead and it will work.

1 Like

This post says that the Internal classes are not available to people outside of Atlassian.
However, the documentation says the interface is public.
I’m so confused. :confused: