您可以扩展LoginUrlAuthenticationEntryPoint。这是我的:
package hu.progos.springutils;// imports omittedpublic class AjaxAwareLoginUrlAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint { public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException { if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied"); } else { super.commence(request, response, authException); } }}然后配置spring以使用您的实现:
<beans:bean id="authEntryPoint" scope="singleton> <beans:property name="loginFormUrl" value="/login.html" /></beans:bean><http entry-point-ref="authEntryPoint"> <!-- your settings here --></http>



