Class FileTokenStore
java.lang.Object
cloud.opencode.base.oauth2.token.FileTokenStore
- All Implemented Interfaces:
TokenStore
File-based Token Store
文件 Token 存储
Persistent file-based implementation of TokenStore.
TokenStore 的持久化文件实现。
Features | 主要功能:
- Persistent storage - 持久化存储
- Simple JSON format - 简单 JSON 格式
- Automatic directory creation - 自动创建目录
Usage Examples | 使用示例:
TokenStore store = new FileTokenStore(Path.of(".tokens"));
// Save token
store.save("user-1", token);
// Load token
Optional<OAuth2Token> loaded = store.load("user-1");
File Format | 文件格式:
Tokens are stored as simple property files for easy debugging.
令牌以简单的属性文件格式存储,便于调试。
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: Yes (validates inputs) - 空值安全: 是(验证输入)
- Since:
- JDK 25, opencode-base-oauth2 V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete a token by key 通过键删除令牌voidDelete all stored tokens 删除所有存储的令牌keys()Get all stored keys 获取所有存储的键Load a token by key 通过键加载令牌voidsave(String key, OAuth2Token token) Save a token with the given key 使用给定的键保存令牌Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TokenStore
exists, size
-
Constructor Details
-
FileTokenStore
Create a new file token store 创建新的文件令牌存储- Parameters:
directory- the storage directory | 存储目录- Throws:
OAuth2Exception- if directory creation fails | 如果目录创建失败
-
-
Method Details
-
save
Description copied from interface:TokenStoreSave a token with the given key 使用给定的键保存令牌- Specified by:
savein interfaceTokenStore- Parameters:
key- the storage key | 存储键token- the token to save | 要保存的令牌
-
load
Description copied from interface:TokenStoreLoad a token by key 通过键加载令牌- Specified by:
loadin interfaceTokenStore- Parameters:
key- the storage key | 存储键- Returns:
- the token if found | 找到的令牌
-
delete
Description copied from interface:TokenStoreDelete a token by key 通过键删除令牌- Specified by:
deletein interfaceTokenStore- Parameters:
key- the storage key | 存储键
-
deleteAll
public void deleteAll()Description copied from interface:TokenStoreDelete all stored tokens 删除所有存储的令牌- Specified by:
deleteAllin interfaceTokenStore
-
keys
Description copied from interface:TokenStoreGet all stored keys 获取所有存储的键- Specified by:
keysin interfaceTokenStore- Returns:
- the set of keys | 键集合
-