In one of the scenario we have the requirement where we need to create user in OIM using scheduler.The scheduler will take the parameters from csv file and run after particular interval of time and create the user. In this lab we are going to create the custom scheduler using java code and we create the scheduler we will manually fill the required details in the scheduler and will run it to check whether it is creating user or not.
Note: Here we are assuming that you have oim custom installer for jdeveloper. Also you know how to create the folder structure structure for the same.
1) Create the java project in jdeveloper and add the following jar as shown in figure.
2) Copy and Paste the below code.
<oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<plugins pluginpoint="oracle.iam.scheduler.vo.TaskSupport">
<plugin pluginclass="Test" version="2.0" name="SampleTestUserScheduledTask"/> </plugins>
</oimplugins>
4) Create "metadata.xml" with content as shown below
<?xml version="1.0" encoding="UTF-8"?>
<scheduledTasks xmlns="http://xmlns.oracle.com/oim/scheduler">
<task>
<name>Create New User</name>
<class> Test</class>
<description>Create a new OIM User</description>
<retry>5</retry>
<parameters>
<string-param required="true" encrypted="false" helpText="First Name">First Name</string-param>
<string-param required="true" encrypted="false" helpText="Last Name">Last Name</string-param>
<string-param required="true" encrypted="false" helpText="User Login">User Login</string-param>
</parameters>
</task>
</scheduledTasks>
5) If you see the metadata.xml file above, you will observer that we are going to create three fields on the scheduler namely First Name, Last Name, User Login. We will provide our parameters here and the default value for Organization, User Type are take from java code.
6) Paste the plugin.xml & metadata.xml file inside config folder.
7) Deploy the project.
8) Login to oim and create the custom scheduler.The only thing you need to take care here is while creating the custom scheduler make sure to select task name same the one you have given in plugin.xml file.
9) Once the scheduler gets created fill the required details and click on RunNow. The user will get created in OIM.
Note: Here we are assuming that you have oim custom installer for jdeveloper. Also you know how to create the folder structure structure for the same.
1) Create the java project in jdeveloper and add the following jar as shown in figure.
2) Copy and Paste the below code.
- import java.util.HashMap;
- import oracle.iam.identity.usermgmt.api.UserManager;
- import oracle.iam.identity.usermgmt.vo.User;
- import oracle.iam.platform.Platform;
- import oracle.iam.scheduler.vo.TaskSupport;
- public class Test extends TaskSupport {
- public void execute(HashMap hm) throws Exception {
- UserManager usrMgr = Platform.getService(UserManager.class);
- String userKey = null; // USR_KEY
- String firstName = (String) hm.get("First Name");
- String lastName = (String) hm.get("Last Name");
- String userLogin = (String) hm.get("User Login");
- String organizationKey = "1";
- String userType = "End-User";
- String role = "Full-Time";
- User newUser = new User(userKey);
- newUser.setLogin(userLogin);
- newUser.setFirstName(firstName);
- newUser.setLastName(lastName);
- newUser.setOrganizationKey(organizationKey);
- newUser.setUserType(userType);
- newUser.setEmployeeType(role);
- usrMgr.create(newUser);
- System.out.println("User creation successfully done");
- System.out.println("user display name is "+newUser.getLogin());
- }
- public HashMap getAttributes() {
- return null;
- }
- public void setAttributes() {
- }
- }
<oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<plugins pluginpoint="oracle.iam.scheduler.vo.TaskSupport">
<plugin pluginclass="Test" version="2.0" name="SampleTestUserScheduledTask"/> </plugins>
</oimplugins>
4) Create "metadata.xml" with content as shown below
<?xml version="1.0" encoding="UTF-8"?>
<scheduledTasks xmlns="http://xmlns.oracle.com/oim/scheduler">
<task>
<name>Create New User</name>
<class> Test</class>
<description>Create a new OIM User</description>
<retry>5</retry>
<parameters>
<string-param required="true" encrypted="false" helpText="First Name">First Name</string-param>
<string-param required="true" encrypted="false" helpText="Last Name">Last Name</string-param>
<string-param required="true" encrypted="false" helpText="User Login">User Login</string-param>
</parameters>
</task>
</scheduledTasks>
5) If you see the metadata.xml file above, you will observer that we are going to create three fields on the scheduler namely First Name, Last Name, User Login. We will provide our parameters here and the default value for Organization, User Type are take from java code.
6) Paste the plugin.xml & metadata.xml file inside config folder.
7) Deploy the project.
8) Login to oim and create the custom scheduler.The only thing you need to take care here is while creating the custom scheduler make sure to select task name same the one you have given in plugin.xml file.
9) Once the scheduler gets created fill the required details and click on RunNow. The user will get created in OIM.
No comments:
Post a Comment