【问题标题】:Spring Security remember me logout issueSpring Security 记住我注销问题
【发布时间】:2016-10-28 15:49:40
【问题描述】:

remember me 有问题。我已经使用 PersistentTokenRepository 实现了它。一切正常,除了注销。

登录后,在数据库中创建新记录,用户有记住我的cookie。

删除会话cookie后,用户获取新cookie,更新DB中的旧记录。

/logout 之后,logout 方法没有被调用(来自 PersistentTokenBasedRememberMeServices,我通过扩展类和日志记录检查了它)。如何将其添加到注销过滤器或类似的东西?我检查了源和logout 方法调用从数据库中删除记录并删除co​​okie,所以我只需要调用它。 我正在使用 java 配置。

安全性:

http.csrf();
http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/test").hasRole("USER")
    .antMatchers("/made/administration/**").hasRole("ADMIN");
http.formLogin().loginPage("/login").usernameParameter("email").passwordParameter("password");
http.logout().logoutUrl("/logout").logoutSuccessUrl("/login?logout");
http.exceptionHandling().accessDeniedPage("/access-denied");
http.rememberMe().tokenRepository(persistentTokenRepository)
    .tokenValiditySeconds(rememberMeValidSeconds);

【问题讨论】:

    标签: java spring spring-mvc cookies spring-security


    【解决方案1】:

    问题解决了。我不得不更改控制器,因为我使用的是 csrf - 通过 POST(而不是 GET)注销。

    所以我删除了:

    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public String logoutPage(HttpServletRequest request, HttpServletResponse response) {
      Authentication auth = SecurityContextHolder.getContext().getAuthentication();
      if (auth != null) {
        new SecurityContextLogoutHandler().logout(request, response, auth);
      }
      return "redirect:/login?logout";
    }
    

    并将表单添加到 POST /logout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-22
      • 2011-01-28
      • 2011-03-09
      • 2011-03-05
      • 1970-01-01
      • 2015-05-10
      • 2011-01-28
      相关资源
      最近更新 更多