Feb 13th, 2006, 08:38 AM
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.
Feb 13th, 2006, 12:55 PM
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.
Feb 14th, 2006, 03:26 AM
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.
Mar 6th, 2006, 12:46 AM
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.