cancel
Showing results for 
Search instead for 
Did you mean: 

Intercept alfresco login/logout in java

liuk88
Champ in-the-making
Champ in-the-making

Hi, i have the following necessity:
clear the content of a folder when a user login/logout.
I found that this can be done with java interceptors, but i don't know how, somebody can help me?
Thanks!
Luca
7 REPLIES 7

kaynezhang
World-Class Innovator
World-Class Innovator
More detail information is needed ,which application (explorer? share?) do you want to intercept ? what information do you want to intercept ?

liuk88
Champ in-the-making
Champ in-the-making
Sorry, my mistake, i put the text in the summary and not in the body Smiley Happy

P.S. I need to intercept in Share

kaynezhang
World-Class Innovator
World-Class Innovator
alfresco share is builded on spring surf framework which is builded on spring MVC.

alfresco uses the SimpleUrlHandlerMapping to map the incoming request. The SimpleUrlHandlerMapping maps request url to spring mvc controller.Mapping is configured in a file named alfresco\slingshot-application-context.xml in classpath.
Open  you'll see alfresco\slingshot-application-context.xml

   <bean id="webframeworkHandlerMappings" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" abstract="true">
      <property name="urlPathHelper" ref="urlPathHelper" />
      <property name="pathMatcher" ref="pathMatcher" />
      <property name="interceptors">
         <list>
            <ref bean="requestContextInterceptor"/>
            <ref bean="userDashboardInterceptor"/>
            <ref bean="editionInterceptor"/>
         </list>
      </property>
      <property name="mappings">
         <value>
            /system/**=remoteController
            /proxy/**=endpointController
            /resource/**=resourceController
            /feed/**=feedController
      
            /dologin/**=loginController
            /dologout/**=logoutController
      
         </value>
      </property>
   </bean>


So if you want to intercept login/logout ,you can write a springmvc interceptor or servlet filter to intercept login/logout request.

liuk88
Champ in-the-making
Champ in-the-making
Yes, i heard that i can do this with a java interceptor (is the servlet filter you mean?) but i don't know how to start, can u make me an example of a interceptor method?
Thanks!

kaynezhang
World-Class Innovator
World-Class Innovator
By filter I mean javax.servlet.Filter,You have two options to intercept login/logout
1.using springmvc interceptor
2 using javax.servlet.Filter

Here is an springmvc interceptor example

java source code

import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;

public class TestInterceptor implements WebRequestInterceptor {
   @Override
   public void afterCompletion(WebRequest request, Exception ex)
         throws Exception {
      // TODO Auto-generated method stub
   }
   @Override
   public void postHandle(WebRequest request, ModelMap model) throws Exception {
      // TODO Auto-generated method stub
   }
   @Override
   public void preHandle(WebRequest request) throws Exception {
      // TODO Auto-generated method stub

   }
}



spring configuration

…    
<property name="interceptors">
         <list>
            <ref bean="testInterceptor"/>
         </list>
      </property>
      <property name="mappings">
         <value>
            /dologin/**=loginController
            /dologout/**=logoutController
         </value>
      </property>


    <bean id="testInterceptor" class="***.***.***.***.TestInterceptor" >
        <property name="***" ref="****"></property>
    </bean>



Can this be applied to a simple custom WebScript?

No interceptors can not be applied at webscript level.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)