00【笔记】 Shiro登陆过滤提示信息
作者:互联网
Shiro登陆过滤 提示信息
package top.yangbuyi.system.shiro;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
/**
* ClassName: ShiroLoginFilter
* Description: 杨不易网站 :www.yangbuyi.top
* date: 2020/4/14 20:38
*
* @author TeouBle
* @author yangbuyi
* @since JDK 1.8
* 登陆 进行认证后 输出提示语句
*/
public class ShiroLoginFilter extends FormAuthenticationFilter {
/**
* 当用户访问未登陆资源时,会走的方法。
* 返回true代表已登陆,不用处理
* 返回false代表未登陆。提示前端
*/
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
Map<String,Object> resultData = new HashMap<>();
resultData.put("code", -1);
resultData.put("msg", "杨不易提示您:登录认证失效,请重新登录!");
PrintWriter out= response.getWriter();
//使用fastjson的对象转化方法
out.write(JSONObject.toJSON(resultData).toString());
return false;
}
}
标签:00,java,resultData,yangbuyi,登陆,提示信息,import,response,Shiro 来源: https://www.cnblogs.com/Yangbuyi/p/13153326.html