我试图通过oAuth在Spring Security应用程序中对用户进行身份验证。我已经收到 token 和用户的数据。

如何在没有密码和经典登录表单的情况下手动验证用户身份?
谢谢你。

最佳答案

像这样的东西:

Authentication authentication =  new UsernamePasswordAuthenticationToken(person, null, person.getAuthorities());
log.debug("Logging in with {}", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication);

其中person是您的UserDetailsBean对象。

关于authentication - Spring 安全: Authentication user manually,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9941773/

10-12 17:32