Skip to content

Instantly share code, notes, and snippets.

Created November 25, 2014 04:53
What would you like to do?
Showing how to grab a document, either by ID or by path, from an Alfresco 5.0.a repository, even when the user does not have access to the enclosing folders


  1. Create a folder called "test1" in Company Home.
  2. Modify its permissions to turn off inheritance.
  3. Create a sub-folder called "test2" under "test1".
  4. Modify its permissions to turn off inheritance.
  5. Create a plain text file in test2 called test.txt.
  6. Modify its permissions to turn off inheritance and add a single user with Consumer access (tuser1).
  7. You can still get to the document via CMIS, which is the expected behavior.

This Java class inherits from BaseOnPremExample which can be found here:

package com.alfresco.api.example;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Session;
public class GetDocumentExample extends BaseOnPremExample {
public static void main(String[] args) {
GetDocumentExample gde = new GetDocumentExample();
public void doExample() {
Session cmisSession = getCmisSession();
System.out.println("Version: " + cmisSession.getRepositoryInfo().getProductVersion());
System.out.println("User: " + getUsername());
// This works
//Document doc = (Document) cmisSession.getObject("workspace://SpacesStore/fd05d750-1083-4e46-9507-566bc7b7712f");
// This works as well
Document doc = (Document) cmisSession.getObjectByPath("/test1/test2/test.txt");
System.out.println("Name: " + doc.getPropertyValue("cmis:name"));
try {
BufferedReader in = new BufferedReader(new InputStreamReader(doc.getContentStream().getStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
} catch (IOException ioe) {
Found 1 networks.
Your home network appears to be: -default-
Version: 5.0.0 (r75118-b23)
User: tuser1
Name: test.txt
This is some test content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment