WebSphere Portal: AuthorizationException Is Thrown While Calling Workspace getById Method

Below looks like an innocent block of codes written to retrieve WCM items:

 Content content = null;
 Workspace ws=WCM_API.getRepository().getWorkspace();
 DocumentIdIterator iter = ws.findByPath(path, Workspace.WORKFLOWSTATUS_ALL);

 if(iter.hasNext()) {
  DocumentId docId = iter.nextId();
  if (docId.isOfType(DocumentTypes.Content)) {
   content = (Content)ws.getById(docId,true,true);
  }
 }

But as soon as you try to retrieve WCM items with “User” access, the following “AuthorizationException” will be thrown (even though you are able to view the items in WCM Authoring Portlet):

  • com.aptrix.pluto.security.AuthorizationException
  • com.ibm.workplace.wcm.api.exceptions.AuthorizationException

This is because getById method by default required min “Contributor” rights. In order to resolve the issue, call Workspace.useUserAccess(true) before you call the getById method.

Leave a Reply

Your email address will not be published. Required fields are marked *