cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to basic alfresco repository using CMIS

Vishruti_Shah
Champ in-the-making
Champ in-the-making

Hi,

I need to connect to the basic alfresco repository using the CMIS API URL using Atompub or browser binding.

I tried connecting to the repository using the URLs provided in the alfresco documentation.

URLs : 

http://<hostname>:<port>/alfresco/api/-default-/public/cmis/versions/1.1/atom
http://<hostname>:<port>/alfresco/api/-default-/public/cmis/versions/1.1/browser

But I am facing an error related to http authentication

{
    "status" : 
  {
    "code" : 401,
    "name" : "Unauthorized",
    "description" : "The request requires HTTP authentication."
  },  
  
  "message" : "11210005 Authentication failed for Web Script org\/alfresco\/api\/opencmis\/OpenCMIS.get",  
  "exception" : "",
  
  "callstack" : 
  [ 
  	   
  ],
  
  "server" : "Enterprise v6.2.0 (ra498a911-b5) schema 13,001",
  "time" : "21 Dec 2020, 07:33:37"
}

 How can I solve this error, where do I need to auntheticate this?

3 REPLIES 3

sanjaybandhaniya
Elite Collaborator
Elite Collaborator

Try to call with basic authentication.

kaynezhang
World-Class Innovator
World-Class Innovator

Please paste your code here 

abhinavmishra14
World-Class Innovator
World-Class Innovator
{
    "status" : 
  {
    "code" : 401,
    "name" : "Unauthorized",
    "description" : "The request requires HTTP authentication."
  },  
  
  "message" : "11210005 Authentication failed for Web Script org\/alfresco\/api\/opencmis\/OpenCMIS.get",  
  "exception" : "",
  
  "callstack" : 
  [ 
  	   
  ],
  
  "server" : "Enterprise v6.2.0 (ra498a911-b5) schema 13,001",
  "time" : "21 Dec 2020, 07:33:37"
}

Your error indicates authentication failure, possible that you are using invalid credentials.

There is another good way to work with CMIS api, read this tutorial:

https://ecmarchitect.com/alfresco-developer-series-tutorials/content/tutorial/tutorial.html#cmis-1.0...

Example source code

https://github.com/jpotts/alfresco-developer-series/tree/master/content/content-tutorial-cmis/src/ma...

On the other hand, either of the URLs should work if you trying to access via some client. As indicated by the folks, you can use basic authentication or alf_ticket (get it using login api) to access the atompub url using any client/java code. Use the httppost request if using basic auth. It is not recommended to use basic auth with httpget in general.

POST http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom

Also refer this doc: https://docs.oasis-open.org/cmis/CMIS/v1.1/errata01/os/CMIS-v1.1-errata01-os-complete.html

this url based on browser binding is meant to be accessed from browser/httpget request. httpPost request is not supported for this url. Hence you can get the alf_ticket and pass along with the url to access the endpoint:

e.g.:

GET http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser?alf_ticket=TICKET_8d8aa27acc731f99c77e3fb670c5c40a6642d039
Some java based httpclient examples for your reference:
public static void main(String[] args) throws ClientProtocolException, IOException { //Basic auth example CloseableHttpClient httpclient = null; try { final CredentialsProvider provider = new BasicCredentialsProvider();
//non admin user final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("testUser", "welcome"); provider.setCredentials(AuthScope.ANY, credentials); httpclient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build(); atomPubTestBasicAuth(httpclient); } finally { if (httpclient != null) { httpclient.close(); } } //Example via alf_ticket browserBindingTest(); } private static void atomPubTestBasicAuth(final CloseableHttpClient httpclient) throws IOException, ClientProtocolException { System.out.println("Invoking atomPubTestBasicAuth..");
//atompub url example final HttpPost httpPost = new HttpPost("http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom"); try(CloseableHttpResponse httpResp = httpclient.execute(httpPost);) { if (httpResp != null) { final StatusLine statusLine = httpResp.getStatusLine(); final String statusMsg = statusLine.getReasonPhrase(); final int statusCode = statusLine.getStatusCode(); System.out.println("StatusMsg: "+statusMsg+", StatusCode: "+statusCode); if (statusCode == 200) { // process further } else { //report error } } } } private static void browserBindingTest() throws IOException, ClientProtocolException { System.out.println("Invoking browserBindingTest.."); try (final CloseableHttpClient httpclient = HttpClientBuilder.create().build();) {
//example browser binding url final HttpGet httpGet = new HttpGet("http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser?alf_ticket=TICKET_8d8aa27acc731f99c77e3fb670c5c40a6642d039"); try(CloseableHttpResponse httpResp = httpclient.execute(httpGet);) { if (httpResp != null) { final StatusLine statusLine = httpResp.getStatusLine(); final String statusMsg = statusLine.getReasonPhrase(); final int statusCode = statusLine.getStatusCode(); System.out.println("StatusMsg: "+statusMsg+", StatusCode: "+statusCode); if (statusCode == 200) { // process further } else { //report error } } } } }
~Abhinav
(ACSCE, AWS SAA, Azure Admin)