Authentication Spring安全性:手动验证用户身份

Authentication Spring安全性:手动验证用户身份,authentication,spring-mvc,oauth,spring-security,Authentication,Spring Mvc,Oauth,Spring Security,我试图通过oAuth验证Spring安全应用程序中的用户。我已经收到令牌和用户数据 如何在没有密码和经典登录表单的情况下手动验证用户? 谢谢。类似这样的内容: Authentication authentication = new UsernamePasswordAuthenticationToken(person, null, person.getAuthorities()); log.debug("Logging in with {}", authentication.getPrincip

我试图通过oAuth验证Spring安全应用程序中的用户。我已经收到令牌和用户数据

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

类似这样的内容:

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

其中,
person
是您的UserDetailsBean对象。

请注意,只有当您的登录路径使用以下类型的安全映射时,此操作才有效。在较新版本的spring security中,有一种更好、更快的跳过安全性的方法,例如,
使用新格式时,给定的解决方案将无法正常工作在后面的场景中没有创建SecurityContextHolder。