Bean定義が複数の親子コンテキストに分割されたSpring-MVCアプリケーションでSpring Securityを定義するための推奨方法を理解しようとしています。Spring Security + MVC:コンテキスト定義とBeanスコープに関する質問
たとえば、次のように私の現在のアプリのweb.xml
は、(私はかなり標準的であることを理解している)、見え
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
/WEB-INF/securityContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
だから、私は私の世界のconfigsをロードする、/
で定義された標準ContextLoaderListener
を持っている - applicationContext.xml
とsecurityContext.xml
。 /app/
にspring mvc DispatcherServlet
を定義します。spring-mvc-servlet.xml
から独自のBeanをロードします。
私が理解しているように、spring-mvc-servlet.xml
に定義されている設定は、いずれのトップレベルのコンテキストファイルでも定義されていません。
どこにアプリケーションレベルのセキュリティの概念を定義するのが最適ですか?たとえば、次のフィルタを追加したいとします。
<security:http pattern="/oauth/token" create-session="stateless" entry-point-ref="oauthAuthenticationEntryPoint">
<security:custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" />
</security:http>
/app/oauth/token
への要求は、このフィルタを通過し、基本認証を処理しますようにするためです。
これはSpring MVCアプリケーションの懸念事項に直接関係しているので、最初にspring-mvc-context.xml
に定義しました(そのため、app
はURLから除外されています)。
しかし、これはsecurityContext.xml
で定義されているセキュリティ設定では表示されないため、無視されます。
したがって、私はsecurityContext.xml
に移動しますが、その際にはすべての依存関係も移動する必要があります。 私はすぐにすべてapplicationContext.xml
に移動してしまうので、spring-mvc-context.xml
はほとんど空です。
これは一般的ですか?トップレベルのコンテキストで定義されているものと、子のコンテキストで定義されているものとの間の欲求的な分割は何ですか?
spring-mvcが一連のコントローラを定義していて、これを@Secured
としてマークしたい場合、コントローラがセキュリティコンテキストに表示されていない場合、これらはどのように処理されますか?
<mvc:annotation-driven />
をservlet.xml
からグローバルapplicationContext.xml
に移動する必要がありますか? spring-mvc-servlet.xml
の中で、Springセキュリティに参加するよう追加の設定が必要ですか?
私はdocumentation on Spring-MVCを読んだことがありますが、これを構成する方法は非常に少ないです。 さらに、Spring OAuth examplesは、単一の設定ファイル内にすべてを定義しているように見えますが、現実的ではないようで、私が読んだ他の例と矛盾しているようです。