AnsweredAssumed Answered

Create content with OpenCMIS using a user added with POST /api/people

Question asked by juans on Aug 12, 2016
Latest reply on Aug 19, 2016 by jpotts
Hi

I successfully created the user unittestuser1 using this endpoint
Address: http://localhost:9090/alfresco/s/api/people
Http-Method: POST

I successfully created a folder /agencies/agency1 using OpenCMIS with admin user.

But when I tried to create the document test.txt in the folder /agencies/agency1 with OpenCMIS using the user unittestuser1 I get this error:


org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException: Unauthorized
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:466)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:635)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.createDocument(ObjectServiceImpl.java:120)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.createDocument(SessionImpl.java:1028)
   at org.apache.chemistry.opencmis.client.runtime.FolderImpl.createDocument(FolderImpl.java:75)
   at org.apache.chemistry.opencmis.client.runtime.FolderImpl.createDocument(FolderImpl.java:449)
   at test.documentlibrary.services.impl.DocumentLibraryImpl.createDocument(DocumentLibraryImpl.java:305)
   at test.documentlibrary.services.DocumentLibraryTest.createDocument_Success(DocumentLibraryTest.java:152)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
   at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:200)
   at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:175)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:212)
   at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
   at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
   at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
   at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
   at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
   at org.testng.TestRunner.privateRun(TestRunner.java:767)
   at org.testng.TestRunner.run(TestRunner.java:617)
   at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
   at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
   at org.testng.SuiteRunner.run(SuiteRunner.java:240)
   at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
   at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
   at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
   at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
   at org.testng.TestNG.run(TestNG.java:1057)
   at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:115)
   at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:207)
   at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:178)




I am creating the document like this:


      String filename = "test.txt";

      Session session = getUserSession(getLoggedUser());
      Folder rootAgency = (Folder) session.getObjectByPath("/agencies/agency1");

      // Create a Map of objects with the props we want to set
      Map <String, Object> properties = new HashMap<String, Object>();
      properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");      
      properties.put(PropertyIds.NAME, filename);
      
      // I am getting variables length, mimeType and inputStream as paramaters
      ContentStream contentStream = session.getObjectFactory().createContentStream(filename, length, mimeType, inputStream);

      Document doc = rootAgency.createDocument(
               properties,
               contentStream,
               VersioningState.MAJOR);





I thought it was because at user creation time I did not send any list of groups, so I deleted the user and created it again with the group Collaborator in the list of groups, something like this:

Address: http://localhost:9090/alfresco/s/api/people
Http-Method: POST
Content-Type: application/json
Payload:

{
"userName":"unittestuser1",
"firstName":"Test User Name",
"lastName":"Last Name for User Test",
"email":"testuser@company.com",
"password":"password",
"disableAccount":false,
"quota":-1,
"groups":["Collaborator"]
}


But, when I try to create the document I get the same error :(

And when I try to see the groups of the user, I see he has no groups related:

GET http://localhost:9090/alfresco/s/api/people/unittestuser1?groups=true

{
   "url": "\/alfresco\/s\/api\/people\/unittestuser1",
   "userName": "unittestuser1",
   "enabled": true,
   "firstName": "Test User Name",
   "lastName": "Last Name for User Test",
   "jobtitle": null,
   "organization": null,
   "organizationId": null,
   "location": null,
   "telephone": null,
   "mobile": null,
   "email": "testuser@company.com",
   "companyaddress1": null,
   "companyaddress2": null,
   "companyaddress3": null,
   "companypostcode": null,
   "companytelephone": null,
   "companyfax": null,
   "companyemail": null,
   "skype": null,
   "instantmsg": null,
   "userStatus": null,
   "userStatusTime": null,
   "googleusername": null,
   "quota": -1,
   "sizeCurrent": 0,
   "emailFeedDisabled": false,
   "persondescription": null,
   "authorizationStatus": null,
   "isDeleted": false,
   "isAdminAuthority": false
,
   "capabilities":
   {
      "isAdmin":
      false
            ,"isMutable":
      true
            ,"isGuest":
      false
         },
   "groups": [
],
   "immutability":
   {
   }
}




I want the user to be able to create new content, delete content, edit existing content in that folder. And that is the definition of the Collaborator group right ?
What am I missing ?

Outcomes