//
// Source code recreated from a .class file by IntelliJ IDEA
package com.fjs.scenic.handler;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

@Component
public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler {
	public MyAuthenticationFailureHandler() {
	}

	public void onAuthenticationFailure(HttpServletRequest req, HttpServletResponse res, AuthenticationException auth) throws IOException, ServletException {
		String strUrl = req.getContextPath() + "/login";
		req.getSession().setAttribute("status", 0);
		req.getSession().setAttribute("message", auth.getLocalizedMessage());
		String msg = (String)req.getSession().getAttribute("msg");
		if (msg == null || "".equals(msg)) {
			req.getSession().setAttribute("msg", "用户名密码错误。请重新输入");
		}

		req.getSession().setAttribute("SPRING_SECURITY_LAST_EXCEPTION", auth);
		res.sendRedirect(strUrl);
	}
}
