This project includes a custom event handler CustomEventHandler that handles the WSO2 Identity Server's
POST_REVOKE_ACESS_TOKEN, POST_REVOKE_ACESS_TOKEN_BY_ID, SESSION_TERMINATE, and SESSION_EXPIRE events.
Look here for more information on event handlers.
Add the below to the <IS_HOME>/repository/conf/deployment.toml file:
[[event_handler]]
name = "CustomEventHandler"
subscriptions = ["POST_REVOKE_ACESS_TOKEN", "POST_REVOKE_ACESS_TOKEN_BY_ID", "SESSION_TERMINATE", "SESSION_EXPIRE"]You can add custom properties to the event handler by adding it under properties:
[[event_handler]]
name = "CustomEventHandler"
subscriptions = ["POST_REVOKE_ACESS_TOKEN", "POST_REVOKE_ACESS_TOKEN_BY_ID", "SESSION_TERMINATE", "SESSION_EXPIRE"]
properties.custom_property = "custom_value"Then, read it in the CustomEventHandler class using the AbstractEventHandler#config field:
configs.getModuleProperties().getProperty("CustomEventHandler.custom_property");The property name will always be in the format event_handler_name.property_name.
- Build the project using Maven:
mvn clean install
- Copy the
target/custom_event_handler-1.0.0-SNAPSHOT.jarfile to the<IS_HOME>/repository/components/dropinsdirectory. - Add the configuration mentioned in the Configuration section.
- Start the server.
For this component's logs to be printed, you need to do the following steps in to the <IS_HOME>/repository/conf/log4j2.properties file:
- Create a Log4J2 Logger named
org-samplemapped to theorg.samplepackage:logger.org-sample.name = org.sample logger.org-sample.level = DEBUG
- Add the new
org-samplelogger to theloggersvariable:loggers = AUDIT_LOG, . . ., org-sample
. . . DEBUG {org.sample.event.handler.CustomEventHandler} - POST_REVOKE_ACESS_TOKEN_BY_ID event received to CustomEventHandler.
. . . INFO {org.sample.event.handler.CustomEventHandler} - Session ID or Authenticated User is not available in the event properties.
. . . DEBUG {org.sample.event.handler.CustomEventHandler} - SESSION_TERMINATE event received to CustomEventHandler.
. . . INFO {org.sample.event.handler.CustomEventHandler} - Session ID: eee2cae36bfe4f96fb269458b708036c71cb9efdb3696c2cfa241834e2b9602f, Authenticated User: admin@carbon.super
To debug this component while the Identity Server is running:
- Run the Identity Server in debug mode:
sh $IS_HOME/bin/wso2server.sh --debug 5005 - Attach the JVM to your IDE:
- For IntelliJ IDEA:
- Go to
Run>Edit Configurations... - Click on the
+icon and selectRemote JVM Debug. - Set the port to
5005and clickOK. - Add your breakpoints in the code.
- Click on the green debug icon to start debugging.
- Go to
- For VSCode:
- Go to the
Runtab on the left sidebar. - Click on
create a launch.json file. - Select
Javaand then selectRemote. - Set the port to
5005and clickOK. - Add your breakpoints in the code.
- Click on the green debug icon to start debugging.
- Go to the
- For IntelliJ IDEA:
Note: The Identity Server's startup will be blocked until you connect the debugger.