我使用Spring Security 3.1.0和Spring MVC 3.1.1。 我希望能够基于URL即更改地区:LocaleResolver in filter null yet shows it has autowired! Spring MVC 3.1.1/Spring Security 3.1.0
http://localhost:8080/abc?lang=fr
现在,这个工作“正常”的情况下,即从一个页面到另一个页面然而,在我的应用程序,如果我去从一个不安全的页面到一个安全的页面,它首先碰到我的登录页面,这是Spring Security在打开我想要的页面之前提供的。
这是正常的春季安全特性(拦截安全资源),所以有这个behavuour没有问题。
问题是,当我抵达受保护的页面时,语言环境不会改变!它保持为默认语言环境。我.. lang = fr没有解析出来。
我已经打了定义语言环境相关的豆类调度-servlet.xml的内部和外部,在应用程序上下文文件执行以下操作:
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang" />
</mvc:interceptors>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en" />
我也试图分裂上述2在应用上下文配置中只有localResolver。
我做这个研究吨,基本上,我明白我需要手动更改语言环境。
即使春节文档为春季安全3.1.0说,你需要自己的“过滤器”,或者您可以使用RequestContextFilter两个。但RequestContextFilter不会解析查询字符串中的区域设置参数。
Spring Security relies on Spring's localization support in order to actually lookup
the appropriate message. In order for this to work, you have to make sure that the
locale from the incoming request is stored in Spring's
org.springframework.context.i18n.LocaleContextHolder. Spring MVC's DispatcherServlet
does this for your application automatically, but since Spring Security's filters are
invoked before this, the LocaleContextHolder needs to be set up to contain the correct
Locale before the filters are called. You can either do this in a filter yourself
(which must come before the Spring Security filters in web.xml) or you can use
Spring's RequestContextFilter.
我想截取请求之前,它击中控制器,所以,我写了我自己的过滤器。
我的解决方案的基础上,别人怎么做,以及,是自动装配的LocaleResolver中。当tomcat启动时,它会在我的日志中显示“localeResolver”已被自动装配(否则应用程序将在那里失败),但是在运行时localeResolver为NULL。
此外,已经有职位,说在应用程序上下文中定义的LocaleResolver ......我已经这样做了,但我还是最终得到一个空的LocaleResolver当一个请求发生。
任何想法??非常感激。
p.s.我定义的过滤器在Spring Security过滤器之前。我可以调试它,它首先点击它,但是因为LocaleResolver上的NPE而死。
欣赏这一点,谢谢。
你看过这个答案:http://stackoverflow.com/questions/8026320/spring-security-localeresolver – Gren 2012-04-24 15:48:33