Events

Events can be used to customize the functionality of LDAP authentication without having to modify the package code.

ec_ldap_on_directory_init

Description: Dispatched when a Directory object is initialized. The object is passed as a reference to the event which exposes the directory's public functions and properties.

Example Usage: One example of leveraging this event is to modify the user data that is returned by the ldap queries. This code adds the employeeID from an active directory directory to the list of fields that are returned for users so that we might use this data later (such as when syncing the user).

Events::addListener('ec_ldap_on_directory_init', function($event) {
    $event->getDirectoryObject()->additionalUserFields[] = 'employeeID';
});

ec_ldap_on_directory_user_sync

Description: Dispatched immediately after a DirectoryUser object sync is run. The object is passed as a reference to the event which exposes the DirectoryUser's public functions and properties.

Example Usage: If you need additional information to be synced from your LDAP server to a user this event can be used to update or add that additional information. This code assumes we've also leveraged the ec_ldap_on_directory_init event to add the additional user field for employeeid and we're going to save it to the concrete5 user's employee_id attribute we created.

Events::addListener('ec_ldap_on_directory_user_sync', function($event) {
    $ldapEmployeeID = $event->getDirectoryUserObject()->getLdapUser()['employeeid'][0];
    $event->getDirectoryUserObject()->getConcreteUser()->setAttribute('employee_id', $ldapEmployeeID);
});

ec_ldap_on_directory_user_delete

Description: Dispatched immediately after a DirectoryUser object is marked deleted. The object is passed as a reference to the event which exposes the DirectoryUser's public functions and properties.

Example Usage: If you choose to leave a concrete5 user active after its associated LDAP users have been deleted, it may make sense to clear out any attributes you set from the LDAP user. In this example, we want to unset the employee_id attribute if the LDAP user is deleted.

Events::addListener('ec_ldap_on_directory_user_delete', function($event) {
    $event->getDirectoryUserObject()->getConcreteUser()->clearAttribute('employee_id');
});