Class JwtAuth

java.lang.Object
io.github.xezzon.zeroweb.auth.JwtAuth

public class JwtAuth extends Object
JWT 认证工具类,用于管理和获取当前线程的 JWT 认证信息。 支持从 ScopedValue 和 gRPC Context 中获取认证数据。
Author:
xezzon
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ScopedValue<io.github.xezzon.zeroweb.auth.JwtClaim>
    ScopedValue 用于在当前线程范围内存储 JWT 认证信息。
    static final io.grpc.Context.Key<io.github.xezzon.zeroweb.auth.JwtClaim>
    gRPC Context.Key 用于在 gRPC 请求上下文中存储 JWT 认证信息。
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NonNull Optional<io.github.xezzon.zeroweb.auth.JwtClaim>
    get()
    获取当前线程的 JWT 认证信息。
    static @NonNull io.github.xezzon.zeroweb.auth.JwtClaim
    获取当前线程的 JWT 认证信息,如果不存在则抛出异常。

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CLAIM

      public static final ScopedValue<io.github.xezzon.zeroweb.auth.JwtClaim> CLAIM
      ScopedValue 用于在当前线程范围内存储 JWT 认证信息。
    • CONTEXT

      public static final io.grpc.Context.Key<io.github.xezzon.zeroweb.auth.JwtClaim> CONTEXT
      gRPC Context.Key 用于在 gRPC 请求上下文中存储 JWT 认证信息。
  • Method Details

    • get

      public static @NonNull Optional<io.github.xezzon.zeroweb.auth.JwtClaim> get()
      获取当前线程的 JWT 认证信息。 优先从 gRPC Context 中获取,如果不存在,则从 ScopedValue 中获取。 如果两种方式都未获取到,则返回 Optional.empty()
      Returns:
      包含 JWT 认证信息的 Optional 对象,如果不存在则为 empty。
    • getOrThrow

      public static @NonNull io.github.xezzon.zeroweb.auth.JwtClaim getOrThrow()
      获取当前线程的 JWT 认证信息,如果不存在则抛出异常。 优先从 gRPC Context 中获取,如果不存在,则从 ScopedValue 中获取。
      Returns:
      JWT 认证信息。
      Throws:
      cn.dev33.satoken.exception.NotLoginException - 如果当前线程没有认证信息。