【问题标题】:Spring OAuth2 client_credentials in combination with preauthenticated userSpring OAuth2 client_credentials 结合预认证用户
【发布时间】:2015-05-10 14:10:37
【问题描述】:

我的应用使用preauthentication

我想使用 ClientCredentialsResourceDetails(签名获取)来使用受 OAuth2 保护的资源。

当将它与预认证的UserDetails 结合使用时,spring 不会存储 OAuth 令牌:

DEBUG o.s.s.w.a.AnonymousAuthenticationFilter - SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken@4662f11e: Principal: User = ***

我怎样才能做到这一点?

【问题讨论】:

  • 我还没收到问题,抱歉。如果您已通过容器进行了预身份验证,为什么需要 OAuth2,您希望令牌存储在哪里?
  • 我想使用一个使用 OAuth2 和 client_credentials 的 api。为下一个请求存储令牌以节省时间不是最好吗?

标签: java spring-mvc spring-security spring-boot spring-security-oauth2


【解决方案1】:

令牌存储在内存中的OAuth2RestTemplate 中。这对于大多数用例来说已经足够了,因为您可以将其设置为单例 bean(每个客户端一个)。

【讨论】:

    猜你喜欢
    • 2021-11-11
    • 2015-11-27
    • 2015-03-11
    • 2017-03-17
    • 2019-09-17
    • 2020-05-26
    • 2016-07-14
    • 2018-09-04
    • 2018-10-04
    相关资源
    最近更新 更多