5

私は立ち往生していますが、おそらくドキュメントに何かが見当たらなかったり、小さな間違いがありました。AcceptHeaderLocaleResolverとi18nでの春のセキュリティ

Spring Security 3.0.5がSpring MVC 3.0.5アプリケーションに統合されました。 AcceptHeaderLocaleResolverは、ロケールの検出に使用され、セキュリティエラーメッセージを除いてローカライゼーションは正常に機能します。

私はspringセキュリティパッケージからmessages.propertiesをコピーして名前を変更し、既存の"messageSource" bean(ResourceBundleMessageSource)の値リストに追加しました。

上述したように、ハードコードされた英語のメッセージを使用するセキュリティシームを除いて、すべてのテキストとメッセージは正しくローカライズされています。

これを解決する方法はありますか?

UPDATE:
私のxy-servlet.xmlが含まれています

... 
<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> 

とファイル

  • defaultMessages.properties
  • defaultMessages_en.properties
  • defaultMessages_de.properties
  • defaultMessages_sl.properties

  • securityMessages.properties
  • securityMessages_en.properties
  • securityMessages_de.properties
  • securityMessages_sl.properties

しかしdefaultMessages WOR k ok。 securityMessagesはありません。 securityMessagesすべてのファイルに小さな変更を加えましたが、無視され、ハードコードされた英語のメッセージが表示されます。

UPDATE v2の: 私のディスパッチャ-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> 

答えて

5

最後に、溶液!

私はapplicationContext-security.xmlの で宣言されている必要がありますが、アプリケーションコンテキストでは設定されていない必要があります。私の場合は

正しい解決策は、ApplicationContextの-のsecurity.xmlでBeanです:いくつかのアイデアのための@bluefoot@jtoberon

<b:bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <b:property name="basenames"> 
      <b:value>secMessages</b:value> 
     </b:property> 
    </b:bean> 

感謝。

UPDATE: この適切web.xmlのがspringSecurityFilterChainlocalizationFilterが含まれている必要があります動作するように、私のweb.xmlがある:i18nのコメントの後

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

<!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/spring/applicationContext-security.xml</param-value> 
</context-param> 

<!-- i18n --> 
<filter> 
    <filter-name>localizationFilter</filter-name> 
    <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> 
</filter> 

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<!-- i18n --> 
<filter-mapping> 
    <filter-name>localizationFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping> 


<!-- Creates the Spring Container shared by all Servlets and Filters --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<!-- Processes application requests --> 
<servlet> 
    <servlet-name>appServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

</web-app> 


チェックライン。

+0

私はSpring MVCに関する多くの経験がなく、 'xy-servlet.xml'ファイルがアプリケーションコンテキスト設定ファイルではないことを知りませんでした。とにかく私はうまく働いてうれしいです。 – bluefoot

+0

私はSpring 3.2を使用していますが、この同じ問題に直面しているようですが、残念ながらこの解決法は私にとってはうまくいかないようです。 – Ryan

3

私は(あなたが言っていなかった)あなたはそれをどうやったのか知らないが、あるメッセージバンドルを使用します

<bean id="messageSource" 
    class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basenames"> 
     <list> 
      <value>org/springframework/security/messages_pt_BR</value> 
     </list> 
    </property> 
</bean> 

MESSAを変更します:春のセキュリティ(代わりにハードコード化されたテキストメッセージの)に同梱されて、私はちょうどResourceBundleMessageSource Beanを宣言し、basenamesプロパティを設定する必要がありますgesをpt_BRに変更するには、デフォルトBeanの代わりにこのBeanを使用してスプリングを作成します(もちろん、クラスパス上にjarファイルがあると仮定してファイルを別の場所にコピーする必要はありません)。ここで

+0

私は同意する、これは私のためにも働く。 – carlspring

+0

@bluefoot最新の質問を確認してください。私はあなたの答えを使う方法を知らない。私は ' org/springframework/security/securityMessages_sl'を使うべきですか? – Solata

+0

なぜ自分のプロパティを作成していますか?それらのいくつかはすでに春のセキュリティコアの瓶に入っています。おそらくファイルがクラスパスに見つかりません。 ' defaultMessages securityMessages'を削除し、それを ' org/springframework/security/messages_de'( 'xy-servlet.xml'はあなたのアプリケーションコンテキスト設定ファイルとする)と置き換え、何が起こるかを見てください。 – bluefoot

1

はいくつかのアイデアです:

  1. は、セキュリティメッセージがクラスパス上にないという可能性はありますか?あなたのリソースファイルはすべて同じディレクトリにありますか?あなたはWEB-INF/classesに入れていますか?もしそうでなければ、クラスパスにいることをどのように知っていますか?
  2. 名前空間またはキーの競合がありますか。言い換えれば、他のリソースファイル(すでに動作しているもの)に既に定義されているセキュリティエラーメッセージのデフォルト値ですか?
+0

アイデアありがとう! ** 1。**メッセージがクラスパス上にあるかどうかを確認するにはどうすればいいですか?すべてのファイルは同じディレクトリにあり、WEB-INF/classes ** 2にあります。**私のdefaultMessagesでは、名前空間やキーの競合がないと思います。 – Solata

関連する問題