Results 1 to 2 of 2

Thread: Forcing the language for SPRING_SECURITY_LAST_EXCEPTION

  1. #1
    Join Date
    Jun 2009
    Posts
    10

    Default Forcing the language for SPRING_SECURITY_LAST_EXCEPTION

    Hi all,

    I am using Spring Security 2.0.4 and the following code:
    Code:
    %{#session.get('SPRING_SECURITY_LAST_EXCEPTION').message}
    to display error on login page. I've noticed that the message is displayed in the default language of the browser (for Firefox, Tools/Options/Content/Languages). This is pretty neat if i18n is what you are after, but I want to force the message to be in English for everyone, including those whose language is set to some other. I can't find anywhere how to do it, and would appreciate if someone could help me.

    I tried debugging it and have noticed that in AbstractProcessingFilter.doFilterHttp method the exception caught is BadCredentialsException which contains the foreign message string in it's detailMessage.
    EDIT: After more debugging, the exception is thrown from ProviderManager.doAuthentication method, when AuthenticationProvider.authenticate method is called. For some reason I cannot step into that method (AuthenticationProvider.authenticate), when I try I go to JdkDynamicAopProxy.invoke

    Cheers, Ben.
    Last edited by bengateau; Jun 29th, 2009 at 03:06 AM.

  2. #2
    Join Date
    Jun 2009
    Posts
    10

    Default

    I think this message is in the wrong forum, it should be in Web forum. Would appreciate if admin would copy it over to the Web forum.

    I found that the default locale resolver in Spring is AcceptHeaderLocaleResolver. To override it, I created my own resolver:
    Code:
    public class FixedLocaleResolver implements LocaleResolver {
    	private Locale defaultLocale;
    	
    	public Locale resolveLocale(HttpServletRequest req) {
    		return defaultLocale;
    	}
    
    	public void setLocale(HttpServletRequest req, HttpServletResponse res, Locale loc) {
    	}
    
    	public Locale getDefaultLocale() {
    		return defaultLocale;
    	}
    	public void setDefaultLocale(Locale defaultLocale) {
    		this.defaultLocale = defaultLocale;
    	}
    And in applicationContext.xml:
    Code:
    <bean id="localeResolver" class="my.package.goes.here.FixedLocaleResolver">
        <property name="defaultLocale" value="en"/>
    </bean>
    But it's still not working. Can someone tell me, do I need to define my localeResolver somewhere else so it can be picked up by application?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •