ACEGI: Always use defaultTargetUrl when doing the AuthenticationProcessingFilter
ACEGI's current ~AuthenticationProcessFilter default setup will redirect a user to the login page, if they are not authenticated to the system. Once authenticated, the system will forward the user back to the initial url where they needed to be authenticated. If the user came directly from the login page, and there was no authentication error to forward the user to, the system will send the user to the default target url. This default target url has been defined in the ACEGI xml configuration file as property defaultTargetUrl.
So if the user was not logged into the system, and tried to access the http://localhost/admin/home.jsp, they will be forwarded to the login page. Once the user has logged into the system, the default setup will forward the user back to http://localhost/admin/home.jsp.
Well this seems to work great for me most of the time, but I have found situations where I do not want this to be my default behavior. You might want the user to always be sent to a default page after the user has logged into the system. In a simple application I am doing, I want the user to be sent to a default action, after signing into the system. This result is desired, so that I can preform some extra validation, and then forward the user to a signup page if necessary.
To achieve this, all you have to do is put the property of alwaysUseDefaultTargetUrl in your xml config file and set the value to true. The property is set to false by default.
Here is a example of how my ACEGI xml config file now looks with the alwaysUseDefaultTargetUrl set to true.
<bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"> <property name="authenticationManager" ref="authenticationManager"/> <property name="authenticationFailureUrl" value="/login.jsp?login_error=1"/> <property name="defaultTargetUrl" value="/eligibility.action"/> <property name="filterProcessesUrl" value="/j_acegi_security_check"/> <property name="rememberMeServices" ref="rememberMeServices"/> <property name="alwaysUseDefaultTargetUrl" value="true"/> </bean>




Thank you! this was useful to my scenario
Posted by Ray Johnson on May 13, 2008 at 12:03 PM EDT #
kudos from me too!
I did't find this handy feature in the reference guide.
Posted by nada on May 15, 2008 at 12:28 PM EDT #
Thanks! Thas was really useful to me :)
Posted by wlo on June 06, 2008 at 01:55 PM EDT #
This would have really helped me out of my jam, but I'm using x509 filtering/processing... Anyone have any ideas?
Posted by Rintoul on February 02, 2009 at 06:56 PM EST #