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

Get Space Permissions in XMLRPC Plugin (Hibernate Problems)

Martin Steinorth September 20, 2012

Hi there,

according to this ticket (https://jira.atlassian.com/browse/CONF-14162) i need to implement a XMLRPC plugin to retrieve all permissions for a given space and distribute it via the API.

Simple as it is i thought of something like

Space space = spaceManager.getSpace(spaceKey);
List<SpacePermission> permissions = space.getPermissions();

But in fact all i got was a LazyInitializationException thrown by Hibernate. It seems that the Object isn't bound to a session anymore, so i can't access the permissions. There is a topic on that which advises to wrap the whole block in a transaction (https://developer.atlassian.com/display/CONFDEV/Hibernate+Sessions+and+Transaction+Management+Guidelines) If i do that i get a exception telling me, that there is no Session.

Searching through the API i found the class com.atlassian.confluence.security.persistence.dao.hibernate.HibernateSpacePermissionDao which also offer a findPermissionsForSpace(Space space) method. Unfortunately it is returning null.

Does anybody know how to deal with this case? I just need all permissions of a space inside a XMLRPC Plugin.

Thanks!

Martin

1 answer

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
Martin Steinorth September 27, 2012

Got it working by sticking to this Code Example:

https://developer.atlassian.com/display/CONFDEV/RPC+Module

package com.atlassian.confluence.extra.helloworldrpcv2;
 
import com.atlassian.confluence.spaces.SpaceManager;
import com.atlassian.sal.api.transaction.TransactionCallback;
import com.atlassian.sal.api.transaction.TransactionTemplate;
 
public class DefaultHelloWorld implements HelloWorld
{
    private final TransactionTemplate transactionTemplate;
    private final SpaceManager spaceManager;
 
    public DefaultHelloWorld(final SpaceManager spaceManager, final TransactionTemplate transactionTemplate)
    {
        this.spaceManager = spaceManager;
        this.transactionTemplate = transactionTemplate;
    }
 
    public String sayHello()
    {
        return (String) transactionTemplate.execute(new TransactionCallback()
        {
            public Object doInTransaction()
            {
                return String.format("Hello world! Number of spaces: %d", spaceManager.getAllSpaces().size());
            }
        });
    }
}

Though, the examples on https://developer.atlassian.com/display/CONFDEV/Hibernate+Sessions+and+Transaction+Management+Guidelines are not working for me, due to some wicked dependencies and package problems.

Trupti Kanase May 21, 2015

@Martin Steinorth : Thanks a lot...Worked for me.!!!

TAGS
AUG Leaders

Atlassian Community Events