Class AllowList
java.lang.Object
cloud.opencode.base.expression.sandbox.AllowList
Allow List
白名单
A flexible whitelist for controlling access to classes, methods, and properties. Supports exact matches and wildcard patterns.
用于控制对类、方法和属性访问的灵活白名单。支持精确匹配和通配符模式。
Usage | 用法
AllowList allowList = AllowList.builder()
.allowClass("java.lang.String")
.allowClass("java.util.*") // All classes in java.util
.allowMethod("get*") // All methods starting with "get"
.allowProperty("name")
.build();
Features | 主要功能:
- Exact match and wildcard pattern support for classes, methods, properties - 类、方法、属性的精确匹配和通配符模式支持
- Configurable default allow/deny policy - 可配置的默认允许/拒绝策略
- Immutable after construction - 构造后不可变
- Factory methods for empty and allow-all lists - 空列表和允许所有列表的工厂方法
Security | 安全性:
- Thread-safe: Yes, immutable after construction with defensive copies - 线程安全: 是,构造后不可变,使用防御性拷贝
- Null-safe: Yes, null names return false - 空值安全: 是,null名称返回false
Usage Examples | 使用示例:
AllowList allowList = AllowList.builder()
.allowClass("java.lang.String")
.allowClass("java.util.*")
.allowMethod("get*")
.allowProperty("name")
.build();
boolean allowed = allowList.isClassAllowed("java.lang.String"); // true
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for AllowList AllowList 构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic AllowListallowAll()Create an allow-all list (allows everything) 创建允许所有的白名单static AllowList.Builderbuilder()Create a builder 创建构建器static AllowListempty()Create an empty allow list (denies all) 创建空白名单(拒绝所有)Get all allowed classes 获取所有允许的类Get all allowed methods 获取所有允许的方法Get all allowed properties 获取所有允许的属性booleanisClassAllowed(Class<?> clazz) Check if class is allowed 检查类是否被允许booleanisClassAllowed(String className) Check if class is allowed 检查类是否被允许booleanisMethodAllowed(String methodName) Check if method is allowed 检查方法是否被允许booleanisPropertyAllowed(String propertyName) Check if property is allowed 检查属性是否被允许
-
Method Details
-
isClassAllowed
Check if class is allowed 检查类是否被允许- Parameters:
className- the class name | 类名- Returns:
- true if allowed | 如果允许返回 true
-
isClassAllowed
Check if class is allowed 检查类是否被允许- Parameters:
clazz- the class | 类- Returns:
- true if allowed | 如果允许返回 true
-
isMethodAllowed
Check if method is allowed 检查方法是否被允许- Parameters:
methodName- the method name | 方法名- Returns:
- true if allowed | 如果允许返回 true
-
isPropertyAllowed
Check if property is allowed 检查属性是否被允许- Parameters:
propertyName- the property name | 属性名- Returns:
- true if allowed | 如果允许返回 true
-
getAllowedClasses
-
getAllowedMethods
-
getAllowedProperties
-
builder
-
empty
Create an empty allow list (denies all) 创建空白名单(拒绝所有)- Returns:
- the empty allow list | 空白名单
-
allowAll
Create an allow-all list (allows everything) 创建允许所有的白名单- Returns:
- the allow-all list | 允许所有的白名单
-