This server will be upgraded at 3pm Sydney time on December 3rd (December 2nd, 8pm PST) and will be down for up to 30 minutes.

Permission Checker RPC Plugin

Name Permission Checker RPC Plugin
Vendor Atlassian Software Systems (Website)
Authors Richard Wallace
Homepage http://confluence.atlassian.com/display/CONFEXT/Permission+Checker+RPC+Plugin
Issue Management http://developer.atlassian.com/jira/browse/CSI
Continuous Integration n/a
Categories Remote Access
Most Recent Version 1.2-SNAPSHOT
Availability Confluence v2.7 to v2.10
State Prerelease
Support Unsupported Plugins
License Freeware / Open Source (BSD)
Price Free
Release Docs http://confluence.atlassian.com/display/CONFEXT/Permission+Checker+RPC+Plugin
Java API Docs n/a
Download Source https://svn.atlassian.com/svn/public/contrib/confluence/permcheckrpc-plugin
Download JAR confluence-permcheck-rpc-1.2-SNAPSHOT.jar
jira project

The Permission Checker RPC Plugin was originally developed for use with the Sharepoint Plugin. So, the Sharepoint Plugin's jira project is the place to submit jira issues. Please choose the component Permission Checker Plugin.

For Confluence versions 2.7 and earlier v1.0 of this plugin is the version needed - confluence-permcheck-rpc-1.0-SNAPSHOT.jar

More details below.

Table of Contents

Description/Features

The Permission Checker RPC Plugin provides permissions handling functionality as a SOAP service.

Installation

Confluence 2.7 and later

Either

  • Install it via the Atlassian Plugin Repository.
    or
  • For Confluence 2.7 or earlier download the jar and upload/install it via the Plugins Console
  • For Confluence 2.8 and later download the jar and upload/install it via the Plugins Console

For Confluence 2.6 and earlier you cannot install the jar dynamically from the admin page - read on

  1. Shutdown Confluence
  2. Drop the jar in WEB-INF/lib
  3. Restart Confluence

See also

Installing plugins overview

Usage

  1. Install the plugin
  2. Generate the soap stubs
  3. Use the soap stubs to interact with the plugin. See the API

Generate the soap stubs

The easiest way to generate the soap stubs is to use the Axis jars bundled with your Confluence to auto-generate the stubs. Axis comes with a WSDL2Java class which, when provided the URL to the relevant wsdl, will generate the Java stubs you will use to communicate with the plugin.

Ant

Attached to this page is a sample ANT build.xml which should help you generate and use the class.
Below is the contents of that build file. You'll need to set three properties in the file:

  1. conf-jars - your local confluence WEB-INF/lib directory so that the build file has access to all the Axis jars and such in order to work.
  2. gen-source-java-dir - this is your output directory. You can choose not to change this, and it will create a direcory called soap-generated-source in the same directory as the build.xml file.
  3. perm-wsdl - the URL to the permission checker plugin wsdl. It will look something like: http://your.confluence/rpc/soap/permcheck.wsdl

There's only one target (generate-axis-client-code), so just cd to the directory with the build file, and run it with ant.

$shell$ ant

Build File

<?xml version="1.0"?>
<!-- Build file to generate Permission Checker RPC Plugin soap stubs -->
<project name="hello-permsoap" default="generate-axis-client-code" basedir=".">

	<!-- Set these three properties. 
	     conf-jars: set this property to any local confluence WEB-INF/lib directory 
	     gen-source-java-dir: set this prop to the directory you wish the soap stub classes to be generated into.
	          If you do not change this setting they will be sent to './soap-generated-source' 
 	          If the directory does not exist it will be created.
	     perm-wsdl: Set this to your confluence's installed permcheck.wsdl
	-->
	<property name="confjars" value="/Users/laura/Code/Confluence/confluence-std-2.6.2/confluence/WEB-INF/lib/"/>
	<property name="gen-source-java-dir" value="soap-generated-source"/>
	<property name="perm-wsdl" value="http://localhost:8082/rpc/soap/permcheck.wsdl"/>

	<!-- Properties you don't need to set. -->
	<property name="conf-wsdl" value="http://localhost:8082/rpc/soap-axis/confluenceservice-v1?wsdl" /> <!-- example. not used -->
	<property name="perm-package" value="com.atlassian.confluence.plugins.rpc.permcheck"/>
	<property name="conf-package" value="com.atlassian.confluence.rpc"/> <!-- example, not used -->
	<property name="wsdl" value="${perm-wsdl}"/>
	<property name="package" value="${perm-package}"/>
	

	<target name="generate-axis-client-code">
         <mkdir dir="${gen-source-java-dir}"/>
         <java classname="org.apache.axis.wsdl.WSDL2Java" fork="true">
         	   <arg line="${wsdl} -p ${package} --output ${gen-source-java-dir}"/>
         		<classpath>
         			<fileset dir="${confjars}">
         				<include name="**/*.jar"/>
         			</fileset>
         		</classpath>
         </java>
	</target>
</project>

API

login

String login(String username, String password)

description - logs in a user to Confluence. The returned String is the required login token needed as a parameter for all other methods in this plugin. You must call login before calling any other methods.
parameters

  • username - username for the desired login
  • password - password for the given username

return value - String - the logintoken representing the successful login of the given username
throws

  • AuthenticationFailerException - if the username or password is incorrect
  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

see also - Remote API Specification
example - getLoginToken example

logout

boolean logout(String logintoken)

description - logs out the user associated with the given logintoken
parameters

  • logintoken - token returned from valid login. See login.

return value - true if user had been logged in, and now is logged out.
throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

see also - Remote API Specification

hasViewPermission

boolean hasViewPermission(String token, String url, String username)

description - detects if the given username has view permissions for the given url
parameters

  • String token - token returned from valid login. See login.
  • String url - url representing the page. Example: http://localhost:8082/display/Serenity/Testpage
  • String username - username we are testing has view permissions for the given url. Does not have to be the same user as the one associated with the login token.

return value - true if the given username has view permissions for the given url
throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

example - hasViewPermission example

hasViewPermissions

boolean[] hasViewPermissions(String token, String[] url, String username)

description - detects the given username's access to each of the urls in the given url array. Behaves as hasViewPermission for each irem in the url array.
parameters

  • String token - token returned from valid login. See login.
  • String[] url - String array of urls to Confluence pages. Each url should look something like: http://localhost:8082/display/Serenity/Testpage
  • String username - username we are testing has view permissions. Does not have to be the same user as the one associated with the login token.

return value - array of boolean values. array corresponds to url array. Example: If the url array contained the following pages:

throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

example - hasViewPermissions example

hasEditPermission

boolean hasEditPermission(String token, String url, String username)

description - detects if the given username has edit permissions for the given page url
parameters

  • String token - token returned from valid login. See login.
  • String url - url representing the page. Example: http://localhost:8082/display/Serenity/Testpage
  • String username - username we are testing has edit permissions for the given page identifier. Does not have to be the same user as the one associated with the login token.

return value - true if the given username has edit permissions for the given url
throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

example - hasEditPermission example

hasEditPermissionById

boolean hasEditPermissionById(String token, long id, String username)

description - detects if the given username has edit permissions for the given page id
parameters

  • String token - token returned from valid login. See login.
  • String id - page id for the desired page
  • String username - username we are testing has edit permissions for the given page identifier. Does not have to be the same user as the one associated with the login token.

return value - true if the given username has edit permissions for the given page
throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

example - hasEditPermissionById example

hasEditPermissions

boolean[] hasEditPermissions(String token, String[] url, String username)

description - detects the given username's edit permissions to each of the urls in the given url array. Behaves as hasEditPermission for each irem in the url array.
parameters

  • String token - token returned from valid login. See login.
  • String[] url - String array of urls to Confluence pages. Each url should look something like: http://localhost:8082/display/Serenity/Testpage
  • String username - username we are testing has edit permissions. Does not have to be the same user as the one associated with the login token.

return value - array of boolean values. array corresponds to url array. Example: If the url array contained the following pages:

throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

example - hasEditPermissions example

getSpacesForUser

RemoteSpaceSummary[] getSpacesForUser(String token, String username)

description - returns a list of spaces the given user has access to. Does not include Personal Spaces.
parameters

  • String token - token returned from valid login. See login.
  • String username - username whose list of spaces we are trying to get. Does not have to be the same user as the one associated with the login token.

return value - list of RemoteSpaceSummary objects representing the (non Personal) spaces the given username has access to.
throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

example - getSpacesForUser example

RemoteSpaceSummary

This is represents data about a space. It provides the following public methods to describe the space:

public String getUrl();
public String getKey();
public String getName();
public String getType();

getPagesForUser

RemotePageSummary[] getPagesForUser(String token, String spaceKey, String username)

description - returns a list of pages the given user has access to.
parameters

  • String token - token returned from valid login. See login.
  • String username - username whose list of spaces we are trying to get. Does not have to be the same user as the one associated with the login token.

return value - list of RemotePageSummary objects representing the pages the user has access to.
throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

example - getPagesForUser example

RemotePageSummary

This object represents a Confluence page, and provides some data about it.
The following getters can be accessed:

String getTitle();
long getId();
String getSpace();
long getParentId();
String getUrl();
int getPermissions(); 

getPageForUser

RemotePage getPageForUser(String token, String spaceKey, String pageTitle, String username)

description - gets the given page for the given user. If the user does not have access to the page, or the page does not exist, an exception is triggered.
parameters

  • String token - token returned from valid login. See login.
  • String spaceKey - spacekey for the space that the page resides in
  • String pageTitle - title of the page
  • String username - username we are trying to get the page for. Does not have to be the same user as the one associated with the login token.

return value - a RemotePage object representing the desired page.
throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException - if the user does not have access to the page, or the page does not exist

example - getPageForUser example

RemotePage

This object represents a Confluence page but has more data that the RemotePageSummary object.
Here are the public getters:

String getTitle()
long getId()
String getSpace()
long getParentId()
String getUrl()
int getPermissions()
String getContentStatus()
String getCreator()
String getModifier()
int getVersion()
Calendar getCreated()
Calendar getModified()
String getContent()

getPageByIdForUser

RemotePage getPageByIdForUser(String token, long pageId, String username)

description - gets the given page for the given user. If the user does not have access to the page, or the page does not exist, an exception is triggered.
parameters

  • String token - token returned from valid login. See login.
  • long pageId - id of the given page
  • String username - username we are trying to get the page for. Does not have to be the same user as the one associated with the login token.

return value - a RemotePage object representing the desired page.
throws

  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException - if the user does not have access to the page, or the page does not exist

example - getPageByIdForUser example

renderContentAsUser

String renderContentAsUser(String token, String spaceKey, long pageId, String newContent, String username)
String renderContentAsUser(String token, String spaceKey, long pageId, String newContent, Map renderParameters, String username)

Bug

renderContentAsUser(String, String, long, String, Map, String) is being auto-generated by Axis with the wrong Map type. Use the other renderContentAsUser.

description - gets the html content of the given page for the given user. This method works like the Confluence Remote Api's renderContent method.
parameters

  • String token - token returned from valid login. See login.
  • String spaceKey - spacekey of the desired page's space
  • long pageId - page id of the desired page
  • String newContent - if the empty string ("") gets the current content of the given page. if not empty, renders the page as if the newContent was the current content, but DOES NOT update the page. This is useful for mimicing the preview feature.
  • Map renderParameters (optional) - Not currently supported
  • String username - username we are trying to get the page for. Does not have to be the same user as the one associated with the login token.

return value - an html page, including css for the page's content. It does not include the Confluence headers or navigation or anything like that. Just the page contents, as an html page, with the css.

throws

  • InvalidSessionException
  • com.atlassian.confluence.plugins.rpc.permcheck.RemoteException
  • java.rmi.RemoteException

example - renderContentAsUser example
see also - [Confluence Remote API]

Examples

Plugins that use this plugin.

You can see the Permission Checker RPC Plugin being used by the Sharepoint Plugin.

examples assume WSDL2Java generated soap stubs

Each of the following examples will assume that the soap stubs were generated using the appropriate Confluence Permission Checker RPC plugin wsdl that you want to be using, and that you've (a)added those stubs to your classpath, and (b) imported the relevant classes into the particular java file you're working on.

log4j

Some of these examples use a log4j logging object. To use log4j:

  1. add the log4j jar (can be found in the Confluence WEB-INF/lib directory) to your classpath
  2. get a log instance
    Logger log = Logger.getLogger(this.getClass());
  3. setup log4j somewhere in the class using a configurator. Either:
    • PropertyConfigurator.configure("log4j.properties");
    • BasicConfigurator.configure();
    • This is not necessary if using Confluence code (plugin framework, etc.), as log4j is already configured for you.
  4. use the logger in your code:
    log.debug("tada");

For more info on log4j, see the log4j manual.

getPermissionCheckerSoapService example

or How to get the soap service object

        /**
	 * @return soap service for the Confluence Remote API
	 * Note: You'll need to the auto-generate the soap service stubs, using axis's WSDL2Java
	 */
	private PermissionChecker_PortType getPermissionCheckerSoapService() {
		
		//get the soap service, using the WSDL2Java auto-generated classes
		PermissionChecker_PortType stub = null;   
		try {
			//need to use the WSDL2java auto-generated locator to get the service
			PermissionChecker_ServiceLocator locator = new PermissionChecker_ServiceLocator();
			//now we actually can get the service!
			stub = locator.getPermissionChecker();
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		return stub;
	}

getLoginToken example

        /**
	 * gets the login token from Confluence's Remote API via Soap
	 * You'll need to generate the stubs with axis's WSDL2Java.
	 * @param username
	 * @param password 
	 * @return login token
	 */
	private String getLoginToken(String username, String password) {
                //get the soap object
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
                String loginToken = null;
		try {
			//make the soap call
			loginToken = service.login(username, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return loginToken;
	}


hasViewPermission example

        private static final String TESTSPACE = "Serenity"; 		//your test spacekey
	private static final String TESTPAGE = "Testpage";		//your test page that the user has complete access to
	private static final String TEST_NOEDIT = "Testpage No Edit";	//your test page that the user can see but not edit
	private static final String TEST_NOVIEW = "Testpage No View";	//your test page that the user has no access to
	private static final String TEST_NOPAGE = "Testpage No Page";	//page that doesn't exist
	
        Logger log = Logger.getLogger(this.getClass());

	private void testHasViewPermission(String loginToken, String url, String username) {
		
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
		try {
			//page user has all access to
			String page = TESTPAGE;
			String spacekey = TESTSPACE;
			String pageurl = createConfluencePageUrl(url, spacekey, page);  
			boolean has = service.hasViewPermission(loginToken, pageurl, username);
			log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " view access to '" + page + "'");

			//page user can view but not edit
			page = TEST_NOEDIT;
			pageurl = createConfluencePageUrl(url, spacekey, page); 
			has = service.hasViewPermission(loginToken, pageurl, username);
			log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " view access to '" + page + "'");
						
			//page user can't view or edit
			page = TEST_NOVIEW;
			pageurl = createConfluencePageUrl(url, spacekey, page); 
			has = service.hasViewPermission(loginToken, pageurl, username);
			log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " view access to '" + page + "'");
			
			//case doesn't appear to matter
			page = TESTPAGE.toUpperCase();
			pageurl = createConfluencePageUrl(url, spacekey, page); 
			has = service.hasViewPermission(loginToken, pageurl, username);
			log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " view access to '" + page + "'");
			
			//page that doesn't exist is handled as if the user doesn't have access to the page
			page = TEST_NOPAGE;
			pageurl = createConfluencePageUrl(url, spacekey, page); 
			has = service.hasViewPermission(loginToken, pageurl, username);
			log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " view access to '" + page + "'");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	/**
	 * @param url confluence location. example: localhost:8082
	 * @param spacekey confluence space where page resides. 
	 * @param page confluence page. example: Testpage Test 
	 * @return url to confluence page. example: http://localhost:8082/display/spacekey/Testpage+Test
	 */
	private String createConfluencePageUrl(String url, String spacekey, String page) {
		return "http://" + url + "/display/" + spacekey + "/" + 
			page.replaceAll(" ", "+");
	}

hasViewPermissions example

	private static final String TESTSPACE = "Serenity"; 		//your test spacekey
	private static final String TESTPAGE = "Testpage";		//your test page that the user has complete access to
	private static final String TEST_NOEDIT = "Testpage No Edit";	//your test page that the user can see but not edit
	private static final String TEST_NOVIEW = "Testpage No View";	//your test page that the user has no access to

	private void testHasMultPermissions(String loginToken, String url, String username) {
		
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
		String[] urls = {
				createConfluencePageUrl(url, TESTSPACE, TESTPAGE),    //see hasViewPermission example above
				createConfluencePageUrl(url, TESTSPACE, TEST_NOEDIT),
				createConfluencePageUrl(url, TESTSPACE, TEST_NOVIEW),
		};
		try {
			boolean[] viewBooleans = service.hasViewPermissions(loginToken, urls, username);
			for (int i = 0; i < viewBooleans.length; i++) {
				boolean has = viewBooleans[i];
				String page = urls[i];
				log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " view privileges to '" + page+ "'");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

hasEditPermission example

	private static final String TESTSPACE = "Serenity"; 			//your test spacekey
	private static final String TESTPAGE = "Testpage";				//your test page that the user has complete access to

	private void testHasEditPermission(String loginToken, String url, String username) {
		
		PermissionChecker_PortType service = getPermissionCheckerSoapService(); //see getPermissionCheckerSoapService example
		try {
			String page = TESTPAGE;
			String pageurl = createConfluencePageUrl(url, TESTSPACE, page); //see hasViewPermission example
			boolean has = service.hasEditPermission(loginToken, pageurl, username);
			log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " edit privileges to '" + page+ "'");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

hasEditPermissionById example

        private static final int TESTPAGEID = 47611925;					//your test page's page id
	private static final int PAGEID_NOEDIT = 47611927;				//no edit's page's id

	private void testHasEditPermissionById(String loginToken, String url, String username) {	
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
		try {
			//testing id method
			long id = TESTPAGEID;
			boolean has = service.hasEditPermissionById(loginToken, id, username); //same as TestPage, so should be true.
			log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " edit privileges to page with id '" + id + "'");

			id = PAGEID_NOEDIT;
			has = service.hasEditPermissionById(loginToken, id, username); //same as TestPage, so should be true.
			log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " edit privileges to page with id '" + id + "'");


		} catch (Exception e) {
			e.printStackTrace();
		}
	}

hasEditPermissions example

	private static final String TESTSPACE = "Serenity"; 		//your test spacekey
	private static final String TESTPAGE = "Testpage";		//your test page that the user has complete access to
	private static final String TEST_NOEDIT = "Testpage No Edit";	//your test page that the user can see but not edit
	private static final String TEST_NOVIEW = "Testpage No View";	//your test page that the user has no access to

	private void testHasMultPermissions(String loginToken, String url, String username) {
		
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
		String[] urls = {
				createConfluencePageUrl(url, TESTSPACE, TESTPAGE),    //see hasViewPermission example above
				createConfluencePageUrl(url, TESTSPACE, TEST_NOEDIT),
				createConfluencePageUrl(url, TESTSPACE, TEST_NOVIEW),
		};
		try {
			boolean[] editBooleans = service.hasEditPermissions(loginToken, urls, username);
			for (int i = 0; i < editBooleans.length; i++) {
				boolean has = editBooleans[i];
				String page = urls[i];
				log.debug("Username '" + username + "' " + (has?"HAS":"does NOT have") + " edit privileges to '" + page+ "'");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

getSpacesForUser example

	private void testGetSpacesForUser(String loginToken, String username) {
		//method sig: RemoteSpaceSummary[] getSpacesForUser(String token, String username) throws RemoteException;
		
		//NOTE: doesn't appear to handle Personal Spaces
		PermissionChecker_PortType service = getPermissionCheckerSoapService(); //see getPermissionCheckerSoapService example 
		com.atlassian.confluence.plugins.rpc.permcheck.RemoteSpaceSummary[] spacesForUser = null;
		try {
			spacesForUser = service.getSpacesForUser(loginToken, username);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		if (spacesForUser != null) {
			log.debug("User '" + username +"' has access to these spaces: ");
			for (com.atlassian.confluence.plugins.rpc.permcheck.RemoteSpaceSummary summary : spacesForUser) {
				log.debug("   * " + summary.getName() + " (" + summary.getKey() + ")");
			}
		}
		
	}

getPagesForUser example

	private static final String TESTSPACE = "Serenity"; 			//your test spacekey
	private void testGetPagesForUser(String loginToken, String username) {

		String spacekey = TESTSPACE;
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
		com.atlassian.confluence.plugins.rpc.permcheck.RemotePageSummary[] pagesForUser = null;
		try {
			pagesForUser = service.getPagesForUser(loginToken, spacekey, username);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (pagesForUser == null) 
			log.error("Problem: no pages from getPagesForUser.");
		else {
			log.debug("User '" + username +"' has access to these pages: ");
			int i = 0; 
			int max = 5; //only show the first N pages
			for (com.atlassian.confluence.plugins.rpc.permcheck.RemotePageSummary summary : pagesForUser) {
				if (i++ >= max) break;
				log.debug("\n" +
						  "   title = " + summary.getTitle() + "\n" +
						  "   id = " + summary.getId() +"\n" +
						  "   space = " + summary.getSpace() + "\n" +
						  "   parentId = " + summary.getParentId() + "\n" +
						  "   url = " + summary.getUrl() + "\n" +
						  "   permissions = " + summary.getPermissions() + "\n");
						  
			}
		}
	}

getPageForUser example

	private static final String TESTSPACE = "Serenity"; 			//your test spacekey
	private static final String TESTPAGE = "Testpage";		//your test page that the user has complete access to
	private static final String TEST_NOVIEW = "Testpage No View";	//your test page that the user has no access to
	private static final String TEST_NOPAGE = "Testpage No Page";	//page that doesn't exist

	private void testGetPageForUser(String loginToken, String username) {
		String spacekey = TESTSPACE;
		String pagename = TESTPAGE;
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
		
		//using pagename and spacekey
		com.atlassian.confluence.plugins.rpc.permcheck.RemotePage pageForUser = null;
		try {
			pageForUser = service.getPageForUser(loginToken, spacekey, pagename, username);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (pageForUser == null) log.error("Page was null");
		else {
			log.debug("\n" +
					  "   title = " + pageForUser.getTitle() + "\n" +
					  "   id = " + pageForUser.getId() +"\n" +
					  "   space = " + pageForUser.getSpace() + "\n" +
					  "   parentId = " + pageForUser.getParentId() + "\n" +
					  "   url = " + pageForUser.getUrl() + "\n" +
					  "   permissions = " + pageForUser.getPermissions() + "\n" +
					  "   content status = " + pageForUser.getContentStatus() + "\n" +
					  "   creator = " + pageForUser.getCreator() + "\n" +
					  "   last modifier = " + pageForUser.getModifier() + "\n" +
					  "   version = " + pageForUser.getVersion() + "\n" +
					  "   created date = " + pageForUser.getCreated() + "\n" +
					  "   last modified date = " + pageForUser.getModified() + "\n" +
					  "   content = \n" + pageForUser.getContent() + "\n");
		}
		
		//if user does not have access
		pagename = TEST_NOVIEW;
		pageForUser = null;
		try {
			pageForUser = service.getPageForUser(loginToken, spacekey, pagename, username);
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (java.rmi.RemoteException e) {
			log.debug("User '" + username +"' does not have view access for page '"+pagename+"'. An exception was triggered successfully.");
		}
		
		//what happens if the page does not exist
		pagename = TEST_NOPAGE;
		pageForUser = null;
		try {
			pageForUser = service.getPageForUser(loginToken, spacekey, pagename, username);
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (java.rmi.RemoteException e) {
			log.debug("Page '"+pagename+"' does not exist. An exception was triggered successfully.");
		}
	}

getPageByIdForUser example

	private static final int TESTPAGEID = 47611925;					//your test page's page id
	private void testGetPageForUser(String loginToken, String username) {
		long pageid = TESTPAGEID;
		com.atlassian.confluence.plugins.rpc.permcheck.RemotePage pageForUser = null;
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
		try {
			pageForUser = service.getPageByIdForUser(loginToken, pageid, username);
		} catch (Exception e) {
			log.error("Problem getting page. " + pageid);
		}
		if (pageForUser == null) log.error("Page was null");
		else {
			log.debug("\n" +
					  "   title = " + pageForUser.getTitle() + "\n" +
					  "   id = " + pageForUser.getId() +"\n" +
					  "   space = " + pageForUser.getSpace() + "\n" +
					  "   parentId = " + pageForUser.getParentId() + "\n" +
					  "   url = " + pageForUser.getUrl() + "\n" +
					  "   permissions = " + pageForUser.getPermissions() + "\n" +
					  "   content status = " + pageForUser.getContentStatus() + "\n" +
					  "   creator = " + pageForUser.getCreator() + "\n" +
					  "   last modifier = " + pageForUser.getModifier() + "\n" +
					  "   version = " + pageForUser.getVersion() + "\n" +
					  "   created date = " + pageForUser.getCreated() + "\n" +
					  "   last modified date = " + pageForUser.getModified() + "\n" +
					  "   content = \n" + pageForUser.getContent() + "\n");
		}
	}

renderContentAsUser example

	private static final String TESTSPACE = "Serenity"; 			//your test spacekey
	private static final int TESTPAGEID = 47611925;				//your test page's page id
	private static final int PAGEID_NOVIEW = 47611926;			//no view's page's id
	private void testRenderContentAsUser(String loginToken, String username) {
		String spacekey = TESTSPACE;
		long pageid = TESTPAGEID;
		String newContent = ""; //if newContent == "", then the existing content is rendered. if "new" (read preview) content is provided, then it's rendered as if there was new content, BUT the page isn't edited.
		PermissionChecker_PortType service = getPermissionCheckerSoapService();//see getPermissionCheckerSoapService example
		
		//testing rendering a simple page user has access to, no params.
		try {
			String rendered = service.renderContentAsUser(loginToken, spacekey, pageid, newContent, username);
			if (rendered == null) log.error("Rendered page was null.");
			else log.debug("\n" + rendered);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		//testing rendering a page the user does not have access to. Should throw exception
		pageid = PAGEID_NOVIEW;
		try {
			String rendered = service.renderContentAsUser(loginToken, spacekey, pageid, newContent, username);
			log.error("An exception should have been thrown.");
		} catch (Exception e) {
			log.debug("As user does not have access to that page id, a RemoteException was thrown. Test succeeded.");
		}
	}

Version History

Version Date State License Price
Show description 1.2-SNAPSHOT (#2) 18 Sep 2008 Prerelease Freeware / Open Source (BSD) Free

Release Notes

Release updated to work with Confluence 2.8+

Contributors

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.