Public Access to documents in a Share site
During the course of one of our recent project, it was required to provide public access to certain piece of content found in a Share site. Alfresco has the concept of Shared content which provides a preview of a piece of content. However it is not possible to access the content file itself.
This blog explains a mechanism for providing a document link against a piece of content so that it can be accessed publicly without need to login to Alfresco.
Alfresco Guest User
Alfresco has a special user called Guest which allows content to be accessible without a user having to provide the guest password. So the first step is to grant the Guest user permission to the desired share site or Repository location. This is simply accomplished by going to Repository folder, clicking on Manage Permissions for the desired share site folder and giving the Guest user the required permission (consumer). You will note that for Sites you cannot add Guest as a Site member, whence we updated the permission directly on the folder.
Content Retrieval URL
Alfresco has a built in servlet called GuestDownloadContentServlet which allows the download of content as the Guest user. The servlet is responsible for streaming a node’s content from the repository directly to the response stream. The NodeRef of the content to retrieve is encoded within the URL. The appropriate mimetype to return in the header of the stream is calculated based on filename extension passed as the final element on the url path.
The URL is in the format http://<domainame>:<port>/alfresco/guestDownload/<d | a>/workspace/SpacesStore/<doc UUID>/<docname>
- If <d> is used in the above url and the document can be rendered in a browser (e.g .txt, .xml ), the document content is displayed
- If <a> is used in the above url, the option to download/save is displayed.
If the content referenced by the URL is not accessible to the guest user, a 403 Forbidden error will be returned rather than the login page.
Hence for content that needs to be accessible publicly, we changed the system to generate a “Content Retrieval URL”. This is achieved using a folder rule calling a custom script. The URL has the above format and allows access to the content of the document via the Guest user account. The guest user account does not need to login to Alfresco in order to view content.
Share Rule and Script
var noderef = document.nodeRef + “”;
var uuid = noderef.replace(“workspace://SpacesStore/”,””);
var filename = document.name;
var downloadURL = “http://localhost:8080/alfresco/guestDownload/d/workspace/SpacesStore/” + uuid + “/” + filename;
props[“seed:downloadURL”] = encodeURI(downloadURL);
<config evaluator=”aspect” condition=”seed:published”>
<!– Default form configuration used on the document details and edit metadata pages –>
<set id=”publish-properties” appearance=”bordered-panel” label=”Publish Properties” />
<field id=”apnic:downloadURL” label-id=”label.seed_downloadURL” set=”publish-properties”/>
This is a simple way to provide public access to content located in the Alfresco repository and can be very handy for integrating alfresco content with non alfresco systems without need for proxying a user login.