我尝试通过oAuth在Spring Security应用程序中验证用户身份。我已收到令牌和用户的数据。
如何在没有密码和经典登录表单的情况下手动验证用户身份? 谢谢。
答案 0 :(得分:19)
这样的事情:
Authentication authentication = new UsernamePasswordAuthenticationToken(person, null, person.getAuthorities());
log.debug("Logging in with {}", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication);
其中person
是您的UserDetailsBean对象。