Sunday, November 21, 2010

Using Oracle Identity Manager’s Java API's from oimclient.jar

Lately I got chance to work on Oracle Identity Manager and I was trying to access Oracle Identity Manager through Java API’s exposed by this product.  Ofcourse it’s a great product but at same time it too complicated and I guess experts would agree that it’s so easy for a newbie to get lost in the tons and tons of doc even if complexity is put aside. Well I was lost for sure…

Here is the link for the Oracle's Developer Guide for Oracle Identity Manager if you want to go for detail steps and demo code.

Here I will try to put some steps in simple and straight forward way if you are interested to access OIM’s Java API’s.

There are two entry points for the OIM, one through OIMClient and other through tcUtilityFactory. Well I cannot comment which is the better but from the Doc OIMClient is ofcourse recommended one. One other thing is coming from the Oracle’s Application Development Framework (ADF), I selected JDeveloper as my tool.
  1. Copy oimclient.zip from OIM Server (OIM_ORACLE_HOME/server/client/ oimclient.zip) to local drive.
  2. Create a Fusion Web Application using JDeveloper.
  3. In the model project go the project properties select Run/Debug/Profile, click Default under Run Configurations and click edit.
  4. Go to the project folder in your JDeveloper Workspace and create two folders as jlib and conf.
  5. Extract the oimclient.jar to any folder and copy all the jars(OimClient.jar, Commons-logging.jar, Eclipselink.jar and Spring.jar) from it to jlib folder that we created in step 4.
  6. Copy the authwl.conf file to conf folder created in step 4.
  7. Go to the project properties for the model project and click on Libraries and Classpath. Click on Add JAR/Directory and add following jars OimClient.jar, Commons-logging.jar, Eclipselink.jar and Spring.jar
  8. Set the Java Options to
    -DXL.HomeDir=PATH\OIM
    -Djava.security.auth.login.config=FILE_PATH\conf\authwl.conf
  9.  Now it’s time to test the API. Create a sample java class and add following method to it.

        public static OIMClient client;
        private static String OIMUserName = "USERNAME";
        private static String OIMPassword = "PASSWORD";
        private static String OIMURL = "t3://OIM_HOSTNAME:OIM_PORT";
        private static String OIMInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";

        public static void loginWithCustomEnv() throws LoginException {
           Hashtable env = new Hashtable();
           env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, OIMInitialContextFactory);
           env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, OIMURL);
           client = new OIMClient(env);
           client.login(OIMUserName, OIMPassword);
           }

        public static void main(String args[]) {
            try {
                loginWithCustomEnv();
            } catch (LoginException e) {
                e.printStackTrace();
            }
        }
  10. Right Click and run to test the login.
Now you are ready to extend this to any level you want to take to. By the way oimclient.jar comes with the sample code to test the login and create user.

1 comment: