I am stuck, probably missed something in docs or made some small mistake.
Spring Security 3.0.5 was integrated in my Spring MVC 3.0.5 app. AcceptHeaderLocaleResolver is used for Locale detection and localisation works ok except for Security error messages.
I copied messages.properties from spring security package and renamed and added to existing “messageSource” bean (ResourceBundleMessageSource) with value list.
As said earlier all texts and messages are localised correctly, except Security seams to use hardcoded English messages.
Any ideas how to solve this?
UPDATE:
My xy-servlet.xml contains:
...
<mvc:resources mapping="/resources/**" location="/resources/" />
...
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>defaultMessages</value>
<value>securityMessages</value>
</list>
</property>
</bean>
and files
defaultMessages.propertiesdefaultMessages_en.propertiesdefaultMessages_de.propertiesdefaultMessages_sl.properties
and
securityMessages.propertiessecurityMessages_en.propertiessecurityMessages_de.propertiessecurityMessages_sl.properties
but defaultMessages work ok. securityMessages does not. I made small changes in all securityMessages files, but they are ignored and the hardcoded english messages are displayed.
UPDATE v2:
My dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<context:component-scan base-package="com.example.sampleapp1" />
<context:annotation-config />
<mvc:annotation-driven/>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/views/" p:suffix=".jsp" />
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>defaultMessages</value>
<value>securityMessages</value>
<value>org/springframework/security/messages_de</value>
</list>
</property>
</bean>
<!-- Persistence -->
<bean id="myPMF" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
<property name="persistenceManagerFactoryName" value="transactions-optional"/>
</bean>
<!-- Form Validator -->
</beans>
Finally, solution!
Bean for security messages apparently must me declared in applicationContext-security.xml
and not in app context xml config… I did not find this anywhere in manual!
In my case correct solution is bean in applicationContext-security.xml:
Thanks to @bluefoot and @jtoberon for some ideas.
UPDATE:
To work this properly web.xml must contain localizationFilter before springSecurityFilterChain, my web.xml is:
Check lines after i18n comments.