mirror of
https://github.com/keycloak/keycloak.git
synced 2026-02-11 17:59:09 -06:00
KEYCLOAK-1062 Document how to configure listeners
This commit is contained in:
@@ -44,7 +44,7 @@ public class MyEventListenerProviderFactory implements EventListenerProviderFact
|
||||
|
||||
}
|
||||
}]]></programlisting>
|
||||
The example uses a MaxList which has a maximum size and is concurrency safe. When the maximum size is reached
|
||||
The example uses an imagined MaxList which has a maximum size and is concurrency safe. When the maximum size is reached
|
||||
and new entries are added the oldest entry is removed. Keycloak creates a single instance of
|
||||
EventListenerProviderFactory which makes it possible to store state for multiple requests. EventListenerProvider
|
||||
instances are created by calling create on the factory for each requests so these should be light-weight.
|
||||
@@ -116,10 +116,10 @@ public class MyEventListenerProvider implements EventListenerProvider {
|
||||
Next you need to register this module with Keycloak. This is done by editing keycloak-server.json and adding
|
||||
it to the providers:
|
||||
<programlisting><![CDATA[{
|
||||
"providers": [
|
||||
...
|
||||
"module:org.keycloak.examples.event-sysout"
|
||||
]
|
||||
"providers": [
|
||||
...
|
||||
"module:org.keycloak.examples.event-sysout"
|
||||
]
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
@@ -147,6 +147,21 @@ public class MyEventListenerProvider implements EventListenerProvider {
|
||||
"providers": [
|
||||
"classpath:/home/user/providers/*"
|
||||
]
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Configuring a provider</title>
|
||||
<para>
|
||||
You can pass configuration options to your provider by setting them in <literal>keycloak-server.json</literal>.
|
||||
For example to set the max value for <literal>my-event-listener</literal> add:
|
||||
<programlisting><![CDATA[{
|
||||
"eventsListener": {
|
||||
"my-event-listener": {
|
||||
"max": 100
|
||||
}
|
||||
}
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
@@ -5,3 +5,13 @@ To deploy copy target/event-listener-sysout-example.jar to standalone/configurat
|
||||
Then start (or restart) the server. Once started open the admin console, select your realm, then click on Events,
|
||||
followed by config. Click on Listeners select box, then pick sysout from the dropdown. After this try to logout and
|
||||
login again to see events printed to System.out.
|
||||
|
||||
The example event listener can be configured to exclude certain events, for example to exclude REFRESH_TOKEN and
|
||||
CODE_TO_TOKEN events add the following to keycloak-server.json:
|
||||
|
||||
...
|
||||
"eventsListener": {
|
||||
"sysout" {
|
||||
"exclude": [ "REFRESH_TOKEN", "CODE_TO_TOKEN" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ public class SysoutEventListenerProviderFactory implements EventListenerProvider
|
||||
|
||||
@Override
|
||||
public void init(Config.Scope config) {
|
||||
String excludes = config.get("excludes");
|
||||
String[] excludes = config.getArray("excludes");
|
||||
if (excludes != null) {
|
||||
excludedEvents = new HashSet<EventType>();
|
||||
for (String e : excludes.split(",")) {
|
||||
excludedEvents = new HashSet<>();
|
||||
for (String e : excludes) {
|
||||
excludedEvents.add(EventType.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user