OIMDAO Getting Started

Setup

Set Java Classpath

  1. The library uses Hibernate to access the database, so you'll need the latest version of hibernate3.jar from that site. OIMDAO has been tested with the 3.6.8-Final and 4.0.0.CR7 release of Hibernate. You shall add the hibernateXXX.jar files and all dependencies to the classpath (see hibernate_classpath variable definition below).
  2. You will need JDBC driver for Oracle database (ojdbc6.jar). You can find this file in any oracle distribution.
  3. Some classes use guava-r09 by Google, so you must have that library on your classpath. Get it at http://code.google.com/p/guava-libraries
  4. You shall add a hibernate configuration file to the classpath (described in the next section).
  5. You shall add the OIMDAO library to the classpath.

So for Hibernate 3 your shell script running OIMDAO examples will look like this:

#!/bin/bash

HIBERNATE_HOME=<your path to hibernate3 distribution>

hibernate_classpath=$HIBERNATE_HOME/hibernate3.jar:\
$HIBERNATE_HOME/lib/required/dom4j-1.6.1.jar:\
$HIBERNATE_HOME/lib/required/jta-1.1.jar:\
$HIBERNATE_HOME/lib/required/slf4j-api-1.6.1.jar:\
$HIBERNATE_HOME/lib/required/javassist-3.12.0.GA.jar:\
$HIBERNATE_HOME/lib/required/commons-collections-3.1.jar:\
$HIBERNATE_HOME/lib/jpa/hibernate-jpa-2.0-api-1.0.1.Final.jar

JDBC_DRIVER_JAR=<path to ojdbc6.jar>
GUAVA_JAR=<path to guava.jar>
OIM_CFG_LOCATION=<path to oim.cfg.xml>
OIMDAO_JAR=<path to oimdaodist.zip>

classpath=$OIMDAO_JAR:$OIM_CFG_LOCATION:$JDBC_DRIVER_JAR:$GUAVA_JAR:$hibernate_classpath

java -Dfile.encoding=UTF-8 -classpath $classpath idm4j.oim.dao.examples.Tutorial "$@"

Provide your own classes for users and organizations

In order to provide support for OIM UDF since release 332 of OIMDAO only the abstract ancestors of idm4j.oim.dao.User and idm4j.oim.dao.Organization entity classes for users and organizations are included into the distribution. So in order to use OIMDAO you have to provide your own variants of these classes.

No UDF support

If you need no UDF support, you will define these classes as follows:

package idm4j.oim.dao;
 
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
 
@SequenceGenerator(name = "USR_SEQ", sequenceName = "USR_SEQ", allocationSize = 1)
@Entity
@Table(name = "USR")
@XmlAccessorType(XmlAccessType.FIELD)
public class User extends AbstractUser {
}

and
package idm4j.oim.dao;
 
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
 
@SequenceGenerator(name = "ACT_SEQ", sequenceName = "ACT_SEQ", allocationSize = 1)
@Entity
@Table(name = "ACT")
@XmlAccessorType(XmlAccessType.FIELD)
public class Organization extends AbstractOrganization {
}

UDF support

If you need support for UDF, you will probably want to modify these classes.

For example, if you added a column named USR_UDF_POSITIONTYPE with column size 256 to the USR table, add the following lines to the body of the idm4j.oim.dao.User class:

  @Column(name = "USR_UDF_POSITIONTYPE", length = 256)
  String positionType;

Set connection parameters

Now you need to tell OIMDAO where your OIM repository is and how to connect to it.

Create a file named oim.cfg.xml, and make sure it is on the Java classpath (see OIM_CFG_LOCATION variable in the previous section), you will probably want to change the connection URL, username and password. Use the following text as an example:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">
      oracle.jdbc.driver.OracleDriver
    </property>
 
    <!-- Connection JDBC URL -->
    <property name="hibernate.connection.url">
      jdbc:oracle:thin:dev_oim@localhost:1521:orcl
    </property>
 
    <!-- Connection username -->
    <property name="hibernate.connection.username">
      dev_oim
    </property>
 
    <!-- Connection password -->
    <property name="hibernate.connection.password">
      secret
    </property>
 
    <property name="hibernate.dialect">
      org.hibernate.dialect.Oracle10gDialect
    </property>
 
    <!-- ... put any Hibernate parameters here if necessary, like the following ... -->
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.hbm2ddl.auto">validate</property>
 
    <property name="hibernate.bytecode.use_reflection_optimizer">true</property>
    <property name="max_fetch_depth">1</property>
  </session-factory>
</hibernate-configuration>

Test connection

Run the script provided in the first section, you shall see something like this:

Successfully connected to OIM repo!

If you take a look at the idm4j/oim/dao/examples/Tutorial.java from your oimdaodist.zip, you will see that the code you've just executed looks like this:

DAOUtils.getEntityManager();
System.out.println("Successfully connected to OIM repo!");

Note: the OIM repository connection parameters are hard-coded into the DAOUtils.java, so you probably will to edit this code.

Hello world application

In this example you will retrieve and print information about the System Administrator user (see displayUserInfo() method in idm4j/oim/dao/examples/Tutorial.java.

EntityManager em = DAOUtils.getEntityManager();
User user = DAOUtils.getUserByLogin(em, "xelsysadm");
System.out.println(user);
System.out.println("Organization:  " + user.getOrganization());
System.out.println("Status:        " + user.getStatus());
System.out.println("Type:          " + user.getType());
System.out.println("Employee Type: " + user.getEmployeeType());
System.out.println("First Name:    " + user.getFirstName());
System.out.println("Last Name:     " + user.getLastName());
System.out.println("Display Name:  " + user.getDisplayName());
 
System.out.println("\nGroups:");
for (User2Group group : user.getGroups())
  System.out.println("  " + group.getGroup());
 
System.out.println("\nOwns groups:");
for (Group group : user.getOwnsGroups())
  System.out.println("  " + group);
 
System.out.println("\nProcess instances:");
for (ProcessInstance processInstance : user.getProcessInstances())
  System.out.println("  " + processInstance);
 
System.out.println("\nProcess tasks:");
for (ProcessTask processInstance : user.getProcessTasks())
  System.out.println("  " + processInstance);

will print:

User{1, System Administrator, XELSYSADM}
Organization:  Organization{1, Xellerate Users, System, Active}
Status:        Active
Type:          End-User Administrator
Employee Type: Full-Time
First Name:    System
Last Name:     Administrator
Display Name:  System Administrator

Groups:
  Group{1, SYSTEM ADMINISTRATORS}

Owns groups:
  Group{13, ATTESTATION CONFIGURATION ADMINISTRATORS}
  Group{27, SOD ADMINISTRATORS}
  Group{15, RESOURCE ADMINISTRATORS}
  Group{17, REQUEST TEMPLATE ADMINISTRATORS}
  Group{22, DEPLOYMENT MANAGER ADMINISTRATORS}
  Group{1, SYSTEM ADMINISTRATORS}
  Group{28, USER NAME ADMINISTRATORS}
  Group{24, REPORT ADMINISTRATORS}
  Group{11, ACCESS POLICY ADMINISTRATORS}
  Group{18, GENERIC CONNECTOR ADMINISTRATORS}
  Group{25, PLUGIN ADMINISTRATORS}
  Group{5, IDENTITY USER ADMINISTRATORS}
  Group{10, ATTESTATION EVENT ADMINISTRATORS}
  Group{8, REQUEST ADMINISTRATORS}
  Group{26, SPML_App_Role}
  Group{21, SYSTEM CONFIGURATION ADMINISTRATORS}
  Group{20, NOTIFICATION TEMPLATE ADMINISTRATORS}
  Group{3, ALL USERS}
  Group{9, RECONCILIATION ADMINISTRATORS}
  Group{12, APPROVAL POLICY ADMINISTRATORS}
  Group{19, SCHEDULER ADMINISTRATORS}
  Group{16, IT RESOURCE ADMINISTRATORS}
  Group{4, SELF OPERATORS}
  Group{23, Administrators}
  Group{6, IDENTITY ORGANIZATION ADMINISTRATORS}
  Group{14, USER CONFIGURATION ADMINISTRATORS}
  Group{7, ROLE ADMINISTRATORS}
  Group{2, OPERATORS}

Process instances:
  ProcessInstance{2, Xellerate Users, XELSYSADM, C, Xellerate User}
  ProcessInstance{1, Xellerate Users, XELSYSADM, C, User}

Process tasks:
  ProcessTask{15, Install Application, Installation Process, null, null, null}
  ProcessTask{14, System Validation, Installation Process, null, null, null}
  ProcessTask{16, Enter Info into Oracle Identity Manager, Installation Process, null, null, null}

Modify objects

All modification shall be made in a transaction. So you need to acquire a transaction, do changes, then commit the transaction or rollback it if something wrong happened while objects were being changed.

In the following example we will find all users with lastName "Dow" and change their lastName to "Smith".

EntityManager em = DAOUtils.getEntityManager();
List<User> users = DAOUtils.getObjects(em, User.class, "lastName", "Dow");
em.getTransaction().begin();
try {
  for(User user : users)
    user.setLastName("Dow");
  em.getTransaction().commit();
} catch (Throwable e) {
  em.getTransaction().rollback();
  e.printStackTrace();
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License