Thursday, April 7, 2016

Create Alfresco Share sites through Webscript.


I see many has requirement to create share site programmatically and OOB API is not available to create fully functional site.

Create a site is two step functionality.
     1. Create repository level site folder structure
     2. Create surf site presets objects.
So we need to call surf web script – “/service/modules/create-site”

As per Alfresco - If you call a Surf Web Script URL directly in a browser address bar there is no authentication (i.e. no context). You would need to have a JSESSIONID that is already authenticated (i.e. by the page). Surf ties the given JSESSIONID to the Alfresco TICKET that is stored in the session for that user for that connector (i.e. alfresco, alfresco-api).

I tried some posts to create site through script but it was not working for me. All scripts like dologin, create-site were getting executed OK with 200 status and without any error but when I check actual site it was not getting created.

Then I tried to login in to Share through browser and I used same cookies from browser to in my code then site was getting created perfectly OK so might be session was not getting initiated.
So I called authenticated service in between and its working fine.

 Below is working JAVA code.

NOTE: I have default Alfresco NTLM authentication and I have disabled CSRF token filter. I have verified it against Alfresco 5.x EE.

If You have not disabled CSRF token filter then add below snippet in your share-config-custom.xml located at [tomcat\shared\classes\alfresco\web-extension] as per - https://www.alfresco.com/blogs/ewinlof/2013/03/11/introducing-the-new-csrf-filter-in-alfresco-share/