Interface TokenStore
- All Known Implementing Classes:
FileTokenStore, InMemoryTokenStore
public interface TokenStore
Token Store Interface
Token 存储接口
Defines the contract for storing and retrieving OAuth2 tokens.
定义存储和检索 OAuth2 令牌的契约。
Implementations | 实现:
InMemoryTokenStore- Memory storage - 内存存储FileTokenStore- File-based storage - 文件存储
Usage Examples | 使用示例:
// Use in-memory store
TokenStore store = new InMemoryTokenStore();
store.save("user-1", token);
// Retrieve token
Optional<OAuth2Token> token = store.load("user-1");
// Custom implementation
TokenStore redisStore = new TokenStore() {
@Override
public void save(String key, OAuth2Token token) {
redis.set("oauth2:" + key, serialize(token));
}
// ... other methods
};
Features | 主要功能:
- SPI for OAuth2 token persistence - OAuth2令牌持久化的SPI接口
- Pluggable storage backend support - 可插拔的存储后端支持
Security | 安全性:
- Thread-safe: Implementation-dependent - 线程安全: 取决于实现
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-oauth2 V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidDelete a token by key 通过键删除令牌voidDelete all stored tokens 删除所有存储的令牌default booleanCheck if a token exists 检查令牌是否存在keys()Get all stored keys 获取所有存储的键Load a token by key 通过键加载令牌voidsave(String key, OAuth2Token token) Save a token with the given key 使用给定的键保存令牌default intsize()Get the number of stored tokens 获取存储的令牌数量
-
Method Details
-
save
Save a token with the given key 使用给定的键保存令牌- Parameters:
key- the storage key | 存储键token- the token to save | 要保存的令牌
-
load
Load a token by key 通过键加载令牌- Parameters:
key- the storage key | 存储键- Returns:
- the token if found | 找到的令牌
-
delete
-
deleteAll
void deleteAll()Delete all stored tokens 删除所有存储的令牌 -
exists
Check if a token exists 检查令牌是否存在- Parameters:
key- the storage key | 存储键- Returns:
- true if exists | 存在返回 true
-
keys
-
size
default int size()Get the number of stored tokens 获取存储的令牌数量- Returns:
- the count | 数量
-