【问题标题】:what's the advantage of java security framework?java安全框架的优势是什么?
【发布时间】: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


    【解决方案1】:

    简而言之,好处在于您能以多快的速度将安全相关要求纳入您的项目;基本的安全要求可能是权限管理和基于角色的授权,而更复杂的要求可能是跨平台会话管理。

    【讨论】:

      猜你喜欢
      • 2016-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 2020-05-06
      相关资源
      最近更新 更多