【问题标题】:clear cookies while logout in spring security or in angular在春季安全或角度注销时清除cookie
【发布时间】:2016-09-09 21:21:18
【问题描述】:

我的删除 cookie 的试用代码

.logout()
.logoutUrl("/access/logout")
.logoutSuccessHandler(new LogoutSuccessHandler() {
 @Override
public void onLogoutSuccess(
HttpServletRequest request,
HttpServletResponse response,
Authentication a) throws IOException, ServletException {
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
  }
})
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)

这是HttpSecurity的注销安全代码
在这里我遇到了删除 cookie 的问题
logoutSuccessHandler 在记录器中它显示 cookies = 1 并且即 JESSESIONID
所以我的问题是如何在注销时删除 cookie
或者如果有任何其他方式或任何角度的方式那么请告诉我

【问题讨论】:

  • 使http会话失效就足够了。在此之后 JSESSION_ID 不再有效。我你真的想删除它,你可能想在客户端使用 $cookies 角度服务,但只有在服务器端取消会话之后
  • 好的,如果我想在 angularJs 端清除它,我应该怎么做
  • 贴出注销涉及的ng代码。

标签: angularjs spring cookies spring-security


【解决方案1】:

在浏览了很多关于spring security的博客后,我得到了答案,

.invalidateHttpSession(true) :- 用于清除我们的会话

.deleteCookies("JSESSIONID") :- 用于删除 cookie

在成功处理程序之后使用它,以便在注销后删除所有 cookie

编辑

如果有人想从前端处理 cookie,那么您可以在 AngularJs 中使用 ng-cookies 处理它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-19
    • 2015-10-02
    • 2011-11-11
    • 2016-06-09
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    • 2015-11-09
    相关资源
    最近更新 更多