如何清除angularjs中的全局cookie

时间:2016-11-22 14:01:35

标签: angularjs spring-security

我正在使用具有弹簧安全性的angularjs 我的app.js中有以下代码

     function run($rootScope, $location, $cookieStore, $http) {
            // keep user logged in after page refresh
            $rootScope.globals = $cookieStore.get('globals') || {};
            if ($rootScope.globals.currentUser) {
                $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
            }
     }

当我按下退出时,我必须删除当前用户 $ rootScope.globals.currentUser ,以便应用程序正常工作

我该怎么做 我试图用java代码删除它

@RequestMapping(value = "/logout", method = RequestMethod.GET)
    public String logout(HttpServletRequest request, HttpServletResponse response) {

        HttpSession session= request.getSession(false);
        SecurityContextHolder.clearContext();
             session= request.getSession(false);
            if(session != null) {
                session.invalidate();
            }
            for(Cookie cookie : request.getCookies()) {
                cookie.setMaxAge(0);
            }
        return "redirect:/j_spring_security_logout";
    }
but It didn't work

1 个答案:

答案 0 :(得分:0)

您可以使用angular $ cookies服务并将其删除,如下所示:

$cookies.remove('coockieName');