【问题标题】:Authenticate User manually手动验证用户
【发布时间】:2011-01-28 19:23:19
【问题描述】:

在使用 oAuth 获得凭据后,我正在尝试对用户进行身份验证(如果有影响,则使用 Twitter)。据我了解,我可以直接将Authentication对象放入SecurityContextHolder。这是我的做法:

Authentication auth = new TwitterOAuthAuthentication(member,
userDetailsService.loadUserByUsername(member.getUsername()).getAuthorities());
SecurityContextHolder.getContext().setAuthentication(auth);

出于某种原因,这完全没有任何作用。我缺少什么,我应该怎么做才能完成什么需求?

【问题讨论】:

    标签: spring-security


    【解决方案1】:

    尝试添加

    auth.setAuthenticated(true);
    

    在将身份验证设置为上下文之前。

    以下代码对我来说很好用(在过滤器类中):

    final Authentication auth = new CustomAuthenticationToken(user);
    auth.setAuthenticated(true);
    SecurityContextHolder.getContext().setAuthentication(auth);
    

    【讨论】:

      猜你喜欢
      • 2012-04-14
      • 2014-08-10
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多