Class UserListStrategy

java.lang.Object
cloud.opencode.base.feature.strategy.UserListStrategy
All Implemented Interfaces:
EnableStrategy

public class UserListStrategy extends Object implements EnableStrategy
User List Strategy 用户列表策略

Strategy that enables feature for specific users.

为特定用户启用功能的策略。

Features | 主要功能:

  • User whitelist - 用户白名单
  • Beta user targeting - Beta用户定向
  • VIP user features - VIP用户功能

Usage Examples | 使用示例:

// Using builder shortcut
Feature feature = Feature.builder("beta-feature")
    .forUsers("user1", "user2", "user3")
    .build();

// Using strategy directly
Feature feature = Feature.builder("vip-feature")
    .strategy(new UserListStrategy(Set.of("vip1", "vip2")))
    .build();

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

    • UserListStrategy

      public UserListStrategy(Set<String> allowedUsers)
      Create user list strategy 创建用户列表策略
      Parameters:
      allowedUsers - the set of allowed user IDs | 允许的用户ID集合
  • Method Details

    • isEnabled

      public boolean isEnabled(Feature feature, FeatureContext context)
      Check if user is in the allowed list 检查用户是否在允许列表中
      Specified by:
      isEnabled in interface EnableStrategy
      Parameters:
      feature - the feature | 功能
      context - the context | 上下文
      Returns:
      true if user is allowed | 如果用户被允许返回true
    • getAllowedUsers

      public Set<String> getAllowedUsers()
      Get the set of allowed users 获取允许的用户集合
      Returns:
      allowed users | 允许的用户
    • isUserAllowed

      public boolean isUserAllowed(String userId)
      Check if a specific user is allowed 检查特定用户是否被允许
      Parameters:
      userId - the user ID | 用户ID
      Returns:
      true if allowed | 如果允许返回true
    • toString

      public String toString()
      Overrides:
      toString in class Object