4

みんな:

3.0.x および 3.1.x で作成されたExceptionTranslationFilterを取得するにはどうすればよいですか? その( accessDeniedHandlerauthenticationEntryPoint )をBeanDefinition再利用したい。Bean 名またはクラスから取得できないことがわかりました。ExceptionTranslationFilter の BeanDefinition が登録されていないようです。PropertyValueBeanDefinitionDefaultListableBeanFactory

のような他のフィルターUsernamePasswordAuthenticationFilterには、Bean 名があります: org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0。しかしExceptionTranslationFilter、持っていません。

私が見つけた唯一の方法は、filterChainProxy のプロパティを繰り返し検索することです。より良い方法はありますか?

私が擬似コードで行うこと:

BeanDefinitionBuilder builder = 
    BeanDefinitionBuilder.rootBeanDefinition(MyExceptionFilter.class);
RootBeanDefinition exceptionTranslationFilter = getExceptionTranslationFilterBeanDefinition();     
PropertyValue accessDeniedHandler = exceptionTranslationFilter.getPropertyValues().getPropertyValue("accessDeniedHandler");
Object handler = (RootBeanDefinition) accessDeniedHandler.getValue();
builder.addPropertyValue("accessDeniedHandler", handler);
beanDefinitionRegistry.registerBeanDefinition("myFilter", builder.getBeanDefinition());

したがって、本当の問題は、コア フィルターの ExceptionTranslation の accesDeniedHandler を取得する最善の方法は何かということです。BeanDefinition

4

1 に答える 1

6

実装を変更したり、実装にアクセスしたりできないExceptionTranslationFilterため:

<http>名前空間ブロックは常に SecurityContextPersistenceFilter、 、ExceptionTranslationFilter およびを作成しFilterSecurityInterceptorます。これらは固定されており、代替品に置き換えることはできません。

「従来の」Bean (名前空間プロキシの名前「springSecurityFilterChain」を使用) を使用するか、明示的に定義して で参照することにより、 のプロパティにFilterChainProxyアクセスする必要があります。ExceptionTranslationFilter<http>

<http entry-point-ref="authenticationEntryPoint">
  <access-denied-handler ref="accessDeniedHandler" />
  <!-- other options -->
</http>

<bean:bean id="authenticationEntryPoint" 
    class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
  <bean:property name="loginFormUrl" value="/login.htm"/>
</bean:bean>

<bean:bean id="accessDeniedHandler"
    class="org.springframework.security.web.access.AccessDeniedHandlerImpl">
  <bean:property name="errorPage" value="/accessDenied.htm" />
</bean:bean>

AuthenticationEntryPointドキュメントによると、実装は構成されている認証メカニズムに応じて設定されるため、必要なものを選択してください。

于 2012-08-29T10:22:58.907 に答える