如何在Spring Security中撤消身份验证令牌? [英] How to revoke auth token in spring security?

查看:817
本文介绍了如何在Spring Security中撤消身份验证令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在注销控制器中,我尝试编写许多代码组合.现在我有了这个:

In logout controller I tryed to write a lot of combination of code. Now I have this:

final Authentication auth = SecurityContextHolder.getContext().getAuthentication();

if (auth != null) {
    new SecurityContextLogoutHandler().logout(request, response, auth);
}

SecurityContextHolder.getContext().setAuthentication(null);
auth.setAuthenticated(false);

但是在提供的代码执行令牌之后,令牌仍然有效.

But after provided code execution token still valid.

我怎么了?最终如何撤销令牌?

What do I wrong? How to revoke token eventually?

推荐答案

您要查找的类是 DefaultServices ,方法revokeToken(String tokenValue).

此处撤销令牌的控制器的示例,并且此处使用DefaultServices bean的oauth2配置.

Here an exemple of a controller that revokes token, and here the oauth2 configuration with the DefaultServices bean.

这篇关于如何在Spring Security中撤消身份验证令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆