该线程有点旧,但对于 JWTToken 用户来说,这不起作用,因为没有存储令牌。所以另一种选择是使用过滤器。1 为管理员创建一种方法来锁定/解锁数据库上的用户。2 使用过滤器,如果方法需要身份验证,检查用户是否处于活动状态
例子:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication != null
&& authentication.getName() != null
&& !authentication.getName().equalsIgnoreCase("anonymousUser")) {
UserModel user = userService.getUser(authentication.getName());
if(user != null && !user.isActivated())
throw new SecurityException("SECURITY_USER_DISABLED");
}
chain.doFilter(request, response);
}
在客户端,只需拦截此错误并断开用户连接,希望这对某人有所帮助。