从Spring安全上下文访问Spring Web MVC异常解析器
我有一个Spring Web MVC配置,其中包含一个SimpleMappingExceptionResolver来处理一些访问异常:从Spring安全上下文访问Spring Web MVC异常解析器,spring,spring-mvc,exception-handling,spring-security,Spring,Spring Mvc,Exception Handling,Spring Security,我有一个Spring Web MVC配置,其中包含一个SimpleMappingExceptionResolver来处理一些访问异常: <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:defaultErrorView="uncaughtException"> <property name="exceptionMappings">
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:defaultErrorView="uncaughtException">
<property name="exceptionMappings">
<props>
<prop key=".DataAccessException">dataAccessFailure</prop>
<prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
<prop key=".TypeMismatchException">resourceNotFound</prop>
<prop key=".MissingServletRequestParameterException">resourceNotFound</prop>
</props>
</property>
</bean>
我在想,通过将安全映射移动到MVC配置,将它们整合到单个异常处理配置中会很好。我的问题是,我不知道如何告诉Spring安全性我希望表单登录的身份验证失败处理程序使用解析器
我不能只向SimpleMappingExceptionResolver添加一个id,因为1身份验证失败处理程序ref需要一个处理程序,而不是解析程序,2 MVC配置中定义的任何bean在安全上下文中似乎都不可见
谢谢你的帮助 要回答问题的第2部分,您可以通过使用标记在配置之间共享bean定义 我不确定您在第1部分“单一异常解析程序”中会取得多大成功,因为看过API后,这两个类完全不同——没有共享接口。您可能需要使用其中一个类作为平台,并将另一个类的功能构建到其中,从而实现自己的功能
<form-login authentication-failure-handler-ref="exceptionMapper" ... />
...
<bean id="exceptionMapper" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler" >
<property name="exceptionMappings">
<props>
<prop key=".CredentialsExpiredException">/resetPassword</prop>
<prop key=".BadCredentialsException">/login?failure=true</prop>
</props>
</property>
</bean>