【发布时间】:2014-02-03 17:14:52
【问题描述】:
我有以下 spring-security.xml
<security:global-method-security proxy-target-class="true" secured-annotations="enabled" />
<security:http auto-config="false" use-expressions="true" entry-point-ref="customLoginEndpoint" >
<security:custom-filter ref="authenticationFilter" position="FORM_LOGIN_FILTER"/>
</security:http>
<bean id="authenticationFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"
p:authenticationManager-ref="customAuthenticationManager"/>
下面是customLoginEndpoint
@Component("customLoginEndpoint")
public class CustomLoginEndpoint extends LoginUrlAuthenticationEntryPoint
{
public AcapLoginEndpoint()
{
super("/auth/login");
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authenticationException)
throws IOException, ServletException {
response.sendRedirect("/auth/login");
}
}
我的控制器类有一个 @ExceptionHandler(Throwable ex) 和几个有 @Secured 注解的方法
问题是@ExceptionHandler 方法捕获了所有由@Secured 注释引起的org.springframework.security.access.AccessDeniedException,因此请求永远不会到达CustomLoginEndpoint.commence 并被拒绝。
如果我删除 @ExceptionHandler 那么一切正常。
我如何让这个工作开始被调用并避免@ExceptionHandler 捕获由于@Secured 注释而导致的 AccessDeniedException。
【问题讨论】:
标签: spring-security