How to use the PermissionManager in a Confluence Plugin Rest Module

I tried to use the (autowired) PermissionManager in a Confluence Rest Module as follows:

ConfluenceUser confluenceUser = AuthenticatedUserThreadLocal.get();
if(!permissionManager.isConfluenceAdministrator(confluenceUser)) {

 If the user is not logged-in the exception is thrown and everything is fine but if the user is logged-in and has admin permissions I get a NullPointerException in the isConfluenceAdministrator method. The user object seems to be fine (and not NULL). The code is within a POST Method. I send the request from a custom settings page (location: system.admin).

2 answers

1 accepted

1 vote
Answer accepted

This is how I build rest resources in plugins, the following shows how to include the PermissionManager


import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.confluence.user.ConfluenceUser;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;


import static java.util.Collections.singletonMap;

public class SampleResource {

private final PermissionManager permissionManager;

public SampleResource(final @ComponentImport PermissionManager permissionManager) {
this.permissionManager = permissionManager;

public Response get() {
final ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get();
if (!permissionManager.isConfluenceAdministrator(currentUser)) {
return Response.status(Response.Status.FORBIDDEN).build();
return Response.ok(singletonMap("username", currentUser.getName())).build();

and has the following package imports on the pom file definition


Hope this helps

great! this works, thanks a lot. But i still need the following entry in the META-INF/spring/plugin-context.xml file:

<osgi:reference id="permissionManager" interface=""/>

 Same for you?

Ah right; indeed !

However I am using atlassian spring scanner, so my plugin-context.xml looks a bit different.

You can find the whole plugin setup here

0 votes
Steven Behnke Community Champion Jan 06, 2018

This would likely be better asked at 

I'm not sure why that method would throw an NPE because the javadoc doesn't state that it throws an NPE under desirable circumstances. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,422 views 3 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you