Class FileTokenStore

java.lang.Object
cloud.opencode.base.oauth2.token.FileTokenStore
All Implemented Interfaces:
TokenStore

public class FileTokenStore extends Object implements 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 Details

    • FileTokenStore

      public FileTokenStore(Path directory)
      Create a new file token store 创建新的文件令牌存储
      Parameters:
      directory - the storage directory | 存储目录
      Throws:
      OAuth2Exception - if directory creation fails | 如果目录创建失败
  • Method Details

    • save

      public void save(String key, OAuth2Token token)
      Description copied from interface: TokenStore
      Save a token with the given key 使用给定的键保存令牌
      Specified by:
      save in interface TokenStore
      Parameters:
      key - the storage key | 存储键
      token - the token to save | 要保存的令牌
    • load

      public Optional<OAuth2Token> load(String key)
      Description copied from interface: TokenStore
      Load a token by key 通过键加载令牌
      Specified by:
      load in interface TokenStore
      Parameters:
      key - the storage key | 存储键
      Returns:
      the token if found | 找到的令牌
    • delete

      public void delete(String key)
      Description copied from interface: TokenStore
      Delete a token by key 通过键删除令牌
      Specified by:
      delete in interface TokenStore
      Parameters:
      key - the storage key | 存储键
    • deleteAll

      public void deleteAll()
      Description copied from interface: TokenStore
      Delete all stored tokens 删除所有存储的令牌
      Specified by:
      deleteAll in interface TokenStore
    • keys

      public Set<String> keys()
      Description copied from interface: TokenStore
      Get all stored keys 获取所有存储的键
      Specified by:
      keys in interface TokenStore
      Returns:
      the set of keys | 键集合