Class PasswordScopedValue
java.lang.Object
com.codeupsoft.component.security.context.PasswordScopedValue
密码作用域值工具类.
提供线程安全的密码存储机制,确保密码在特定作用域内使用, 避免密码在内存中长时间暴露.
- Author:
- Liu,Dongdong
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface函数式接口,用于执行可能抛出异常的操作. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcallWithPassword(String password, PasswordScopedValue.CallableOp<T> callable) 在指定密码的作用域内执行操作并返回结果.static Stringget()获取当前线程作用域内的密码.static booleanisBound()检查当前作用域是否已设置密码.static voidrunWithPassword(String password, Runnable runnable) 在指定密码的作用域内执行操作.
-
Constructor Details
-
PasswordScopedValue
public PasswordScopedValue()
-
-
Method Details
-
isBound
public static boolean isBound()检查当前作用域是否已设置密码.- Returns:
- 如果已设置返回 true,否则返回 false
-
runWithPassword
-
get
-
callWithPassword
在指定密码的作用域内执行操作并返回结果.注意:由于ScopedValue.call()的类型约束,此方法仅能抛出RuntimeException. 如果需要抛出检查型异常,请在callable内部将其包装为RuntimeException.
- Type Parameters:
T- 返回值类型- Parameters:
password- 密码callable- 要执行的操作- Returns:
- 操作结果
-