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.internal.security.SpacePermissionContext;
import com.atlassian.confluence.internal.security.SpacePermissionManagerInternal
import com.atlassian.confluence.security.SpacePermissionManager
import com.atlassian.confluence.internal.security.SpacePermissionSaverInternal
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.security.SpacePermissionSaver
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.confluence.security.SpacePermission
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.setSpace(spaceManager.getSpace("GATTS"))
//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