package ru.hflabs.rcd.web.handler; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * Класс <class>AjaxAwareLoginUrlAuthenticationEntryPoint</class> реализует точку входа аутентификации для AJAX запросов * * @see org.springframework.security.web.AuthenticationEntryPoint */ public class AjaxAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint { public AjaxAuthenticationEntryPoint(String loginFormUrl) { super(loginFormUrl); } @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { String xRequestedWith = request.getHeader("x-requested-with"); if ("XMLHttpRequest".equals(xRequestedWith) && authException != null) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { super.commence(request, response, authException); } } }