Class SecureEventBus
java.lang.Object
cloud.opencode.base.event.security.SecureEventBus
- All Implemented Interfaces:
AutoCloseable
Secure Event Bus
安全事件总线
A secure wrapper around OpenEvent that enforces security policies.
在OpenEvent周围的安全包装器,强制执行安全策略。
Features | 主要功能:
- Listener whitelist - 监听器白名单
- Package restrictions - 包限制
- Event verification - 事件验证
- Rate limiting integration - 频率限制集成
Usage Examples | 使用示例:
SecureEventBus bus = new SecureEventBus();
bus.addAllowedPackage("com.myapp.handlers");
bus.addToWhitelist(MyHandler.class);
bus.register(new MyHandler()); // OK
bus.register(new UntrustedHandler()); // throws SecurityException
Security | 安全性:
- Thread-safe: Yes (concurrent data structures) - 线程安全: 是(并发数据结构)
- Since:
- JDK 25, opencode-base-event V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate secure event bus with default settings 使用默认设置创建安全事件总线SecureEventBus(EventRateLimiter rateLimiter) Create secure event bus with rate limiter 使用频率限制器创建安全事件总线SecureEventBus(EventRateLimiter rateLimiter, String verificationSecret) Create secure event bus with rate limiter and verification secret 使用频率限制器和验证密钥创建安全事件总线 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllowedPackage(String packageName) Add an allowed package prefix 添加允许的包前缀voidaddToWhitelist(Class<?> listenerClass) Add a class to the listener whitelist 将类添加到监听器白名单voidclose()Close the secure event bus, releasing underlying resources.Get the underlying event bus (CAUTION: bypasses ALL security checks) 获取底层事件总线(注意:绕过所有安全检查)<E extends Event>
voidon(Class<E> eventType, EventListener<E> listener) Register a lambda listener with security checks 使用安全检查注册Lambda监听器voidPublish an event with security checks 使用安全检查发布事件voidRegister a subscriber with security checks 使用安全检查注册订阅者voidunregister(Object subscriber) Unregister a subscriber 注销订阅者
-
Constructor Details
-
SecureEventBus
public SecureEventBus()Create secure event bus with default settings 使用默认设置创建安全事件总线 -
SecureEventBus
Create secure event bus with rate limiter 使用频率限制器创建安全事件总线- Parameters:
rateLimiter- the rate limiter | 频率限制器
-
SecureEventBus
Create secure event bus with rate limiter and verification secret 使用频率限制器和验证密钥创建安全事件总线- Parameters:
rateLimiter- the rate limiter | 频率限制器verificationSecret- the secret for verifying signed events | 用于验证签名事件的密钥
-
-
Method Details
-
addToWhitelist
Add a class to the listener whitelist 将类添加到监听器白名单- Parameters:
listenerClass- the listener class to allow | 要允许的监听器类
-
addAllowedPackage
Add an allowed package prefix 添加允许的包前缀- Parameters:
packageName- the package prefix to allow | 要允许的包前缀
-
register
Register a subscriber with security checks 使用安全检查注册订阅者- Parameters:
subscriber- the subscriber to register | 要注册的订阅者- Throws:
EventSecurityException- if subscriber is not allowed | 如果订阅者不被允许
-
on
Register a lambda listener with security checks 使用安全检查注册Lambda监听器- Type Parameters:
E- the event type parameter | 事件类型参数- Parameters:
eventType- the event type | 事件类型listener- the listener | 监听器
-
unregister
Unregister a subscriber 注销订阅者- Parameters:
subscriber- the subscriber to unregister | 要注销的订阅者
-
publish
Publish an event with security checks 使用安全检查发布事件- Parameters:
event- the event to publish | 要发布的事件- Throws:
EventSecurityException- if rate limit exceeded or verification failed | 如果频率限制超出或验证失败
-
close
public void close()Close the secure event bus, releasing underlying resources. 关闭安全事件总线,释放底层资源。- Specified by:
closein interfaceAutoCloseable
-
getEventBus
Get the underlying event bus (CAUTION: bypasses ALL security checks) 获取底层事件总线(注意:绕过所有安全检查)WARNING: Direct access to the underlying event bus bypasses all security policies (whitelist, rate limiting, signature verification). Use only for advanced integration scenarios where the caller manages its own security. Consider using
SecureEventBusmethods instead.警告:直接访问底层事件总线将绕过所有安全策略(白名单、频率限制、签名验证)。 仅在调用者自行管理安全性的高级集成场景中使用。请优先使用
SecureEventBus方法。- Returns:
- the underlying OpenEvent instance | 底层OpenEvent实例
-