The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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 } }
Community moderators have prevented the ability to post new answers.
maybe that helps:
Space space = spaceManager.getSpace("somespace"); SpacePermission spacePermission = SpacePermission.createUserSpacePermission(SpacePermission.VIEWSPACE_PERMISSION, space, "username"); spacePermissionManager.removePermission(spacePermission);
Cheers,
Lars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[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);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 */
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
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...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.