Skip to content

Commit

Permalink
KEYCLOAK-1062 Document how to configure listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
stianst committed Mar 20, 2015
1 parent 5455211 commit d44cc86
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
25 changes: 20 additions & 5 deletions docbook/reference/en/en-US/modules/providers.xml
Expand Up @@ -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.
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
10 changes: 10 additions & 0 deletions examples/providers/event-listener-sysout/README.md
Expand Up @@ -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" ]
}
}
Expand Up @@ -24,10 +24,10 @@ public EventListenerProvider create(KeycloakSession session) {

@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));
}
}
Expand Down

0 comments on commit d44cc86

Please sign in to comment.