I am trying to make our webapp I18N compatible but we want our users to be able to "choose" their locale. The way we are doing this is on the login.jsp page there are links to a set list of available languages. When they click on the appropriate link it changes their locale through Springs SessionLocaleResolver and a LocaleChangeInterceptor.
I've got this part of the code working fine but now I'm looking for the best way to make this work with Acegi. I'm using a custom authenticationDao but I'm using Acegi's DaoAuthenticationProvider.Code:<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> <property name="paramName" value="siteLang" /> </bean> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" /> <!-- Map urls to controller --> <bean id="beanNameUrlMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"> <property name="interceptors"> <list> <ref bean="localeChangeInterceptor" /> </list> </property> <property name="order"><value>0</value></property> </bean>
Here's my filter chain proxy setup:
NOTE:lanchange.html just points to a simple controller I wanted outside the security wall to change the locale FROM the login.jsp page. It's currently called from a second form on the login.jsp page that calls /langChange.html?siteLang="<de,en,etc>". But my actual login form on login.jsp calls /j_acegi_security_check. What I think I want to do is add this siteLang input to the /j_acegi_security_check form and have it get processed by the SessionLocaleResolver.Code:<bean id="filterChainProxy" class="net.sf.acegisecurity.util.FilterChainProxy"> <property name="filterInvocationDefinitionSource"> <value> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON PATTERN_TYPE_APACHE_ANT /langchange.html*=integrationFilter /index.jsp=integrationFilter /login.jsp*=integrationFilter /j_acegi_security_check*=integrationFilter,authenticationProcessingFilter /**/*.html*=integrationFilter,authenticationProcessingFilter,securityEnforcementFilter /**/*.jsp*=integrationFilter,authenticationProcessingFilter,securityEnforcementFilter </value> </property> </bean>
I've come up with some possible approaches but none of them sound like they'll work:
1.The way the SessionLocaleResolver works is that whenever I make a request that is processed through Spring's UrlHandlerMapping, an interceptor on that handler (see code above) looks for a request parameter called "siteLang". If it finds it, it changes the locale to the value of siteLang. I figured I can just add another input to my login.jsp page called "siteLang" and submit it along with the rest of the fields. The problem is that I can't put "j_acegi_security_check" into my Spring urlHandlerMapping bean can I? If I can, where do I have it map to?
2.Maybe I can just pass "siteLang" input from login.jsp just as another input and write my own implementation of some Acegi class in the authentication process that manually calls RequestContextUtils.getLocaleResolver(request).set Locale(request,response,new Locale("en,de,etc"));.
I'm not sure if either of these will work however. Any advice would be helpful.
Maybe I'm making this much more complicated than it needs to be. In short my goal is that I want to give our users the ability to choose their language from the Login page. I want to use the Locale for this because we're using Springs ResourceBundleViewResolver with I18N based interntionalization. But I don't want to just use their browser's locale, I want the user to choose one from the login screen, so I need to use one of Spring's locale resolvers. I'd like to have it be the SessionLocaleResolver but I'm flexible on that. I know how to do all of this outside of Acegi, but now I need to integrate it with the Acegi login process. If anyone has a nice clean way to do this I'd be in your debt. This has been driving me nuts.


