Friday, February 27, 2015

Custom Alfresco Share logout

When clicking on the default Alfresco Share "logout" link, it takes you back to the login screen.  If you want to send the user to a custom page, but keep all the existing functionality of actually logging the user's session out, here's what you can do:

I tested this on Alfresco Community 4.2.e.

  1. When mousing over the Logout link in Alfresco Share, you can see it wants to send you to "http://<host>:<port>/share/page/dologout".
  2. Grepping the code base for files that contain /dologout url, the following files comes up: 
    • WEB-INF/classes/alfresco/share-config.xml: /dologout 
    • WEB-INF/classes/alfresco/share-security-config.xml: /page/dologout(\?.+)? 
    • WEB-INF/classes/alfresco/slingshot-application-context.xml: /dologout/**=logoutController 
  3. We'll only need to override definitions in slingshot-application-context.xml, since this is where the logoutController bean is defined, and where it is used to controller the /dologout mapping.  Reference the two bean with definition: 
    • <bean id="webframeworkHandlerMappings" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" abstract="true">
    • <bean id="'logoutController" class="org.aflresco.web.site.servlet.SlingshotLogoutController">
  4. To override slingshot-application-context.xml, we'll have to use web-extension/custom-slingshot-application-context.xml.  To minimize other cascading changes, we will not change the /dologout url, we will extend the spring bean that is implementing the /dologout url
    • Copy over the two beans from slingshot-application-context.xml from the previous step.
    • Change the "logoutController" beanId name with a custom one (let's call it cherryshoeLogoutController), and extend it with a custom java class (let's call it CherryShoeSlingshotLogoutController.java). 
    • For the "webframeworkHandlerMappings" beanId, change the following in the "mappings" property.
      • /dologout/**= cherryshoeLogoutController
  5. The org.alfresco.web.site.servlet.SlingshotLogoutController is located in alfresco-share-<version>.jar.  Make a copy of the java code from there and name it CherryShoeSlingshotLogoutController.java.
    • CherryShoeSlingshotLogoutController should extend SlingshotLogoutController, to keep the existing functionality.
    • Make modifications to "handleRequestInternal" method - override the finally block to redirect to a custom cherryshoe-logout.jsp page that is located in the share context root folder.
      finally
      {
          // Copy the code from this class's parent parent that does additional logout capabiliites, 
          // so we can control the redirect page
          AuthenticationUtil.logout(request, response);
                  
          // redirect to a custom jsp page in the root of the website
          response.sendRedirect(request.getContextPath() + "/cherryshoe-logout.jsp");
          return null;
                  
          //return super.handleRequestInternal(request, response);
      }
  6. Create a custom cherryshoe-logout.jsp page and save it under the share context root folder.

6 comments:

  1. response.sendRedirect(request.getContextPath() + "/cherryshoe-logout.jsp"); seems to be not redirecting.

    Could you please suggest, I am using alfresco 5.0.1

    ReplyDelete
    Replies
    1. Can you describe the changes that you have made?

      If you debug or put debug statements inside CherryShoeSlingshotLogoutController before and after handleRequestInternal's send Redirect code, does it print it out in the log or console window? Is sendRedirect enabled?

      Is AuthenticationUtil.logout enabled and prior to sendRedirect?

      Did you create a custom.jsp page in the root context of the share webapp folder?

      How do you customize alfresco, do you use amps, if so, has the custom java code been redeployed in the custom jar in the amp into share.war?

      Thanks
      Judy

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Sorry for late reply, there is as such no error message and it is also executing the response.sendRedirect(request.getContextPath() + "/cherryshoe-logout.jsp"); statement but seems to be not forwarding to /cherryshoe-logout.jsp page..
    I am deploying the changes using the amp file as amp_share..

    ReplyDelete
  4. I got the solutions and fixed...
    Thanks..

    ReplyDelete

I appreciate your time in leaving a comment!