Announcement Announcement Module
No announcement yet.
setting the locale for the DaoAuthenticationProvider Page Title Module
Move Remove Collapse
This topic is closed
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • setting the locale for the DaoAuthenticationProvider

    I want the DaoAuthenticationProvider to provide localized exception messages when a user fails to login but the problem I have is spring's DispatcherServlet is not called until after the user is authenticated hence the LocaleContextHolder is not set. I know I can set the locale manually using the LocaleContextHolder but where do I get the Locale from when I dont have access to the http servlet request in the DaoAuthenticationProvider.

    Thanks for your help.

  • #2
    I looked at the source for AbstractUserDetailsAuthenticationProvider, which is the super class, and it looks to me like it's using org.acegisecurity.AcegiMessageSource for the messages.


    • #3
      The problem isnt getting the messages from the message source but having the locale set correctly when messages are displayed for a failed login attempt.

      What i ended up doing is sublcassing AuthenticationProcessingFilter and setting the LocaleContextHolder locale in attemptAuthentication from the request. Im unsure if this is a good way of solving my problem but it works.


      • #4
        Seems a reasonable approach, although maybe writing a dedicated Filter would be more extensible in that if messages need to be generated from other parts of the framework (eg if an authorization fails) the LocaleContextHolder will that way be correctly set.