Class PasswordScopedValue

java.lang.Object
com.codeupsoft.component.security.context.PasswordScopedValue

public class PasswordScopedValue extends Object
密码作用域值工具类.

提供线程安全的密码存储机制,确保密码在特定作用域内使用, 避免密码在内存中长时间暴露.

Author:
Liu,Dongdong
  • Constructor Details

    • PasswordScopedValue

      public PasswordScopedValue()
  • Method Details

    • isBound

      public static boolean isBound()
      检查当前作用域是否已设置密码.
      Returns:
      如果已设置返回 true,否则返回 false
    • runWithPassword

      public static void runWithPassword(String password, Runnable runnable)
      在指定密码的作用域内执行操作.
      Parameters:
      password - 密码
      runnable - 要执行的操作
    • get

      public static String get()
      获取当前线程作用域内的密码.
      Returns:
      密码,如果未设置则返回 null
    • callWithPassword

      public static <T> T callWithPassword(String password, PasswordScopedValue.CallableOp<T> callable)
      在指定密码的作用域内执行操作并返回结果.

      注意:由于ScopedValue.call()的类型约束,此方法仅能抛出RuntimeException. 如果需要抛出检查型异常,请在callable内部将其包装为RuntimeException.

      Type Parameters:
      T - 返回值类型
      Parameters:
      password - 密码
      callable - 要执行的操作
      Returns:
      操作结果