【问题标题】:SecurityContextHolder.getContext (). GetAuthentication (). GetPrincipal () can only get the usernameSecurityContextHolder.getContext()。获取身份验证()。 GetPrincipal() 只能获取用户名
【发布时间】:2019-12-10 03:33:14
【问题描述】:

SecurityContextHolder.getContext()。获取身份验证()。 GetPrincipal() 只能获取用户名, 我其实想得到一个用户对象。

【问题讨论】:

  • @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) { endpoints.allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST) .tokenStore(tokenStore()) .tokenEnhancer(tokenEnhancer()) .userDetailsS​​ervice(userDetailsS​​ervice) 。 authenticationManager(authenticationManager) .reuseRefreshTokens(false) .exceptionTranslator(new GzsWebResponseExceptionTranslator()); }
  • 如果你得到用户名,那么你可以检索用户对象。

标签: spring spring-security-oauth2


【解决方案1】:

是的,这是正确的。您必须使用户名字段唯一。然后,您将能够在存储库中创建一个方法,该方法允许您通过用户名恢复用户。在那里你可以得到你需要的字段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多