Documentation for Crowd 1.6. Documentation for other versions of Crowd is available too.
On this page:
If you are familiar with writing a listener for Confluence, writing a listener plugin for Crowd should be almost identical.
In Crowd, events are thrown for almost all operations that occur to a user. (If you need more or find a spot we haven't thought of, please let us know!.)
Below is an example atlassian-plugin.xml
that will configure your event Listeners:
<atlassian-plugin name="Example Listeners" key="crowd.listeners.core" system="false"> <plugin-info> <description>This contains example listeners</description> <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/> <version>1.0</version> </plugin-info> <listener name="Reset Password Listener" key="resetpasswordlistener" class="com.atlassian.crowd.event.listener.ResetPasswordListener"> <description>Will handle reset password events, sending out a principal their new password.</description> </listener> </atlassian-plugin>
Your event listener must implement the com.atlassian.event.EventListener
interface:
package com.atlassian.event; /** * Defines a listener for Crowd events. */ public interface EventListener { /** * Perform some action as a response to an event. The EventManager will * ensure that this is only called if the class of the event matches one of the * classes returned by getHandledEventClasses * * @param event some event triggered within Crowd */ void handleEvent(Event event); /** * Determine which event classes this listener is interested in. * * <p>The EventManager performs rudimentary filtering of events by their class. If * you want to receive only a subset of events passing through the system, return * an array of the Classes you wish to listen for from this method. * * <p>Listening for a class will also listen for all its subclasses. (And listening * for an interface will listen for any implementation of that interface) * * <p>Returning an empty array will allow you to receive every event. * * @return An array of the event classes that this event listener is interested in, * or an empty array if the listener should receive all events. <b>Must not</b> * return null. */ Class[] getHandledEventClasses(); }
Most event types in Crowd currently extend com.atlassian.crowd.event.DirectoryEvent
. If you want to see the current list of available events, please take a look at Crowd's JavaDoc.
Generally Crowd uses the following naming scheme for events:
<Object><Operation>Event
For example:
PrincipalUpdatedEvent.
This event would indicate that a Principal (<Object>) has been updated (<Operation>).
Please take note of the following limitations:
GroupUpdatedEvent
that itself causes a GroupUpdatedEvent
to be generated, you are responsible for preventing the ensuing infinite loop.We would suggest looking at the current Crowd source. Currently there are only a few listeners implemented in Crowd, but more will come.
The above example of a module descriptor defines a ResetPasswordListener
. Please look at this listener if you need a practical example.