...
...
class | breadcrumbs |
---|
Style | ||
---|---|---|
| ||
EmpowerID provides a number of hard-coded methods, known as EmpowerID event receivers, that are called during inventory and attribute flow processes, providing organizations with the ability to write custom code that allows them to respond to specific actions carried out against objects discovered by EmpowerID. For example, one of the EmpowerID event receivers is the ActiveDirectoryAccountChangedReceiver event receiver. This event receiver is called as a "last resort" each time EmpowerID inventories Active Directory. It is the final method before EmpowerID calls InventoryBulkUpdate(), which pushes any changes in external Active Directory accounts to the EmpowerID Identity Warehouse. The default implementation of the ActiveDirectoryAccountChangedReceiver event receiver, as well as the default implementation for all EmpowerID event receivers, do nothing more than write out a record stating they have been called. However, each of these event receivers can can be custom coded to do anything from sending notifications of changes to interested parties, to initiating specific workflows to accomplish tasks related to those changes, to providing a fail-safe for corrective action when undesired changes are discovered.
Each EmpowerID event receiver lives as an object on the EmpowerIDEventReceivers table of the Identity Warehouse (for a tabular view of all the default EmpowerID event receivers, see the EmpowerIDEventReceivers table at the end of this topic), with two special properties, among others, the ReceiverAdapterAssembly property that refers to the specific assembly and the ReceiverAdapterType property that refers to the specific assembly with the code that is to be executed when the event receiver is invoked. When custom coding an existing default event receiver in this way, you simply create and publish a custom class library in Workflow Studio, being sure to implement to appropriate interface for the event receiver in the class. You then update the ReceiverAdapterAssembly and ReceiverAdapterType properties for the EmpowerID event receiver record in the EmpowerIDEventReceivers table. When event receivers are called, they look for the assembly and class to execute therein. If you do not update these properties, your custom code will not be called.
Info |
---|
When customizing EmpowerID event receivers, you must be sure to implement the appropriate interfaces for those event receivers for your customization to work in EmpowerID. These interfaces are baked in and cannot be changed. |
When EmpowerID executes the ActiveDirectoryAccountChangedReceiver event receiver, it does so in the following way. (The process is the same for each default EmpowerID event receiver.)
In the following example, we create a class library in Workflow Studio implementing the IAccountChangedReceiver interface. This allows us to add code to the Receive() method to perform any actions when the ActiveDirectoryAccountChangedReceiver event receiver is invoked. We then compile and publish the class library and update the ReceiverAdapterAssembly and ReceiverAdapterType properties for the event receiver.
EmpowerID calls the ActiveDirectoryAccountChangedReceiver.ExecuteReceiver() method, passing the collection of ExistingAccounts ;to the receiver. It does this right before the Account.InventoryBulkUpdate() method is called.
- ExecuteReceiver(), in turn, calls the EmpowerID database to get the values of the ReceiverAdapterAssembly and ReceiverAdapterType properties.
ExecuteReceiver() then uses reflection to invoke the Receive() method implemented by the IAccountChangedReceiver interface. This method receives a collection of accounts.
The Receive() method executes any code for the event receiver. Organizations wishing to implement their own custom code would do so here. We demonstrate this below.
Info The below code below is for demonstration purposes only.
To customize the ActiveDirectoryChangedReceiver event receiver
- In Workflow Studio, click on the application icon to open the application menu and select Extensibility > EmpowerID Class Library.
- Name the Class Library "Custom_ActiveDirectoryAccountChangedReceiver" and save it to the package of your choice.
Workflow Studio creates the class library and opens the C# Editor for it. In the C# Editor for the class library, add code to the class declaration to implement the IAccountChangedReceiver interface.
Code Block public class Custom_ActiveDirectoryAccountChangedReceiver : TheDotNetFactory.Framework.ResourceManagement.IAccountChangedReceiver
In the C# Editor for the class library, add the following code to the OnProcessAlert() method (Comments have been added for clarity).
Code Block //Call the Receive() method of the IAccountChangedReceiver interface to return the collection of changed accounts public void Receive(TList<Account> changedObjects) { //Create a list of account objects E.VList<C.AccounView> accList = new E.VList<C.AccountView>(); //Add all changed objects to the list of account objects if(changedObjects.Count > 0) { foreach(var v in changedObjects) accList.Add(v); //Implement further code to work with the list as desired ... } }
- When ready, compile and publish the class library.
- In SQL Server, update the ReceiverAdapterAssembly and ReceiverAdapterType properties accordingly for the event receiver.
...