Please bear with me as I'm learning JSP, Spring, and Acegi all at once..
How can I intercept the Acegi security check? I wrote an interceptor and tested it out on a mock login handler, but now I need to apply it to the Acegi handler.
web.xml:
Code:
<filter>
<filter-name>Acegi Authentication Processing Filter</filter-name>
<filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param>
<param-name>targetClass</param-name>
<param-value>net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter</param-value>
</init-param>
</filter>
applicationContext-acegi.xml:
Code:
<bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="authenticationFailureUrl"><value>/login?loginError=1</value></property>
<property name="defaultTargetUrl"><value>/secure/welcome</value></property>
<property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
</bean>
<bean id="authenticationProcessingFilterEntryPoint" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<property name="loginFormUrl"><value>/login</value></property>
<property name="forceHttps"><value>false</value></property>
</bean>
myapp-servlet.xml:
Code:
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/j_acegi_security_check">What_Goes_Here</prop>
</props>
</property>
<property name="interceptors">
<list>
<ref bean="loginInterceptor"/>
</list>
</property>
</bean>
<bean id="loginInterceptor" class="mypackage.myapp.web.interceptor.LoginInterceptor"/>
I'm not sure what to replace What_Goes_Here (above) with. To test the interceptor, I used a normal URL-to-Spring-controller mapping here, but I'm not sure how to apply this to the Acegi login form processor, since I never explicitly map /j_acegi_login_security_check to a Spring controller. I realize that the filter definition in web.xml is establishing the relationship, but I'm not sure where to fit my interceptor into the mix.
Should I be creating a custom filter instead?
Here's the relevent portion of my interceptor:
LoginInterceptor.java:
Code:
package mypackage.myapp.web.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class LoginInterceptor extends HandlerInterceptorAdapter {
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
request.getSession().setAttribute("myAttribute", "myValue");
// ...etc.
}
}
I don't want to apply this interceptor to every request, although I suppose that's an option if that's the only solution. I'm not sure how to implement that either, however.
Thanks in advance.
--Jim