12-05-2012 02:59 AM
permissions.add("{http://www.alfresco.org/model/content/1.0}cmobject.Collaborator");
instead of permissions.add(BasicPermissions.WRITE);
And indeed the test completes without errors.public class CmisTests {
@Test
public void test() throws IOException {
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(SessionParameter.USER, "admin");
parameters.put(SessionParameter.PASSWORD, "admin");
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/cmisatom");
Session session = sessionFactory.getRepositories(parameters).get(0).createSession();
Document document = FileUtils.createTextDocument("/", "test.txt", "Some text", BaseTypeId.CMIS_DOCUMENT.value(), VersioningState.MAJOR, session);
String id = document.getId();
OperationContext operationContext = new OperationContextImpl();
operationContext.setIncludeAcls(true);
document = (Document) session.getObject(id, operationContext);
System.out.println("Acl:");
Acl acl = document.getAcl();
for (Ace ace : acl.getAces()) {
System.out.println(ace);
}
parameters.put(SessionParameter.USER, "user");
parameters.put(SessionParameter.PASSWORD, "user");
session = sessionFactory.getRepositories(parameters).get(0).createSession();
document = (Document) session.getObject(id);
String content = IOUtils.toString(document.getContentStream().getStream());
System.out.println("Content: " + content);
ObjectId checkedOutDocumentObjectId = null;
try {
checkedOutDocumentObjectId = document.checkOut();
} catch (CmisPermissionDeniedException e) {
System.out.println("No permission to check out");
}
parameters.put(SessionParameter.USER, "admin");
parameters.put(SessionParameter.PASSWORD, "admin");
session = sessionFactory.getRepositories(parameters).get(0).createSession();
document = (Document) session.getObject(id, operationContext);
String principal = "user";
List<String> permissions = new LinkedList<String>();
permissions.add(BasicPermissions.WRITE);
Ace addAce = session.getObjectFactory().createAce(principal, permissions);
List<Ace> addAces = new LinkedList<Ace>();
addAces.add(addAce);
document.addAcl(addAces, AclPropagation.REPOSITORYDETERMINED);
System.out.println("Acl:");
acl = document.getAcl();
for (Ace ace : acl.getAces()) {
System.out.println(ace);
}
parameters.put(SessionParameter.USER, "user");
parameters.put(SessionParameter.PASSWORD, "user");
session = sessionFactory.getRepositories(parameters).get(0).createSession();
document = (Document) session.getObject(id);
// CmisPermissionDeniedException: Forbidden below
checkedOutDocumentObjectId = document.checkOut();
Document checkedOutDocument = (Document) session.getObject(checkedOutDocumentObjectId);
String newContent = "New text.";
boolean major = false;
Map<String, String> properties = null;
String filename = document.getName();
BigInteger length = BigInteger.valueOf(newContent.length());
String mimeType = document.getContentStreamMimeType();
InputStream stream = IOUtils.toInputStream(newContent);
ContentStream updatedContentStream = new ContentStreamImpl(filename, length, mimeType, stream);
String checkinComment = "Text is updated";
checkedOutDocument.checkIn(major, properties, updatedContentStream, checkinComment);
document = document.getObjectOfLatestVersion(false);
content = IOUtils.toString(document.getContentStream().getStream());
System.out.println("Content: " + content);
}
@Test
public void t() {
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(SessionParameter.USER, "admin");
parameters.put(SessionParameter.PASSWORD, "admin");
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/cmisatom");
Session session = sessionFactory.getRepositories(parameters).get(0).createSession();
Document document = (Document) session.getObjectByPath("/test.txt");
OperationContext operationContext = new OperationContextImpl();
operationContext.setIncludeAcls(true);
document = (Document) session.getObject(document, operationContext);
Acl acl = document.getAcl();
for (Ace ace : acl.getAces()) {
System.out.println(ace);
}
}
@Before
public void init() {
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(SessionParameter.USER, "admin");
parameters.put(SessionParameter.PASSWORD, "admin");
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/cmisatom");
Session session = sessionFactory.getRepositories(parameters).get(0).createSession();
session.delete(session.getObjectByPath("/test.txt"));
}
}
12-08-2012 01:42 AM
<cmis:mapping>
<cmis:key>canCheckout.Document</cmis:key>
<cmis:permission>cmis:all</cmis:permission>
<cmis:permission>{http://www.alfresco.org/model/content/1.0}lockable.CheckOut</cmis:permission>
</cmis:mapping>
12-10-2012 03:38 AM
RepositoryInfo repositoryInfo = session.getRepositoryInfo();
AclCapabilities aclCapabilities = repositoryInfo.getAclCapabilities();
Map<String, PermissionMapping> permissionMappings = aclCapabilities.getPermissionMapping();
PermissionMapping permissionMapping = permissionMappings.get(PermissionMapping.CAN_CHECKOUT_DOCUMENT);
List<String> permissions = permissionMapping.getPermissions();
Ace addAce = session.getObjectFactory().createAce(principal, permissions);
List<Ace> addAces = new LinkedList<Ace>();
addAces.add(addAce);
document.addAcl(addAces, AclPropagation.REPOSITORYDETERMINED);
05-26-2015 02:39 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.