Tuesday, December 7, 2010

Creating an Event Handler in OIM

  1.  Copy the following code into a java file and then export it to the  OIM-HOME\xellerate\evenhandler folder.
  2.  Now open the Development Tools -> Business Rule Definition -> Event Handler Manager in the design console.
  3. Create a new Event Handler and specify:
    Event Handler Name: tcGenerateRandomPassword
  4. In the package name give the package in which the class is present.
  5. Select the pre-insert checkbox and then save the event handler.
  6. Now Goto Development Tools -> Business Rule Definition -> Data Object Manager
  7. Search for "Users" and add the event handler to the Pre-Insert list.
  8. Save it.
Now once you create a user in xellerate it will generate a random password for the user. Try logging in with the password generated and you should be able to login successfully.




import java.util.Random;
import com.thortech.xl.dataobj.tcDataSet;
import com.thortech.xl.util.logging.LoggerMessages; import com.thortech.xl.util.logging.LoggerModules;
import com.thortech.util.logging.Logger;

public class tcGenerateRandomPassword extends com.thortech.xl.client.events.tcBaseEvent

{


public tcGenerateRandomPassword()
{
setEventName("Generating a random password for a User.");
}

protected void implementation() throws Exception

{

if (getDataObject().isDeleting())

{

return;

}

if (getDataObject().isUpdating())

{

return;

}

String randomPassword = getRandomPassword();

getDataObject().setString("usr_password",randomPassword);

System.out.println("The Random Password generated is -----" +randomPassword);

return;

}

private String getRandomPassword()

{

StringBuffer buffer = new StringBuffer();

Random random = new Random();

for ( int i = 0; i < 10; i++ ) {

buffer.append(((char)

('a'+random.nextInt(20))));

}

return buffer.toString();

}

}

No comments:

Post a Comment