Tuesday, March 5, 2013

Custom Common Name Generation Policy Plugin in OIM 11g r2

By default the Common Name Generation Policy used in OIM is "oracle.iam.ldapsync.impl.plugins.FirstNameLastNamePolicy". If you want to use your own policy for example mapping the User ID as Common Name. Here is how it can be achieved.

Create a custom plugin class implementing the CommonNamePolicy:

CustomCommonNamePolicy Class:

 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
import java.util.Locale;
import java.util.Map;

import static oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName.USER_LOGIN;
import oracle.iam.ldapsync.api.CommonNamePolicy;
import oracle.iam.ldapsync.exception.CommonNameGenerationException;


public class CustomCommonNamePolicy implements CommonNamePolicy{
    public CustomCommonNamePolicy() {
        super();
    }

    @Override
    public String getCommonNameFromPolicy(Map<String, Object> userData)throws CommonNameGenerationException {
        return (String) userData.get(USER_LOGIN.getId());
    }

    @Override
    public boolean isCommonNameValid(String commonName, Map<String,Object> userData) {
       return true;
    }

    @Override
    public String getDescription(Locale locale) {
        return "Custom policy - returns user login as common name";
    }
}

Create a plugin xml file with the following content:

plugin.xml file:

1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8"?>
<oimplugins>
    <plugins pluginpoint="oracle.iam.ldapsync.api.CommonNamePolicy">
        <plugin pluginclass="com.plugins.custom.commonname.CustomCommonNamePolicy" version="1.0" name="CustomCommonNamePolicy"/>
    </plugins>
</oimplugins>

Create a zip file CustomCommonNamePolicyPlugin.zip with the following folder structure:
  • The plugin.xml file: the plugin file created above.
  • The lib/ directory: The lib/ directory consists of class files with full package structure that contains the classes implementing the plug-in logic.
  • The resources/ directory: empty folder.
Copy Common Name Generation Policy plugin to the plugins directory:

1. Transfer the Common Name Generation plugin zip file (CustomCommonNamePolicyPlugin.zip) to the $OIM_ORACLE_HOME/server/plugins directory on the server using WinScp or any other sftp software;

Update the OIM system property to use the custom common name generation policy:

1) Login to OIM System Administration Console using the following URL. http://<OIM Server Hostname>:<OIM server Port>/sysadmin and the following connections page will appear as shown in the below:
Note 1: The OIM Server Hostname and OIM server Port values have to be replaced with actual values depending on the environment you are carrying out these steps.
Note 2: A sample URL for accessing OIM System Administration screen is: http://<oim-host>:<oim-port>/sysadmin.

Figure 1: OIM Login page

2) Enter the value for User ID and Password and Click on Sign In as shown in Figure 1 above.
 
Figure 2: OIM page after Login

3) Click on System Configuration under System Management as shown in Figure 2 above.

 Figure 3: Search System Configuration Page

4) Enter *Common* in the search criteria and click search button as highlighted in Figure 3.

 Figure 4: Search Results

5) Click on the CommonName Generation plugin as highlighted in Figure 4.
Figure 5: Search Results

6) Modify the value to have com.custom.commonname.CustomCommonNamePolicy as highlighted in the figure and click Save.

3 comments:

Sumanth A R said...

Hi Sir,

We followed all the steps in this link but the common name does not get populated when an user is created, can you please help.

Thanks & Regards,
Sumanth A Raichur

Darren S said...

Thanks, worked first time although our setup means we had to run an ant task to register the plugin rather than just copy it to the plugins directory.

shikida said...

Hi, do I have to restart OIM after registering? And how do I test this? Thx