Advanced Share Customization (part 2)

Showing results for 
Search instead for 
Did you mean: 

Advanced Share Customization (part 2)

Intermediate II
0 15 4,670


In the first part of this tutorial I demonstrated how you could add a new page to Alfresco Share and have it protected by the standard authentication mechanism. I also showed how you can make that new page the landing page for your Alfresco Share by setting it as the root page in the Spring Surf configuration. In the second part of this tutorial I'll show how you can override the default Alfresco Share login page and in next blog I'll show how to customize and re-use existing pages and access core services.

Step 3: Override the default login page

Spring Surf applications can define a login page by configuring the 'login' page-type mapping to reference a specific Page object. In Alfresco Share this definition can be found in the 'surf.xml' configuration file which sets the 'login' page-type to map to the 'slingshot-login' page.

To override this definition you should create a (or add to your existing) 'share-config-custom.xml' file and place it in 'alfresco/web-extension' folder (this location can quite happily exist within the JAR file that we started creating in the first part of this tutorial). Add the following content to this file:


   <config evaluator='string-compare' condition='WebFramework'>











We now need to create the Page that we have referenced, create a file called: 'blog-login.xml' and place it in the 'alfresco/site-data/pages' path of your JAR. It should contain the following:





Notice that the Page definition sets and <authentication> value of 'none' - this is important to ensure that Surf doesn't attempt to redirect to the login page when the user isn't authenticated causing an infinite loop!

Next create a file called 'blog-login.xml' and place it in the 'alfresco/site-data/template-instances' path of your JAR. It should contain the following:




This file creates the mapping between the Template-Instance object and the FreeMarker template that will actually render your new login page. Create this file 'blog-login.ftl' and place it in the 'alfresco/templates/blog/demo' path of your JAR. This file should contain the following code to render a login page (NOTE: this is a completely stripped down login page - I'm not trying to win any awards for style, accessibility or i18n here... I'm just demonstrating the bare minimum required!!):



      <title>Blog Application Login</title>



      <form id='loginform' accept-charset='UTF-8' method='post' action='${url.context}/page/dologin'>

         Username: <input type='text' id='username' name='username'/><br>

         Password: <input type='password' id='password' name='password'/><br>

         <input type='submit' id='btn-login' />




Build your JAR, re-deploy it to '<tomcat-home>/webapps/share/WEB-INF/lib' and restart Tomcat (assuming you're using Tomcat - adjust as necessary for your web server). Now when you attempt to view 'http://localhost:8080/share' (adjust port as necessary) you will be prompted with your new login page and following successful authentication will be taken to your new landing page.

New login screen
Active Member
Thanks for the post really interesting...
Active Member
Great! Cant wait to try this. Our Alfresco is live, 14 sites, 70+ users. Here we go collaborating!
Favor Request - Im new to Spring and Rest and YUI. Im playing catch-up. learning as fast as I can...however, I could really use two step by steps:
(1) How to upgrade Alfresco community. I know its supposed to be easy, but when you dont have the basic skills, none of this stuff is easy.
(2) How to limit the file upload size in share. There is no good reason to upload a 6MB PDF!
Mike Chase (Former Microsoft .Net developer, now open source Evangelist)
Intermediate II
Thanks for the feedback Mike, however this isn't really the right place for those questions - you should really be using the Alfresco forums ( as you're almost certainly going to hit a wider audience and the answers may already be there if you use the search facility - also, the responses will be able to benefit the wider community as well if they haven't already been answered.
Active Member
sorry for the question, but could you please indicate the correct instruction to build the JAR ?

what is the correct command to execute ?

Best regards
Intermediate II
@Fred... I normally just use Eclipse to export a Java project as a JAR. If you work through all my previous blogs you'll see how the JAR file should be structured. I've tried to avoid repeating instructions with each blog post so as not to clutter them up - each post (relating to customization) is really building on the last.
Active Member
Hi David,

I just want to know how can i display custom messages for invalid login in my custom login page.I followed the instructions you have provided in your blog to override the default login of alfresco with mine and it was helpful alot.So kindly help
Active Member
I was able to login from my custom login page following your tutorial. There is only one thing that is obscure to me. How can I bring in new resources like you say? I mean, I want to make some enhancements to the page using some css and jQuery library. Where do I have to import those resources, in the ftl file?

I noticed that it's not necessary to create a jar file to put on the tomcat/shared/lib folder, I simply put all the files in the correct position inside tomcat/shared/classes.

Do I have to create a META-INF folder inside  tomcat/shared/classes/alfresco with my resources?

I'm a bit confused.

Thanks a lot
Intermediate II
@Stefano When adding in content via a JAR file you should place resources under the META-INF folder as you've said, but if you're updating the WAR file directly then you can just add those files anywhere within the 'share' folder.  This will work as long as you prefix all your resource requests with /res (e.g. '/share/res/my_javascript.js') as Surf will look in both the 'share' folder and in 'META-INF' on the classpath.  There are other locations that Surf will look in but these are the two you should be familiar with and it's also possible to configure Surf to look in custom locations.
Active Member
Dave, what a speed Smiley Tongue

I did it deploying a custom jar in tomcat/shared/lib with only a META-INF folder with my resources inside. Now share 'can see' them. Linked in my ftl file as you said: /share/res/my_javascript.js

The rest of my files for the share login customization live under tomcat/shared/classes/alfresco.

Just js and css in the jar.

Thank you!!!
Active Member
Hi Dave,

have you ever finished part three of this article? I am really interested in using a stripped down share interface for a specific group of users. These users should only be able to upload and download files without any other features.


Intermediate II
Hi Jan,

Unfortunately not. That's an interesting use case though, and something that might be interesting for me to blog about in the future. I have a limited amount of time for blogging and each post takes quite a bit of time though, but please add a sub-task to this issue ( with as much detail as possible for what you're looking for and hopefully I'll find some time soon to get some more blog posts done,


Active Member

I am getting the login page but when I am clicking on submit button page is not going forward to next page or dashboard. I am getting the below error in tomcat log file. Can you please help me out?

2014-09-10 23:46:27,797  INFO  [webscripts.connector.RemoteClient] [http-apr-809

0-exec-10] Exception calling (GET) http://localhost:8080/alfresco/s/remoteadm/ha


2014-09-10 23:46:27,797  INFO  [webscripts.connector.RemoteClient] [http-apr-80

90-exec-10] Error status 503 Connection refused: connect Connection refused: connect

        at Method)









Intermediate II
@Sudipto - you've not really provided much information to go on here... e.g. what version of Alfresco you're using, if you're following the blog post example exactly or are building your own variant, etc. Also, I'd recommend moving this question to the Alfresco forums, as you may get a solution faster.
Active Member
Same error of Sudipto, I use the 5.0.a. Perhaps Sudipto uses the same version.

Active Member
Sorry not the same, when I access to the share login page, with alfresco 5.0.a I get a lot of errors like this: 17:23:49,956 INFO  [org.springframework.extensions.webscripts.connector.RemoteClient] [http-apr-443-exec-1] Exception calling (GET) http://localhost:8080/alfresco/s/api/admin/restrictions?guest=true

17:23:49,958 INFO  [org.springframework.extensions.webscripts.connector.RemoteClient] [http-apr-443-exec-1] Error status 503 Connessione rifiutata Connessione rifiutata

        at Method)






        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(

        at java.lang.reflect.Method.invoke(

        at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(

        at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(


        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(

        at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(

        at org.apache.commons.httpclient.HttpClient.executeMethod(

        at org.apache.commons.httpclient.HttpClient.executeMethod(

        at org.springframework.extensions.webscripts.connector.RemoteClient.service(

        at org.springframework.extensions.webscripts.connector.RemoteClient.service(








        at org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter.preHandle(

        at org.springframework.web.servlet.DispatcherServlet.doDispatch(

        at org.springframework.web.servlet.DispatcherServlet.doService(