Announcement Announcement Module
Collapse
No announcement yet.
Custom login page and localization Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom login page and localization

    Hi all, I am having trouble with custom login page and localization.

    some interesting configuration parts

    applicationContext-security.xml
    Code:
    	<beans:import resource="classpath:applicationContext.xml"/>
    	
    	<http auto-config="true" access-denied-page="/accessDenied.jsp" access-decision-manager-ref="accessDecisionManager">
    		<intercept-url pattern="/favicon.ico*" filters="none" />
    		<intercept-url pattern="/css/**" filters="none" />
    		<intercept-url pattern="/images/**" filters="none" />
    		<intercept-url pattern="/sessionTimeout.jsp" filters="none" />
    		<intercept-url pattern="/login.htm" filters="none" />
    		<intercept-url pattern="/**" access="PERM_FULL_ACCESS" />
    		<form-login login-page="/login.htm" authentication-failure-url="/login.htm?login_error=1" default-target-url="/helloworld.htm" always-use-default-target="true" />		
    	</http>
    
    ... deliberatly omitted for clarity ...
    applicationContext.xml
    Code:
             ... deliberatly omitted here for clarity ...
    
    	<!-- ### Localization ### -->
    	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basenames">
    			<list>
    				<value>WEB-INF/classes/spring/security/messages/messages</value>
    			</list>
    		</property>
    	</bean>
    	
    	<!-- Enables annotated POJO controllers with @Controller -->
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    	
    	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    	
    	<bean id="localeResolver" class="org.springframework.web.servlet.i18n.FixedLocaleResolver"
    		p:defaultLocale="es_ES" />
    	
    	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    		p:viewClass="org.springframework.web.servlet.view.JstlView"
    		p:prefix="/WEB-INF/jsp/"
    		p:suffix=".jsp" />
    		
    	<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"
    		p:defaultErrorView="defaulterror" />
    web.xml (found on this forum)
    Code:
    	<listener>
    	   <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    	</listener>
    And now description of a problem.

    I have a custom login form ("login.htm") form, and controller that will result as login.jsp view.

    As can be seen from image001.jpg, login.htm page shows that CurrentLocale is es_ES.
    I've copied messages_es_ES.properties and put this file in "src/main/resources" and when WAR is deployed in Tomcat, it is under WEB-INF/classes/spring/security/messages.
    (see image002.jpg)

    I've entered wrong credentials and I am expecting that I will get 'Bad credentials' in spanish. But that is not what is happening

    When I look in log I see this message (and you can see it in image001.jpg):
    Code:
    ResourceBundle [WEB-INF/classes/spring/security/messages/messages] not found for MessageSource: Can't find bundle for base name WEB-INF/classes/spring/security/messages/messages, locale en_GB
    So why this is happening ?

    Page shows correct FixedLocaleResolver set to es_ES, but springsecurity doesn't look for es_ES but looking for Browser locale.

    I say browser locale because I've tried with FF 3.6.x and IE 8 (FF is set to en_GB and IE is set to en_US)

    Any ideas? Help ?

  • #2
    Any help ???

    I will here attach Maven2 project that I've isolated (project consists of parent springsecurity[pom packaging] and web [war packaging] module) in order to make easier to someone to help me out.

    I've debugged for a while and I've descovered that ResourceBundleMessageSource doesn't use set Locale while try to resolve message for a code.

    Any ideas ???

    I 'googled' a bit and found that people had similar questions, even there was a issue on SpringSecurity https://jira.springsource.org/browse/SEC-631
    but it seems that I can't access to that issue.

    Comment


    • #3
      Possible reason ???

      I've just find this thread

      https://jira.springsource.org/browse/SEC-499

      Is this one bugging me ? And what would be the solution ? To write my own filter ?

      Comment


      • #4
        Finally done!

        Finally I've managed to solve this problem.

        I've read comments from link above and added LocaleChangeFilter as described. LocaleChangeFilter implemented as custom filter and positioned on first place.

        I've attached full source code of project here.


        P.S. Since I am from Serbia, I am willing to contribute messages_sr_RS.properties to Spring Security 3.x

        There is still problem with encoding Serbian special chars, and if You plan to add this to Spring Security some should contact me and explain me how to allow UTF-8 encoding of some characters in messages_sr_RS.properties file.

        Comment


        • #5
          Hi!

          Thanks for the sourcecode!

          I too solved this issue using LocaleChangeFilter!

          Feel free to vote for the following issue which contain an implementation of LocaleChangeFilter: https://jira.springframework.org/browse/SPR-3939


          -Kaj

          Comment


          • #6
            You might also want to check this recent thread.

            Comment

            Working...
            X