title: How do you enable LocaleInterceptor to change the locale in spring-security login page?
body: <p>Pardon me if this question has been asked before, but I haven't gotten a straight answer that helped me solve my problem. 
  I have a gwt application that I have secured using spring-security. Spring security just authenticates the user and redirects to the gwt application. Now i want the user to be able to change the locale from a link on the login page after which the locale will be stored on a cookie and used in the app. </p>
  
  <p>I have the following configurations, in my applicationContext.xml</p>
  
  <pre><code>&lt;http auto-config="true"&gt;
      &lt;intercept-url pattern="/mywebapp/**" access="ROLE_USER"/&gt;
      &lt;intercept-url pattern="/gwt/**" access="ROLE_USER"/&gt;
      &lt;intercept-url pattern="/**/*.html" access="ROLE_USER"/&gt;
      &lt;intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
      &lt;intercept-url pattern="/login.jsp*" access="IS_AUTHENTICATED_ANONYMOUSLY"/&gt;
      &lt;form-login login-page="/login.jsp"/&gt;
  &lt;/http&gt;
  &lt;beans:bean id="userDetailsService"
      class="com.kibet.mywebapp.server.auth.UserDetailsServiceImpl"&gt;
  &lt;/beans:bean&gt;
  
  ...
  &lt;!-- Application Message Bundle --&gt;
  &lt;beans:bean id="messageSource"
  class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
      &lt;beans:property name="basename" value="classpath:messages" /&gt;
      &lt;beans:property name="defaultEncoding" value="UTF-8"/&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="localeChangeInterceptor"
  class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"&gt;
      &lt;beans:property name="paramName" value="lang" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="localeResolver"
  class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt;
      &lt;beans:property name="defaultLocale" value="pt"/&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="urlMapping"
       class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
      &lt;beans:property name="interceptors"&gt;
      &lt;beans:list&gt;
          &lt;beans:ref bean="localeChangeInterceptor"/&gt;
      &lt;/beans:list&gt;
      &lt;/beans:property&gt;
      &lt;beans:property name="mappings"&gt;
      &lt;beans:value&gt;/login.jsp=userDetailsService&lt;/beans:value&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p>This doesn't seem to work. I have the locale properties files messages_en.properties, messages_es.properties and messages_pt.properties in my classpath. The only time it works is when I change the browsers default locale.
   As far as I can tell, the login page is generated by spring-security and the handler mapping cannot intercept the locale change request. If this is the reason how would I go about this? Help is highly appreciated.</p>
  
  <p>Here's my Custom filter code.</p>
  
  <pre><code>public class InternationalizationFilter implements Filter {
  
  @Override
  public void destroy() {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void doFilter(ServletRequest request, ServletResponse response,
          FilterChain filterChain) throws IOException, ServletException {
      String newLocale = request.getParameter("lang");
      if (newLocale != null) {
          Locale locale = StringUtils.parseLocaleString(newLocale
                  .toLowerCase());
          LocaleContextHolder.setLocale(locale);
      }
      try {
          filterChain.doFilter(request, response);
      } finally {
  
          LocaleContextHolder.resetLocaleContext();
      }
  }
  
  @Override
  public void init(FilterConfig arg0) throws ServletException {
  
  }}
  </code></pre>