弹簧安全:实施JWT过滤器

发布于 2025-02-09 19:20:18 字数 438 浏览 0 评论 0原文

登陆春季安全确实是一条艰难的道路。

我需要实施身份验证机制,以选择JWT令牌并提取身份验证。

确保我是否使用最佳方法来实施它真的很复杂。

我需要实现和jwtauthenticationFilter

问题:

  • 为什么我需要从basicAuthenticationFilter扩展?那里的所有示例都从它延伸到实现jwtauthenticationfilter!它与基本机制有什么关系?
  • 我也看到了jwtauthorizationfilter。为什么...授权filter而不是... AuthenticationFilter

要实现我的目标的最佳方法是哪种?

Landing on Spring security is really an stucky path.

I need to implement an authentication mechanism in order to pick jwt token and extract authentication.

It's really complicated to be sure whether I'm using best approach in order to implement it.

I need to implement and JWTAuthenticationFilter

Questions:

  • Why do I need to extend from BasicAuthenticationFilter? All exemples over there extends from it to implement a JWTAuthenticationFilter! What does it have to do with BASIC mechanism?
  • Also I saw over there JWTAuthorizationFilter. Why ...AuthorizationFilter instead of ...AuthenticationFilter?

Which is the best approach about to get my goal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅气称霸 2025-02-16 19:20:18

您无需为此提供自定义过滤器,可以使用 spring-security-oauth2-resource-server依赖关系和配置spring boot ,就像这样:

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: https://idp.example.com/issuer

通过这样做,Spring Security将转到Identity提供者并检索JWT键验证请求中提供的令牌。如果您需要自定义行为,则可以覆盖Spring Boot自动configuration,请参见文档

You don't need to provide a custom filter for that, you can use spring-security-oauth2-resource-server dependency and configure Spring Boot, like so:

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: https://idp.example.com/issuer

By doing this, Spring Security will go to the identity provider and retrieve the JWT keys to validate the token provided in the request. If you need to customize the behavior you can override Spring Boot auto-configuration, see the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文