Class SecureFeatureManager

java.lang.Object
cloud.opencode.base.feature.security.SecureFeatureManager

public class SecureFeatureManager extends Object
Secure Feature Manager 安全功能管理器

Feature manager with permission control and audit logging.

带有权限控制和审计日志的功能管理器。

Features | 主要功能:

  • Permission control - 权限控制
  • Admin whitelist - 管理员白名单
  • Audit logging - 审计日志

Usage Examples | 使用示例:

SecureFeatureManager manager = new SecureFeatureManager(
    Set.of("admin1", "admin2"),
    new FileAuditLogger(logPath)
);

manager.enable("new-feature", "admin1"); // OK
manager.enable("new-feature", "user1");  // throws FeatureSecurityException

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
Since:
JDK 25, opencode-base-feature V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • SecureFeatureManager

      public SecureFeatureManager(Set<String> adminUsers, AuditLogger auditLogger)
      Create secure feature manager 创建安全功能管理器
      Parameters:
      adminUsers - the set of admin user IDs | 管理员用户ID集合
      auditLogger - the audit logger | 审计日志记录器
    • SecureFeatureManager

      public SecureFeatureManager(OpenFeature features, Set<String> adminUsers, AuditLogger auditLogger)
      Create with custom OpenFeature instance 使用自定义OpenFeature实例创建
      Parameters:
      features - the OpenFeature instance | OpenFeature实例
      adminUsers - the set of admin user IDs | 管理员用户ID集合
      auditLogger - the audit logger | 审计日志记录器
  • Method Details

    • register

      public void register(Feature feature, String operatorId)
      Register a feature (requires admin) 注册功能(需要管理员)
      Parameters:
      feature - the feature to register | 要注册的功能
      operatorId - the operator ID | 操作者ID
      Throws:
      FeatureSecurityException - if not authorized | 如果未授权
    • enable

      public void enable(String featureKey, String operatorId)
      Enable a feature (requires admin) 启用功能(需要管理员)
      Parameters:
      featureKey - the feature key | 功能键
      operatorId - the operator ID | 操作者ID
      Throws:
      FeatureSecurityException - if not authorized | 如果未授权
    • disable

      public void disable(String featureKey, String operatorId)
      Disable a feature (requires admin) 禁用功能(需要管理员)
      Parameters:
      featureKey - the feature key | 功能键
      operatorId - the operator ID | 操作者ID
      Throws:
      FeatureSecurityException - if not authorized | 如果未授权
    • updateStrategy

      public void updateStrategy(String featureKey, EnableStrategy strategy, String operatorId)
      Update feature strategy (requires admin) 更新功能策略(需要管理员)
      Parameters:
      featureKey - the feature key | 功能键
      strategy - the new strategy | 新策略
      operatorId - the operator ID | 操作者ID
      Throws:
      FeatureSecurityException - if not authorized | 如果未授权
    • isEnabled

      public boolean isEnabled(String featureKey)
      Check if feature is enabled (no permission required) 检查功能是否启用(无需权限)
      Parameters:
      featureKey - the feature key | 功能键
      Returns:
      true if enabled | 如果启用返回true
    • isEnabled

      public boolean isEnabled(String featureKey, FeatureContext context)
      Check if feature is enabled for context (no permission required) 检查功能对上下文是否启用(无需权限)
      Parameters:
      featureKey - the feature key | 功能键
      context - the context | 上下文
      Returns:
      true if enabled | 如果启用返回true
    • get

      public Optional<Feature> get(String featureKey)
      Get a feature (no permission required) 获取功能(无需权限)
      Parameters:
      featureKey - the feature key | 功能键
      Returns:
      optional containing feature | 包含功能的Optional
    • isAdmin

      public boolean isAdmin(String operatorId)
      Check if operator is admin 检查操作者是否为管理员
      Parameters:
      operatorId - the operator ID | 操作者ID
      Returns:
      true if admin | 如果是管理员返回true