Spring Security:手动验证用户

时间:2012-03-30 11:07:40

标签: authentication spring-mvc oauth spring-security

我尝试通过oAuth在Spring Security应用程序中验证用户身份。我已收到令牌和用户的数据。

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

1 个答案:

答案 0 :(得分:19)

这样的事情:

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

其中person是您的UserDetailsBean对象。