Sunday, November 17, 2013

Close Reconciliation Events Through OIM API

Version: Oracle Idenity Manager 11g R1
Description: Reconciliation events are created when you run target user reconciliation. On a target system with a large number of accounts, it is likely to have events that are ophran accounts, which are users who does not exist in OIM but exists on the target system, and events that are in pending state. When you view these reconcilation events through the OIM console, you have the choice to manually link to an OIM user or close the event. Given here is code to close all the reconciliation events that were not linked.
import Thor.API.Exceptions.tcAPIException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;
import oracle.iam.reconciliation.api.ReconOperationsService;

/**
 * Closes Reconciliation Events that do not belong in 
 * Closed or Linked categories.
 */
public class CloseReconciliationEvents
{
    public static String NO_USER_MATCH_FOUND = "No User Match Found";
    public static String EVENT_RECEIVED = "Event Received";
    
    public static void main(String[] args) throws LoginException, ClassNotFoundException, SQLException, tcAPIException
    {
        String ctxFactory = "weblogic.jndi.WLInitialContextFactory";
        String oimServerURL = "t3://localhost:14000";
        String authwlConfigPath = "/home/oracle/Oracle/Middleware/Oracle_IDM1/designconsole/config/authwl.conf";
        String username = "xelsysadm"; //OIM Administrator 
        String password = "Password1"; //Administrator Password
        OIMClient oimClient = null;
        
        //Database Objects
        Connection connection = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
           
        try
        {
            //Setup OIMClient and login
            System.setProperty("java.security.auth.login.config", authwlConfigPath);
            Hashtable<String,String> env = new Hashtable<String,String>();
            env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, ctxFactory);
            env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, oimServerURL);
            oimClient = new OIMClient(env);
            oimClient.login(username, password.toCharArray()); //login to OIM
            ReconOperationsService reconOps = oimClient.getService(ReconOperationsService.class);
            
            //Connect to Oracle Database
            String serverName = "localhost";
            String portNumber = "1521";
            String sid = "orcl";
            String db_url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
            String db_username = "DEV_OIM";
            String db_password = "Password1";
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection(db_url, db_username, db_password);
            
            //Query the Recon Events table
            String query = "SELECT RE_KEY, RE_STATUS FROM RECON_EVENTS WHERE RE_STATUS IN (?, ?)";
            ps = connection.prepareStatement(query);
            ps.setString(1, NO_USER_MATCH_FOUND);
            ps.setString(2, EVENT_RECEIVED);
            rs = ps.executeQuery();
            
            System.out.println(query);
            System.out.println(String.format("IN ('%s', '%s')", NO_USER_MATCH_FOUND, EVENT_RECEIVED));
            
            while(rs.next())
            {
                Long reconEventKey = rs.getLong("RE_KEY");
                String reconStatus = rs.getString("RE_STATUS");
                System.out.println(String.format("{RE_KEY =  %s, RE_STATUS = %s}", reconEventKey,reconStatus));
                reconOps.closeReconciliationEvent(reconEventKey);
            }
            
        }
        
        finally
        {
            if(oimClient != null)
                oimClient.logout();
            
            if(rs != null)
                rs.close();
            
            if(ps != null)
                ps.close();
            
            if(connection != null)
                connection.close();
        }
        
    }
}

No comments:

Post a Comment