Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Restrict a page to user [JAVA] [Confluence]

Fabian Angst June 29, 2015

Hey guys,

I want to restrict a page via java to only a amount of users. How can I restrict a page with Java - couldnt find it with google..

Thank You!

 

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Lukas Knoch -Rumpelcoders-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2015

I usually do something like that:

/**
     * remove edit permissions from old page
     * @param page
     */
    public static void removeEditPermissions(AbstractPage page , ContentPermissionManager contentPermissionManager) {
        //remove old edit permissions
        List<ContentPermission> toDelete = new ArrayList<ContentPermission>();
        if (page.getContentPermissionSet(ContentPermission.EDIT_PERMISSION) != null) {
            for (ContentPermission cp : page.getContentPermissionSet(ContentPermission.EDIT_PERMISSION)) {
                toDelete.add(cp);
            }
            for (ContentPermission cp : toDelete) {
                contentPermissionManager.removeContentPermission(cp);
            }
        }
    }

This removes all edit permissions. I did not find any better way yet.

Fabian Angst June 30, 2015

Thank you for your fast and good answers! But I've to say I still get a nullpointer: [com.atlassian.hibernate.HibernateObjectDao] remove remove error! org.springframework.orm.hibernate.HibernateSystemException: not-null property references a null or transient value: com.atlassian.confluence.security.ContentPermission.owningSet; nested exception is net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.atlassian.confluence.security.ContentPermission.owningSet

Lukas Knoch -Rumpelcoders-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2015

That's strange. In which context are you executing this? I am doing this in a servlet and it works just fine. (confluence 5.7.4) But it might be that this is because i never leave the permissions completely empty? Not sure. Consider asking a new question for this issue.

Fabian Angst June 30, 2015

I'm using this with a normal class which is used in a Event Listener and a Action. I'm using 5.8.4 - and 5.8.4 does many strange stuff.. Thank you! I'll ask a new question! Best regards

2 votes
Lukas Knoch -Rumpelcoders-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2015

Hi, you can use the following code:

page.addPermission(ContentPermission.createUserPermission(ContentPermission.VIEW_PERMISSION, confluenceUser));

for a view permission for example.

Best regards,

Lukas

Fabian Angst June 29, 2015

thank you! But does this mean, that all other users cant view or should i remove all permissions to this page and add all user permissions of the users which should have the permission? Thanks, Best regards, Fabian

Lukas Knoch -Rumpelcoders-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2015

Those are basically the restrictions on the page. If no restriction is applied, every one who can see the space can see the page. (same with edit.) If view is restricted to a specific user, only the restricted user can view the page only if he has permission to view the space only if he is allowed to vie the parent page. Similar with edit, but you have to have permission to view the page in order to be able to edit it. https://confluence.atlassian.com/display/DOC/Page+Restrictions Best regards

Fabian Angst June 29, 2015

Ok! Thannk you very much! Best Regards!

0 votes
Fabian Angst June 30, 2015

Ok thanks, but if i want to remove the permission set ill get a nullpointer.. Can you tell me why @lukas.knoch

page.removeContentPermissionSet(page.getContentPermissionSet(ContentPermission.EDIT_PERMISSION));
            page.removeContentPermissionSet(page.getContentPermissionSet(ContentPermission.VIEW_PERMISSION));

Thanks!

TAGS
AUG Leaders

Atlassian Community Events