Advanced Share Customization (part 2)

cancel
Showing results for 
Search instead for 
Did you mean: 

Advanced Share Customization (part 2)

ddraper
Intermediate
0 15 1,123

Introduction



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:

<alfresco-config>

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

      <web-framework>

         <defaults>

            <page-type>

               <id>login</id>

               <page-instance-id>blog-login</page-instance-id>

            </page-type>

         </defaults>

      </web-framework>

   </config>

</alfresco-config>


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:

<page>

   <template-instance>blog-login</template-instance>

   <authentication>none</authentication>

</page>


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:

<template-instance>

   <template-type>blog/demo/blog-login</template-type>

</template-instance>


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!!):

<html>

   <head>

      <title>Blog Application Login</title>

   </head>

   <body>

      <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' />

      </form>

   </body>

</html>


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
15 Comments
blog_commenter
Active Member
Thanks for the post really interesting...
blog_commenter
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!
Thanks
Mike Chase (Former Microsoft .Net developer, now open source Evangelist)
ddraper
Intermediate
Thanks for the feedback Mike, however this isn't really the right place for those questions - you should really be using the Alfresco forums (https://forums.alfresco.com/en/) 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.
blog_commenter
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
ddraper
Intermediate
@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.
blog_commenter
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
blog_commenter
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
ddraper
Intermediate
@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.
blog_commenter
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!!!
blog_commenter
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.



Regards,

   Jan
ddraper
Intermediate
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 (https://issues.alfresco.com/jira/browse/ALF-19957) 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,



Thanks,

Dave
blog_commenter
Active Member
Hi,

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

s/alfresco/site-data/template-types/webtemplate.xml?s=sitestore

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

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

java.net.ConnectException: Connection refused: connect

        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)

        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI

mpl.java:85)

        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja

va:339)

        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket

Impl.java:200)

        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java

:182)

        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)

        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

        at java.net.Socket.connect(Socket.java:579)
ddraper
Intermediate
@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.
blog_commenter
Active Member
Same error of Sudipto, I use the 5.0.a. Perhaps Sudipto uses the same version.



Regards
blog_commenter
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

java.net.ConnectException: Connessione rifiutata

        at java.net.PlainSocketImpl.socketConnect(Native Method)

        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)

        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)

        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)

        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

        at java.net.Socket.connect(Socket.java:579)

        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.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)

        at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)

        at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)

        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)

        at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)

        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)

        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)

        at org.springframework.extensions.webscripts.connector.RemoteClient.service(RemoteClient.java:1054)

        at org.springframework.extensions.webscripts.connector.RemoteClient.service(RemoteClient.java:829)

        at org.springframework.extensions.webscripts.connector.RemoteClient.call(RemoteClient.java:577)

        at org.springframework.extensions.webscripts.connector.RemoteClient.call(RemoteClient.java:511)

        at org.springframework.extensions.webscripts.connector.HttpConnector.call(HttpConnector.java:70)

        at org.springframework.extensions.webscripts.RequestCachingConnector.call(RequestCachingConnector.java:90)

        at org.springframework.extensions.webscripts.connector.AbstractConnector.call(AbstractConnector.java:116)

        at org.springframework.extensions.webscripts.connector.AuthenticatingConnector.call(AuthenticatingConnector.java:114)

        at org.alfresco.web.site.EditionInterceptor.preHandle(EditionInterceptor.java:94)

        at org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter.preHandle(WebRequestHandlerInterceptorAdapter.java:54)

        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:781)

        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)