Is there a Java API to remove a permissions from a Space

Andreas von Euw July 6, 2018

We've build a custom Confluence Plugin for managing Space permissions.

In Confluence 5.9 we've used com.atlassian.confluence.spaces.Space.removePermission to remove a existing permission from a Space. This does not work anymore with Confluence 6.x

Does somebody know how to implement this in newer Confluence Versions?

1 answer

0 votes
Steven Kling June 6, 2019

@Andreas von Euw did you ever find an answer? The only way I see in the 6.x Java API to get user-related permissions:

DefaultSpaceManager.getAllPermissionsForUser(ConfluenceUser user) 

...but its protected and not accessible via the API.

I have a list of ConfluenceUser(s) and have to remove them from a specific space's permissions. I see no way of accomplishing this aside from a nuclear option:

//Remove all permissions entirely
DefaultSpaceManager.removeAllPermissions(Space space) 

...then rebuilding all remaining users based on a predefined role-permission mapping

 

Forgot to add, if you have the SpacePermission already you can use this:

removePermission(SpacePermission permission, SpacePermissionContext context)

creating the SpacePermissionContext is straightforward:

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

You can add event-related options to the context if you want to suppress them, etc. 

Damian Jesionek December 19, 2019

@Steven Klingwhich classes removePermission() are you using, since most of them are deprecated in the most recent versions. Also I have issues using Classes from the package com.atlassian.confluence.internal.security (like SpacePermissionContext from you solution).

I suppose they are protected? Is there a way to use them?

Thanks in advance!

 

EDIT:

I also settled to use removeAllPermissions() which is also quite hacky as you need to prevent the side effects that result from this method call (space attribute of the permissions are set to null and the list is cleared).
A prettier solution for that would be appreciated I think

Thomas Clemens April 28, 2020

I am stuck @exactly the same spot. Everything I try to use is deprecated or not working. Everything new I try to import is protected. So frustrating to write scheduled Tasks for this.. Software...  #annoyedPluginDeveloperwhocantfindthingsheneeds

Like Damian Jesionek likes this
Thomas Clemens April 30, 2020

My latest fail:

AuthenticatedUserImpersonator

fired my problem:

SpacesQuery query = SpacesQuery.newQuery().forUser(null).withSpaceType(SpaceType.GLOBAL).withPermission(SpacePermission.VIEWSPACE_PERMISSION).build();
ListBuilder<Space> bereichebuilder = spaceManager.getSpaces(query);

if (bereichebuilder.getAvailableSize() != 0) {
List<Space> bereiche = bereichebuilder.getRange(0, bereichebuilder.getAvailableSize());
for (Space aktspace : bereiche) {
if (aktspace.getKey().equals("FUNFACTORY")) {
List<SpacePermission> spaceperms = new ArrayList<SpacePermission>();
SpacePermission myperm;
myperm = SpacePermission.createAnonymousSpacePermission(SpacePermission.REMOVE_OWN_CONTENT_PERMISSION, aktspace);
spaceperms.add(myperm);
ConfluenceUser aktuser = userAccessor.getUserByName("myadminaccountname");

 AuthenticatedUserImpersonator.REQUEST_AGNOSTIC.asUser(() ->{
aktspace.setPermissions(spaceperms);
    return null;
}, aktuser);

} //if
} // for
} //if

Not Working.. even trying to add a permission @ the moment.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events