Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,297,986
Community Members
 
Community Events
165
Community Groups

Remove a user's space permission via the API [Confluence]

Is there a way to remove a user's space permission via the Confluence API? I'd like my plugin to be able to "clean up" a user from a space. I've checked the PermissionManager and SpacePermissionManager but neither seems to do what I want.

Here's my initial code:

for(String perm : SpacePermission.GENERIC_SPACE_PERMISSIONS){
if(spacePermissionManager.hasPermission(perm, airSpace, user)){
//remove perm
}
}

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Deleted user Jun 10, 2012

maybe that helps:

Space space = spaceManager.getSpace("somespace");            
            SpacePermission spacePermission = SpacePermission.createUserSpacePermission(SpacePermission.VIEWSPACE_PERMISSION, space, "username");
            spacePermissionManager.removePermission(spacePermission);

Cheers,

Lars

That looks to be a good way to do this, thanks!

@[deleted] Could you help me understand how to use spaceManager? I'm trying to use as following but keep getting a null pointer exception error which is essentially saying that my space is null:


import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.atlassian.confluence.spaces.*;
import com.atlassian.confluence.security.*;
import com.atlassian.user.User;
import com.atlassian.user.UserManager;
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.confluence.user.ConfluenceUser;
import com.atlassian.confluence.user.UserAccessor;
// import com.atlassian.confluence.it.space.SpacePermissions;

import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "link")
@XmlAccessorType(XmlAccessType.FIELD)
public class SpacePermissionsModel {

private SpaceManager spaceManager;
private Space space;
private String spaceName;
private String spaceURL;
private String spaceDisplayName;
private List<User> spaceAdmins;

private boolean error;

public SpacePermissionsModel() {}

public SpacePermissionsModel(String spaceKey) {
super();
this.space = this.spaceManager.getSpace(spaceKey);
}


}

I'm pushing this since the API which was used in @Lars Kleen's example is deprecated in Versions 5.9 and up. Any ideas on how to circumvent using the deprecated 'removePermission()' ?

spacePermissionManager.removePermission(spacePermission);

I tried using the SpacePermissionManagerInternal in my plugin but cannot inject it successfully.

It seemed that the recommendation is to use com.atlassian.confluence.internal.security.SpacePermissionManagerInternal class

Deprecated. since 5.9. Use SpacePermissionManagerInternal.removePermission(SpacePermission, com.atlassian.confluence.internal.security.SpacePermissionContext) instead.

 

but according to the javadoc, the internal interfaces are not exposed the plugins

Internal version of the SpacePermissionManager; see package-info.java for rationale.

which states

/**
 * Internal interfaces that are NOT exposed to the plugin classpath, by being excluded in the packageScanningConfiguration
 * of bootstrapContext.xml.
 * <p>
 * This allows us to slowly reduce the surface area of confluence-core as an API, now that we are intentionally
 * exposing an official API in confluence-java-api.
 * <p>
 * When adding new internal interface methods that return multiple entities, they <em>must</em> accept a
 * {@link com.atlassian.confluence.api.model.pagination.LimitedRequest} as an argument.
 *
 * @since 5.5
 */
Like Miroslav Kralik likes this

Nope :(

I tried using the SpacePermissionManagerInternal in my plugin but cannot inject it successfully.

Can you help me, I need to add or remove permissions for the spaces?

 

Thanks

it is interesting as the SpacePermissionManagerInternal is not exposed, but the SpacePermissionManager is deprecated and suggest SpacePermissionManagerInternal.

 

I tried but cannot inject SpacePermissionManagerInternal too. I am using SpacePermissionManager and it works.

Like # people like this

Hi Lionel,

you can try this:

for(String perm : SpacePermission.GENERIC_SPACE_PERMISSIONS){
	if(spacePermissionManager.hasPermission(perm, airSpace, user)){
		spacePermissionManager.removeAllUserPermissions(user.getName());
	}
}

Which Confluence version are you using?

Take a look at:
https://developer.atlassian.com/display/CONFDEV/Confluence+Permissions+Architecture

Cheers
Martin

I was thinking about that, but removeAllUserPermissions doesn't take a space so I assume it whipes out ALL of a user's permissions? I just want to remove them from one space.

We're on Confluence 3.5.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

112 views 1 2
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