1. 介绍

开放内部事件,允许用户订阅事件

2. 基本情况

gb事件总览:

事件名称 描述 参数解释

AppEvent

系统事件基类

source对象是object实例

AppStartupEvent事件

系统启动事件

source对象是字符串"gb system starup init has ran"

AppShutdown事件

系统关闭事件

source对象是字符串"gb system shut down now"

AppOauth2ApprovalAgreeEvent

用户同意授权系统事件

source是一个Map对象;内容是:[authorizationRequest:authorizationRequest,userAuthentication:userAuthentication]

AppOauth2ApprovalDenyEvent

用户拒绝授权系统事件

source是一个Map对象;内容是:[authorizationRequest:authorizationRequest,userAuthentication:userAuthentication]

AppSecurityEvent

安全事件基类

source是一个Map

AppSecurityAuthSuccessEvent

认证成功安全事件

source是一个Map对象;内容是:[request:request,response:response,authentication:authentication]

AppSecurityAuthFailureEvent

认证失败安全事件

source是一个Map对象;内容是:[request:request,response:response,authenticationException:authenticationException]

AppSecurityCasAuthSuccessEvent

cas认证成功安全事件

source是一个Map对象;内容是:[request:request,response:response,authentication:authentication]

AppSecurityCasAuthFailureEvent

cas认证失败安全事件

source是一个Map对象;内容是:[request:request,response:response,authenticationException:authenticationException]

AppSecurityRestAuthSuccessEvent

rest认证成功安全事件

source是一个Map对象;内容是:[request:request,response:response,authentication:authentication]

AppSecurityRestAuthFailureEvent

rest认证失败安全事件

source是一个Map对象;内容是:[request:request,response:response,authenticationException:authenticationException]

3. 事件使用

3.1. 订阅事件

3.1.1. 使用独立listener类订阅

编写listener类来订阅事件

@Configuration
@Slf4j
class NewAppListener implements ApplicationListener<AppStartupEvent> {
    @Override
    void onApplicationEvent(AppStartupEvent event) {
        println "i receiver gb system startup event: ${event}";
    }
}

3.1.2. 简便方法订阅

也可使用GbSpringUtils辅助类的静态方法订阅

        GbSpringUtils.addApplicationListener(new ApplicationListener<AppEvent>() {
            @Override
            void onApplicationEvent(AppEvent event) {
                println "i receiver one gb system event: ${event}"
            }
        })

3.2. 发布事件

使用GbSpringUtils辅助类的静态方法可以发布事件

GbSpringUtils.publishEvent(new AppEvent('测试事件'));