【发布时间】:2018-11-04 08:56:54
【问题描述】:
比较将用户身份保存到会话并使用拦截器进行授权。
喜欢:
认证:
@RequestMapping("/checkLogin.do")
public String checkLogin(Map map, HttpSession httpSession, String username, String password) {
JSONObject userJson = userService.checkLogin(username, password);
if ((Integer) userJson.get("success") == 0) {
httpSession.setAttribute("userinfo", userJson);
return "redirect:/index.do";
} else {
map.put("error", -1);
return "login";
}
授权:
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse arg1, Object arg2) throws Exception {
String requestURI = request.getRequestURI();
HttpSession session = request.getSession();
String userinfo= (String) session.getAttribute("userinfo");
if (userinfo!= null) {
return true;
} else {
arg1.sendRedirect("/login.do");
return false;
}
}
使用 shiro 或 spring-security 等安全框架有什么好处?
【问题讨论】:
标签: spring-security shiro