Monday, February 23, 2015

OIM 11G R2 PS2 (11.1.2.2.0) User Name generation plugin

In this post I will talk about the usage of username generation plugin and how to provide your own custom plugin to generate user login and then how to go about searching a custom user field via oim new api code.


Well to start with OIM generates a user login if no user login is specified. This happens because there is a system property called Default Username Generation plugin  which holds the value of OIM standard class.

Default policy for username generation
= oracle.iam.identity.usermgmt.impl.plugins.DefaultComboPolicy

If you want to override with your custom class then you need to implement
oracle.iam.identity.usermgmt.api.UserNameGenerationPolicy
In your custom class and provide a method named

public String getUserName(Map<String, Object> reqData) throws UserNameGenerationException;

With username generation logic
ReqData contains all the fields that will contains first name last name and other user attribute field

Once your class is developed and jarred
You can create a plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<oimplugins>
<plugins pluginpoint="oracle.iam.identity.usermgmt.api.UserNamePolicy">
<plugin pluginclass="yourfullyqualifiedclassname " version="1.0" name="classname"/>
</plugins>
</oimplugins>

Package the lib/jar and plugin.xml in a plugin.zip and register the plugin

Once the registration is done you will have to modify the system property

Default policy for username generation and specify your custom class name

That's it now the user login will be generated via your custom logic.

Also note that this plugin will run as pre-process event Handler but it does not require import metadata command to be used.

 ---------Sample Implementation --------------------------------------------------------------------

import java.util.Locale;
import java.util.Map;

import oracle.iam.identity.exception.UserNameGenerationException;
import oracle.iam.identity.usermgmt.api.UserManagerConstants;
import oracle.iam.identity.usermgmt.api.UserNameGenerationPolicy;


public class UserIDGeneration implements UserNameGenerationPolicy {

    @Override
    public String getDescription(Locale arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getUserNameFromPolicy(Map<String, String> arg0)
            throws UserNameGenerationException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean isUserNameValid(String arg0, Map<String, String> arg1) {
        // TODO Auto-generated method stub
        return false;
    }
  
    public String createCustomUserGenerationLogic(String firstName, String lastName){
        String userLoginGen = "";
//        put logic here
        return userLoginGen;
    }
  
  
    @Override
    public String getUserName(Map<String, Object> reqData)
            throws UserNameGenerationException {

        String firstName = reqData.get(UserManagerConstants.AttributeName.FIRSTNAME.getId()).toString();
        String lastName = reqData.get(UserManagerConstants.AttributeName.LASTNAME.getId()).toString();
        return createCustomUserGenerationLogic(firstName, lastName);
      
    }

    @Override
    public boolean isGivenUserNameValid(String arg0, Map<String, Object> arg1) {
        // TODO Auto-generated method stub
        return false;
    }

}