Monday, November 25, 2013

Registering a Plugin using OIM APIs

Version: Oracle Identity Manager 11g R2
Description: Provided here is JAVA code to remotely register a plugin such an event handler or a scheduled task. The OIMClient and PlatformService are used. Adjust the variables (E.g. Path to zip file and OIM credentials) accordingly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package oracleidentitymanager;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.pluginframework.PluginException;
import oracle.iam.platformservice.api.PlatformService;
import oracle.iam.platformservice.exception.PlatformServiceAccessDeniedException;
 
public class RegisterPlugin
{
 
    public static final String OIM_HOSTNAME = "localhost";
    public static final String OIM_PORT = "14000";
    public static final String OIM_PROVIDER_URL = "t3://"+ OIM_HOSTNAME + ":" + OIM_PORT;
    public static final String OIM_USERNAME = "xelsysadm";
    public static final String OIM_PASSWORD = "Password1";
    public static final String OIM_CLIENT_HOME = "/home/oracle/Desktop/oimclient";
    public static final String AUTHWL_PATH = OIM_CLIENT_HOME + "/conf/authwl.conf";
    public static final String PLUGIN_ZIP_PATH = "/home/oracle/jdeveloper/mywork/OracleIdentityManager/OracleStack/custom_eventhandlers/custom_eventhandlers.zip";
    
    public static void main (String args[])
    {
        OIMClient oimClient = null;
        FileInputStream fis = null;
         
        try
        {
             //Set system properties required for OIMClient
            System.setProperty("java.security.auth.login.config", AUTHWL_PATH);
            System.setProperty("APPSERVER_TYPE", "wls");
 
            // Create an instance of OIMClient with OIM environment information
            Hashtable env = new Hashtable();
            env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
            env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, OIM_PROVIDER_URL);
            oimClient = new OIMClient(env);
 
            // Login to OIM with the approriate credentials
            oimClient.login(OIM_USERNAME, OIM_PASSWORD.toCharArray());
            
            // Zip file conversion to byte
            String fileName = PLUGIN_ZIP_PATH;
            File zipFile = new File(fileName);
            fis = new FileInputStream(zipFile);
            int size = (int) zipFile.length();
            byte[] b = new byte[size];
            int bytesRead = fis.read(b, 0, size);
            
            while (bytesRead < size)
            {
                bytesRead += fis.read(b, bytesRead, size - bytesRead);
            }
            
            // Register Plugin to OIM
            PlatformService service = oimClient.getService(PlatformService.class);
            service.registerPlugin(b);
 
            // Purge Cache
            PlatformUtilsService platUtilOps = oimClient.getService(PlatformUtilsService.class);
            platUtilOps.purgeCache("ALL");
        }
        
        catch (FileNotFoundException ex)
        {
            Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        catch (PlatformServiceAccessDeniedException ex)
        {
            Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        catch (PluginException ex)
        {
            Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        catch (IOException ex)
        {
            Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        catch (LoginException ex)
        {
            Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        finally
        {
            // Logout user from OIMClient
            if(oimClient != null)   
            {
                oimClient.logout();
            }
            try
            {
                fis.close();                 
            }
            
            catch (IOException ex)
            {
                Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

No comments:

Post a Comment