// Path: ssopay-qywx-bean/src/main/java/com/ssopay/qywx/base/Result.java
// public class Result implements Serializable {
// 	private static final long serialVersionUID = 1L;
// 	
// 	private Integer code = -1;
// 	private String msg;
// 	private String url;
// 	private Long time = new Date().getTime();
// 	private List<ResultMap> data;
// 	public Integer getCode() {
// 		return code;
// 	}
// 	public void setCode(Integer code) {
// 		this.code = code;
// 	}
// 	public String getMsg() {
// 		return msg;
// 	}
// 	public void setMsg(String msg) {
// 		this.msg = msg;
// 	}
// 	public String getUrl() {
// 		return url;
// 	}
// 	public void setUrl(String url) {
// 		this.url = url;
// 	}
// 	public Long getTime() {
// 		return time;
// 	}
// 	public void setTime(Long time) {
// 		this.time = time;
// 	}
// 	public List<ResultMap> getData() {
// 		return data;
// 	}
// 	public void setData(List<ResultMap> data) {
// 		this.data = data;
// 	}
// 
// }
// 
// Path: ssopay-qywx-admin/src/main/java/com/ssopay/qywx/jcaptcha/JCaptchaServiceSingleton.java
// public class JCaptchaServiceSingleton {
// 
// 	private static ImageCaptchaService instance = null;
// 
// 	private JCaptchaServiceSingleton() {
// 	}
// 
// 	// 使用synchronized关键字解决线程不安全
// 	public synchronized static ImageCaptchaService getInstance() {
// 		if (instance == null) {
// 			instance = new DefaultManageableImageCaptchaService(
// 					new FastHashMapCaptchaStore(), new GMailEngine(), 180,
// 					100000, 75000);
// 		}
// 		return instance;
// 	}
// 
// }


import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ssopay.qywx.base.Result;
import com.ssopay.qywx.jcaptcha.JCaptchaServiceSingleton;
	@ResponseBody
	public Result fail(String username, HttpServletRequest request) {
		Result result = new Result();
		Object obj = request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
		String msg = "";
		if(obj != null){
			if("captcha.error".equals(obj))
				msg = "，验证码错误";
			else if("org.apache.shiro.authc.UnknownAccountException".equals(obj))
				msg = "，帐号或密码错误";
			else if("org.apache.shiro.authc.IncorrectCredentialsException".equals(obj))
				msg = "，帐号或密码错误";
			else if("org.apache.shiro.authc.AuthenticationException".equals(obj))
				msg = "，认证失败，请重试";
        }
		result.setMsg(username + "登录失败" + msg);
		return result;
	}
	

	@RequestMapping("code")
	public void code(HttpServletResponse response, HttpServletRequest request) throws Exception{
		response.setHeader("Cache-Control", "no-store");
		response.setHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
		ServletOutputStream sos = null;
		try {
			sos = response.getOutputStream();
			String sid = request.getRequestedSessionId();
// Path: ssopay-qywx-bean/src/main/java/com/ssopay/qywx/base/Result.java
// public class Result implements Serializable {
// 	private static final long serialVersionUID = 1L;
// 	
// 	private Integer code = -1;
// 	private String msg;
// 	private String url;
// 	private Long time = new Date().getTime();
// 	private List<ResultMap> data;
// 	public Integer getCode() {
// 		return code;
// 	}
// 	public void setCode(Integer code) {
// 		this.code = code;
// 	}
// 	public String getMsg() {
// 		return msg;
// 	}
// 	public void setMsg(String msg) {
// 		this.msg = msg;
// 	}
// 	public String getUrl() {
// 		return url;
// 	}
// 	public void setUrl(String url) {
// 		this.url = url;
// 	}
// 	public Long getTime() {
// 		return time;
// 	}
// 	public void setTime(Long time) {
// 		this.time = time;
// 	}
// 	public List<ResultMap> getData() {
// 		return data;
// 	}
// 	public void setData(List<ResultMap> data) {
// 		this.data = data;
// 	}
// 
// }
// 
// Path: ssopay-qywx-admin/src/main/java/com/ssopay/qywx/jcaptcha/JCaptchaServiceSingleton.java
// public class JCaptchaServiceSingleton {
// 
// 	private static ImageCaptchaService instance = null;
// 
// 	private JCaptchaServiceSingleton() {
// 	}
// 
// 	// 使用synchronized关键字解决线程不安全
// 	public synchronized static ImageCaptchaService getInstance() {
// 		if (instance == null) {
// 			instance = new DefaultManageableImageCaptchaService(
// 					new FastHashMapCaptchaStore(), new GMailEngine(), 180,
// 					100000, 75000);
// 		}
// 		return instance;
// 	}
// 
// }


// Path: ssopay-qywx-admin/src/main/java/com/ssopay/qywx/login/web/LoginController.java
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ssopay.qywx.base.Result;
import com.ssopay.qywx.jcaptcha.JCaptchaServiceSingleton;

	@ResponseBody
	public Result fail(String username, HttpServletRequest request) {
		Result result = new Result();
		Object obj = request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
		String msg = "";
		if(obj != null){
			if("captcha.error".equals(obj))
				msg = "，验证码错误";
			else if("org.apache.shiro.authc.UnknownAccountException".equals(obj))
				msg = "，帐号或密码错误";
			else if("org.apache.shiro.authc.IncorrectCredentialsException".equals(obj))
				msg = "，帐号或密码错误";
			else if("org.apache.shiro.authc.AuthenticationException".equals(obj))
				msg = "，认证失败，请重试";
        }
		result.setMsg(username + "登录失败" + msg);
		return result;
	}
	

	@RequestMapping("code")
	public void code(HttpServletResponse response, HttpServletRequest request) throws Exception{
		response.setHeader("Cache-Control", "no-store");
		response.setHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
		ServletOutputStream sos = null;
		try {
			sos = response.getOutputStream();
			String sid = request.getRequestedSessionId();
			BufferedImage challenge = JCaptchaServiceSingleton.getInstance().getImageChallengeForID(sid);