OIM 11G R2PS2 / R2PS3 Custom Pre-processor EventHandler Plugin Registration


    1. Write your custom ProcessHandler
            Sample Code :    AccessPreProcessHandler.java
            
     2. Set Classpath using $OIM_ORACLE_HOME/designConsole/lib and Set other jars if you need for your program.
    
     3. Compile Java class from $OIM_ORACLE_HOME/designConsole where you find all Jars
        javac -cp $CLASSPATH com/massiveGaze/provision/AccessPreProcessHandler.java
        
     4. Create Jar file using above .class
        jar -cvf AccessPreProcessHandler.jar com/massiveGaze/provision/AccessPreProcessHandler.class
        
     5. varify the jar file using decompiler.
    
     6. Create Dummy folder say 'plugin' folder and create below files.
            a) plugin.xml
                <oimplugins>
                 <plugins pluginpoint="oracle.iam.platform.kernel.spi.EventHandler">
                 <plugin pluginclass="com.massiveGaze.provision.AccessPreProcessHandler" version="1.0" name="AccessPreProcessHandler"/>
                 </plugins>
                 </oimplugins>
            b) lib
                Move above AccessPreProcessHandler.jar file to lib folder.
                
     7. Create plugin zip file using below command.
            zip -r plugins.zip ./plugin.xml ./lib/AccessPreProcessHandler.jar
            
     8. Export Specific EventHandlers.xml from EM console to specific location.
        Ex:/metadata/iam-features-provisioning/event-definition/EventHandlers.xml 
        Edit/modify action handler by adding the new tag.
            <action-handler class="com.massiveGaze.provision.AccessPreProcessHandler" entity-type="Entitlement" operation="PROVISION" name="AccessPreProcessHandler" stage="preprocess" order="FIRST" sync="TRUE"/>
        Import back to MDS using EM console.
    
     9. Register the plugin.
        From XL_HOME or OIM_ORACLE_HOME/server/plugin_utility edit the ant.properties with below env variables.
            wls.home=
            oim.home=
            login.config=
            mw.home=
            ex:            
                wls.home=$MW_HOME/wlserver_10.3
                oim.home=$OIM_HOME/server
                login.config=$OIM_HOME/designconsole/config/authwl.conf
                mw.home=$MW_HOME
                        
        execute below command    
         ant -f pluginregistration.xml register
            provide identity console userName,Password,Url and location of Zip file.
            Note : Varify jar is exist or not $MW_HOME/wlserver_10.3/server/lib/wlfullclient.jar
                    If not execute command : java -jar wljarbuilder.jar 
                   Set Ant home before executing above commad.                    

     10. Restrat the server
     11. Execute the testcase

Refrence :    
User Modifiable Metadata Files
    http://docs.oracle.com/cd/E27559_01/dev.1112/e27150/uploadutil.htm#OMDEV4859


Check the Oracle Identity Manager Review for other OIM 11g related posts

OIM API - to Set Process Form Data

  1. package com.oimacademy.provision;
  2. import java.util.HashMap;
  3. import com.oimacademy.connection.Platform;
  4. import oracle.iam.provisioning.exception.GenericProvisioningException;
  5. import Thor.API.tcResultSet;
  6. import Thor.API.Exceptions.tcAPIException;
  7. import Thor.API.Exceptions.tcColumnNotFoundException;
  8. import Thor.API.Exceptions.tcFormNotFoundException;
  9. import Thor.API.Exceptions.tcInvalidValueException;
  10. import Thor.API.Exceptions.tcNotAtomicProcessException;
  11. import Thor.API.Exceptions.tcObjectNotFoundException;
  12. import Thor.API.Exceptions.tcOrganizationNotFoundException;
  13. import Thor.API.Exceptions.tcProcessNotFoundException;
  14. import Thor.API.Exceptions.tcProvisioningNotAllowedException;
  15. import Thor.API.Exceptions.tcRequiredDataMissingException;
  16. import Thor.API.Operations.tcFormInstanceOperationsIntf;
  17. import Thor.API.Operations.tcOrganizationOperationsIntf;
  18. public class SetProcessFormData {
  19. public static void main(String[] args) throws tcAPIException, tcInvalidValueException, tcNotAtomicProcessException,
  20. tcFormNotFoundException, tcRequiredDataMissingException, tcProcessNotFoundException,
  21. tcObjectNotFoundException, tcProvisioningNotAllowedException, tcOrganizationNotFoundException, GenericProvisioningException,
  22. tcColumnNotFoundException {
  23. Long actKey=1L;//actKey - You can get it from ACT table.
  24. Long objKey=1L;// objKey - You can get it from OBJ table.
  25. tcOrganizationOperationsIntf tcOrgOp = Platform.getService(tcOrganizationOperationsIntf.class);
  26. long objInsKey = tcOrgOp.provisionObject(actKey, objKey);
  27. tcResultSet rsetAccounts = tcOrgOp.getObjects(actKey);
  28. long processInstanceKey = -1;
  29. for(int i=0; i<rsetAccounts.getRowCount(); i++) {
  30. rsetAccounts.goToRow(i);
  31. if (rsetAccounts.getLongValue("Object Instance.Key") == objInsKey) {
  32. processInstanceKey = rsetAccounts.getLongValue("Process Instance.Key");
  33. if(processInstanceKey == 0 || rsetAccounts.getStringValue("Objects.Object Status.Status").equals("Waiting")){
  34. throw new GenericProvisioningException("Resource in Waiting status");
  35. }
  36. break;
  37. }
  38. }
  39. tcFormInstanceOperationsIntf tcFrmInsOp = Platform.getService(tcFormInstanceOperationsIntf.class);
  40. HashMap<String, String> data = new HashMap<String, String>();
  41. // Resource Form data, All the values in String format.
  42. data.put("UD_OID_OU_SERVER", "5");
  43. data.put("UD_OID_OU_NAME", "actName");
  44. data.put("UD_OID_OU_ORGNAME", "5~ou=sales,cn=Users,dc=us,dc=oracle,dc=com");
  45. tcFrmInsOp.setProcessFormData(processInstanceKey, data);
  46. }
  47. }

OIM Create Entitlements / Populate Entitlements in Catalog Table


    package com.oimacademy.catalog;
    import java.util.List;
    import java.util.ArrayList;
    import com.oimacademy.connection.Platform;
    import oracle.iam.catalog.api.CatalogService;
    import oracle.iam.catalog.vo.Catalog;
    import oracle.iam.catalog.vo.Result;
    import oracle.iam.catalog.vo.MetaData;
    import oracle.iam.platform.utils.vo.OIMType;
    public class CatalogCreate{
     protected CatalogService serviceObj = null;
     public static void main(String[] args) throws Exception{
      CatalogCreate create = new CatalogCreate();
      try {
       create.execute();
      } catch (Exception ex) {
       System.out.println("EXCEPTION: " + ex.getMessage());
       ex.printStackTrace();
      }
      return;
     }
     protected void execute() throws Exception{
      /*
       * output from a create catalog item
       */

      // updateTime: 2018-10-18 17:07:16.0
      // approverUser: nullapprover
      // UserLogin: null
      // approverRoleDisplayName: null
      // certifierUserLogin: null
      // certifierRoleDisplayName: null
      // fulFillMentUserLogin: null
      // fulFillMentRoleDisplayName: null
      // approverRole: null
      // certifierUser: null
      // certfierRole: null
      // fulFillMentUser: null
      // fulFillMentRole: null
      // certifiable: true
      // riskScoreUpdateTime: null
      // itemRisk: 0
      // id: 60
      // entityKey: 1
      // entityType: ApplicationInstance
      // parentEntityKey: null
      // parentEntityType: ApplicationInstance
      // categoryName: ApplicationInstance
      // requestable: true
      // userDefinedTags: null
      // tags: badging Disconnected Badge Access badging badging
      // deleted: false
      // entityName: badging
      // entityDisplayName: Badge Accessentity
      // Description: Badge Access for physical access control
      // auditObjectives: null
      // metadata: []
      // createBy: null
      // updateBy: null
      Result result = null; // OIMClient API 
      List<MetaData> metadata = new ArrayList<MetaData>();
      MetaData mdata = null;
      mdata = new MetaData();
      mdata.setValue("JK");
      metadata.add(mdata);
      mdata = new MetaData();
      mdata.setValue("Test");
      metadata.add(mdata);
      mdata = new MetaData();
      mdata.setValue("foo");
      metadata.add(mdata);
      System.out.println("__BEGIN__");
      /*
       * add the attribute values
       */
      for(int i=0;i < 1050;i++){
       Catalog catalog = new Catalog();
      catalog.setItemRisk(0);
      catalog.setCertifiable(true);
      catalog.setEntityKey("1"); // must match existing resource object
      catalog.setEntityType(OIMType.valueOf("Entitlement"));
      catalog.setParentEntityType(OIMType.valueOf("ApplicationInstance"));
      catalog.setCategoryName("Entitlement");
      catalog.setRequestable(true);
      catalog.setTags("TestEnt");
      catalog.setDeleted(false);
      catalog.setEntityName("Code"+i);
      catalog.setEntityDisplayName("Decode"+i);
      catalog.setEntityDescription("Create catalog item using api");
      catalog.setMetadata(metadata);
      System.out.println("Catalog object created.");
      serviceObj=Platform.getService(CatalogService.class);
      result = serviceObj.addCatalogItems(catalog);
      }
      System.out.println("Creation status: '" + result.isStatusFlag() + "'");
      System.out.println("__END__");
      return;
     }
    }

Deployment Manager Export OIM Categories in XML Format


    package com.oimacademy.export;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.sql.Timestamp;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;
    import oracle.iam.platform.OIMClient;
    import Thor.API.Exceptions.tcAPIException;
    import Thor.API.Operations.tcExportOperationsIntf;
    import com.oimacademy.connection.OIMConnection;
    import com.thortech.xl.ddm.exception.DDMException;
    import com.thortech.xl.vo.ddm.RootObject;
    public class ExportCategoryUtils {
     public static void main(String str[]) throws tcAPIException, DDMException
     {
      try
      {
       java.util.Date date= new java.util.Date();
                String outputFileName = "Export.xml";
       Collection<RootObject> rdbmsRootObjects = null;
       Collection<RootObject> rdbmsRootObjectsChildren = null;
       Collection<RootObject> rdbmsRootObjectsDependency = null;
       Collection<RootObject> rdbmsRootObjectsDependencytree = null;
       Collection<RootObject> allObjects =  new ArrayList();
                FileWriter fstream = new FileWriter(outputFileName);
       BufferedWriter out = new BufferedWriter(fstream);  
       OIMClient oIMConnection = OIMConnection.getConnection();
                           // c.login(username, password.toCharArray());
                 tcExportOperationsIntf exportIntf =  (tcExportOperationsIntf) oIMConnection.getService(Thor.API.Operations.tcExportOperationsIntf.class);
                 int count=0;              
                Collection<String> categories = exportIntf.retrieveCategories();
                Iterator<String> catIter = categories.iterator();
                while (catIter.hasNext()) {
                    System.out.println(" Category : "+ ++count +"  "+catIter.next());
                }
                count=0;
                /*
                 *  eventhandlers
        Process Form
        Organization
        ITResource
        NOTIFICATIONTEMPLATE
        PasswordPolicy
        RequestDataset
        Role and Orgs UDF
        DataObjectDef
        RequestTemplate
        UserGroup
        PrepopAdapter
        Process
        ITResourceDef
        Resource
        OESPolicy
        EmailDef
        TaskAdapter
        SystemProperties
        GenericConnector
        GTCProvider
        Rule
        ApprovalPolicy
        Job
        Lookup
        scheduledTask
        User UDF
        ErrorCode
                 *
                 */
                String exportCategory = "GenericConnector"; // Which Category user needs to Export
                String searchString = "GTC2*"; //matching String else * for All
                System.out.println("------------------------------------------------------------------------");
                System.out.println(" Start Time : " +new Timestamp(date.getTime()));
                System.out.println("------------------------------------------------------------------------");
                System.out.println(" Finding Objects For Category : '"+exportCategory+"'");           
       rdbmsRootObjects = exportIntf.findObjects(exportCategory, searchString);
       rdbmsRootObjects.addAll(exportIntf.findObjects("Job", "GTC2_GTC"));
       if (rdbmsRootObjects == null || rdbmsRootObjects.size() < 1) {
        throw new DDMException("No Rdbms Objects found");
       }
       Iterator<RootObject> rootObjects = rdbmsRootObjects.iterator();
                while (rootObjects.hasNext()) {
                    System.out.println(" Search results : "+ ++count +"  "+rootObjects.next());
                }
                count=0;
       //Get the child objects
       System.out.println(" Getting Child Objects For Parent Object...!");  
       rdbmsRootObjectsChildren = exportIntf.retrieveChildren(rdbmsRootObjects);
                Iterator<RootObject> rdbmsRootObjectsChld = rdbmsRootObjectsChildren.iterator();
                while (rdbmsRootObjectsChld.hasNext()) {
                    System.out.println(" Child Object : "+ ++count + "  "+rdbmsRootObjectsChld.next());
                }
                count=0;
       System.out.println(" Collecting All Child Objects Into List...!");
       allObjects.addAll(rdbmsRootObjectsChildren);  
       //Get the  dependencies
       System.out.println(" Getting Dependency Object...!");
       rdbmsRootObjectsDependency = exportIntf.getDependencies(rdbmsRootObjectsChildren);
       System.out.println(" Processing Please Wait...!");
       for (Iterator iter = rdbmsRootObjectsDependency.iterator(); iter.hasNext();) {
        RootObject child = (RootObject) iter.next();   
        if (!allObjects.contains(child)) {
          System.out.println(" Dependency Child Object : "+ ++count + "  "+child);
         allObjects.add(child);
        }
       }
       //Get the  dependencies tree
       System.out.println(" Creating Object Dependency Tree... !");
       rdbmsRootObjectsDependencytree =exportIntf.retrieveDependencyTree(allObjects);
       //store all the root objects in 'rdbmsRootObjectsDependencytree' object before export takes off..
       System.out.println(" Processing Root Objects Dependency Tree Please Wait...!");
       for (Iterator iter = allObjects.iterator(); iter.hasNext();) {
        RootObject child = (RootObject) iter.next();
        if (!rdbmsRootObjectsDependencytree.contains(child)) {
         rdbmsRootObjectsDependencytree.add(child);
        }
       }
       // Export the XML file
       System.out.println(" Exporting XML File. Please Wait...!");
       String s = exportIntf.getExportXML(rdbmsRootObjectsDependencytree, "*");
       //System.out.println(s);
       //Store it in XML file.
       out.write(s);
       System.out.println(" '"+exportCategory+"' Objects Successfully Exported : " + outputFileName);
       System.out.println(" DM Export Completed...");
       out.close();
       System.out.println("------------------------------------------------------------------------");
       System.out.println(" End Time : " +new Timestamp(new java.util.Date().getTime())); 
       System.out.println("------------------------------------------------------------------------");
      }
      catch(Exception ex)
      {
       System.out.println(ex);
       ex.printStackTrace();
       throw new DDMException(ex.getMessage());
      }
     }
    }

OIM API - LDAP OID/OUD/OVD Connection


    package com.oimacademy.ldap;
    import java.io.FileInputStream;
    import java.util.Hashtable;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.directory.DirContext;
    import javax.naming.directory.InitialDirContext;
    public class LDAPConnection {
     static String oidUrl,oidUserName,oidPassword,userContainer;
        private static final String TEST_PROPERTIES_FILE = "data/ldapsync.properties";
        static{
     System.out.println("Connection Started ");
      try{
       Properties eventProps = new Properties();
       eventProps.load(new FileInputStream(TEST_PROPERTIES_FILE));
         oidUrl = eventProps.getProperty("LDAP.OID.URL");
                 oidUserName = eventProps.getProperty("LDAP.OID.Username");
                 oidPassword = eventProps.getProperty("LDAP.OID.Password");
                 userContainer = eventProps.getProperty("LDAP.UserContainer");
                 System.out.println("oidUrl- > "+oidUrl);
                 System.out.println("oidUserName- > "+oidUserName);
                 System.out.println("userContainer- > "+userContainer);  
      }catch(Exception e){
       System.out.println("Connection Failed With Exception ");
       e.printStackTrace();
      }
    }
     public static DirContext getLDAPConnection() throws Exception {
      Hashtable<String,String> attrs = new Hashtable<String,String>();
            attrs.put(Context.PROVIDER_URL, oidUrl);
            attrs.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
      attrs.put(Context.SECURITY_PRINCIPAL, oidUserName);
      attrs.put(Context.SECURITY_CREDENTIALS, oidPassword);
      DirContext context = new InitialDirContext(attrs);
      return context;
        }
     public static String getUserContainer(){
      return userContainer;
     }
    }

OIM API - to Search DN from OID/OUD/OVD targets


    package com.oimacademy.ldap;
    import javax.naming.NamingEnumeration;
    import javax.naming.directory.Attribute;
    import javax.naming.directory.Attributes;
    import javax.naming.directory.DirContext;
    import javax.naming.directory.SearchControls;
    import javax.naming.directory.SearchResult;
    public class SearchDN {
     static DirContext ctx = null;
     public static void getDNDetails(){
      try {
       ctx = (DirContext) LDAPConnection.getLDAPConnection();
       String SearchCtrlString = "(&(objectclass=inetOrgPerson)(uid=TUSER3))";
       SearchControls controls = new SearchControls();
       controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
       NamingEnumeration results = ctx.search(LDAPConnection.getUserContainer(), SearchCtrlString, controls);
        System.out.println(" Result Has More -> "+results.hasMore());
        String obPasswordExpiryDate=null;
        while (results.hasMore()) {
         SearchResult searchResult = (SearchResult) results.next();
         Attributes attributes = searchResult.getAttributes();
         Attribute attrObPWDExpiry = attributes.get("obpasswordexpirydate");
         if(attrObPWDExpiry==null){
           attrObPWDExpiry=attributes.get("orclpwdexpirationdate");
           System.out.println("******* -> ");
         }
         if(attrObPWDExpiry!=null)
                  obPasswordExpiryDate = (String) attrObPWDExpiry.get(); 
         System.out.println("obPasswordExpiryDate -> "+obPasswordExpiryDate);    
        }
      } catch (Exception e) {
       e.printStackTrace();
       //fail("UnLock user failed : " + e.getCause());
      }
     }
     public static void main(String args[]){
      getDNDetails();
     }
    }

OIM API -Create Password policy,organization to new User and Reset Password and verify update value in target OID/OUD/OVD


    package com.oimacademy.ldap;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Set;
    import javax.naming.NamingEnumeration;
    import javax.naming.directory.Attribute;
    import javax.naming.directory.Attributes;
    import javax.naming.directory.DirContext;
    import javax.naming.directory.SearchControls;
    import javax.naming.directory.SearchResult;
    import com.oimacademy.connection.Platform;
    import com.oimacademy.ldap.LDAPConnection;
    import oracle.iam.identity.orgmgmt.api.OrganizationManager;
    import oracle.iam.identity.orgmgmt.api.OrganizationManagerConstants;
    import oracle.iam.identity.orgmgmt.vo.Organization;
    import oracle.iam.identity.usermgmt.api.UserManager;
    import oracle.iam.identity.usermgmt.vo.User;
    import oracle.iam.identity.usermgmt.vo.UserManagerResult;
    import oracle.iam.identity.utils.Constants;
    import oracle.iam.passwordmgmt.api.PasswordMgmtService;
    import oracle.iam.passwordmgmt.vo.PasswordPolicyInfo;
    public class TestLDAP {
     static PasswordMgmtService passwordmgmtService=Platform.getService(PasswordMgmtService.class);
     static OrganizationManager m_orgManagerService =Platform.getService(OrganizationManager.class);
     static UserManager usrMgmnt = Platform.getService(UserManager.class);
     static DirContext ctx=null;
     /*
      * 
    Create Password Policy
    Create Organization
    Attach Password policy to organization
    Create user under organization
    Update Password Policy
    Reset Password for user
    verify update value in target for changed value.
      *
      */
     public static void main(String[] args) { 
      try {
       new TestLDAP().pwdNeverExpireForPwdPolicyAsExpireDaysAfterIsNull();
      } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
     }
     public void pwdNeverExpireForPwdPolicyAsExpireDaysAfterIsNull() throws Exception {
      //CreatePasswordPolicy
      int i=5;
      ctx = (DirContext) LDAPConnection.getLDAPConnection();
      String policyName = "PasswordPolicy9"+i ;
            PasswordPolicyInfo passPolicyInfo = new PasswordPolicyInfo();
            passPolicyInfo.setName(policyName);
            passPolicyInfo.setShortDesc(policyName + " description");
            passPolicyInfo.setPasswordExpiresAfterInDays(90);
            passPolicyInfo.setPriority(10000);           
            PasswordPolicyInfo searchPassPolicyInfo = new PasswordPolicyInfo();
            passPolicyInfo = passwordmgmtService.create(passPolicyInfo);       
            searchPassPolicyInfo = passwordmgmtService.getDetails(passPolicyInfo.getName()); 
            System.out.println("Password Policy Created with id "+passPolicyInfo.getId());      
            System.out.println(" Search Password Policy Created with id "+searchPassPolicyInfo.getId());     
            //Create Organization
      Organization org = new Organization();
      org.setAttribute("Organization Name", "myorg"+i);
      org.setAttribute("Organization Customer Type", "Department");
      org.setAttribute("Organization Status", "Active"); 
      String orgKey = m_orgManagerService.create(org);
      System.out.println("Organization Created with ID "+orgKey);
            //Update Organization With PasswordPolicy Key
         HashMap<String, Object> updateAttributes = new HashMap<String, Object>();
         updateAttributes.put(OrganizationManagerConstants.AttributeName.ORG_PASSWORD_POLICY_KEY.getId(),passPolicyInfo.getId());
         orgKey= m_orgManagerService.modify(new Organization(orgKey,updateAttributes));
         System.out.println(" Modified Organization Adding Password Policy for Org ID "+orgKey);
            //CreateUser with Above Created Organization
         HashMap<String, Object> createAttributes = new HashMap<String, Object>();
      String userId =""+i;
         createAttributes.put(Constants.USERID, "TUSER" + userId);
      createAttributes.put(Constants.FIRSTNAME, "TEST" + userId);
      createAttributes.put(Constants.LASTNAME, "USER" + userId);
      createAttributes.put(Constants.ORGKEY, Long.parseLong(orgKey));
      createAttributes.put(Constants.PASSWORD, "Welcome1");
      createAttributes.put(Constants.EMAIL, "TUSER" + userId+ "@oracle.com");
      createAttributes.put(Constants.EMPTYPE, "Full-Time");
      createAttributes.put(Constants.USERTYPE,"End-User Administrator");   
      UserManagerResult result = usrMgmnt.create(new User(null,createAttributes));
         //Update setPasswordExpiresAfterInDays to Null for Password Never Expire
      System.out.println(" User Created with ID "+   result.getEntityId());
      PasswordPolicyInfo passPolicyObjAsNull = new PasswordPolicyInfo();
      passPolicyObjAsNull.setPasswordExpiresAfterInDays(null);
      passPolicyObjAsNull.setName("PasswordPolicy9"+i);
      passwordmgmtService.update(passPolicyObjAsNull);
      System.out.println(" Updated Password Policy to Null  ");
       //Change Password to Update USR_PWD_EXPIRE_DATE Column 
      usrMgmnt.changePassword(result.getEntityId(),"Pass_12345".toCharArray() , false);
      System.out.println(" Chnaged User Password for User +  "+result.getEntityId());
      //get USR_PWD_EXPIRE_DATE value
      Set<String> searchAttrs = new HashSet<String>(); 
      searchAttrs.add("First Name");
      searchAttrs.add("Last Name"); 
      searchAttrs.add("usr_pwd_expire_date");
      User userLookup = usrMgmnt.getDetails(result.getEntityId(), searchAttrs, false);
      String usr_pwd_expire_date=(String)userLookup.getAttributes().get("usr_pwd_expire_date");
      System.out.println(" usr_pwd_expire_date  From DB ->  "+usr_pwd_expire_date);
      //Get LDAP Attributes for the created User.
      String SearchCtrlString = "(&(objectclass=inetOrgPerson)(uid="+"TUSER" + userId + "))";
      SearchControls controls = new SearchControls();
      controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
      NamingEnumeration results = ctx.search(LDAPConnection.getUserContainer(), SearchCtrlString, controls);
      String obPasswordExpiryDate=null;
      while (results.hasMore()) {
       SearchResult searchResult = (SearchResult) results.next();
       Attributes attributes = searchResult.getAttributes();
       Attribute attrObPWDExpiry = attributes.get("obpasswordexpirydate");
       if(attrObPWDExpiry==null){
        System.out.println(" attrObPWDExpiry is NUll   ");
         attrObPWDExpiry=attributes.get("orclpwdexpirationdate");
       }
       if(attrObPWDExpiry!=null)
                obPasswordExpiryDate = (String) attrObPWDExpiry.get();  
       System.out.println(" obPasswordExpiryDate is    "+obPasswordExpiryDate);
       System.out.println(" usr_pwd_expire_date is "+usr_pwd_expire_date);
      }
      /*usrMgmnt.delete(result.getEntityId(), false);
         m_orgManagerService.delete(orgKey, false);
            passwordmgmtService.delete(policyName);*/
     }
    }

OIM API -How to Find LookUp Values in OIM

package com.oimacademy.lookup;
import Thor.API.tcResultSet;
import Thor.API.tcUtilityFactory;
import Thor.API.Operations.tcLookupOperationsIntf;
import com.oimacademy.connection.OIMConnection;
import com.oimacademy.util.OIMUtils;
public class FindLookupValues {
 public static void main(String[] args) throws Exception {
  String lookupCode = "Lookup.OID.Group";
  tcUtilityFactory factory = new tcUtilityFactory(OIMConnection.getEnvironment(), "xelsysadm","Welcome1");
  tcLookupOperationsIntf lookupIntf = (tcLookupOperationsIntf) factory.getUtility("Thor.API.Operations.tcLookupOperationsIntf");
  tcResultSet rs = lookupIntf.getLookupValues(lookupCode);
  OIMUtils.printResultSet(rs); 
  factory.close();
  System.exit(0);
 }
}

Another way using SQL query :
package com.oimacademy.lookup;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import com.oimacademy.connection.DataSource;
    public class GetLookUpValues {
    public List getLookupCodes(String lkvKey){
      List list = new ArrayList();
      Connection con = DataSource.getConnection();
      try {
       Statement stmt = con.createStatement();
       String query ="select * from LKV where lku_key="+lkvKey;
       ResultSet rs = stmt.executeQuery(query);
       while (rs.next()) {
        list.add(rs.getString("lkv_encoded"));
       }
      } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      System.out.println("Size"+ list.size());
      return list;
     }
     public static void main(String[] args) throws Exception {
      System.out.println(new GetLookUpValues().getLookupCodes("1592"));   
     }
    }

OIM API - to Updating Access Policy Form Data


    package com.oimacademy.provision;
    import java.util.HashMap;
    import java.util.Map;
    import com.oimacademy.connection.Platform;
    import Thor.API.tcResultSet;
    import Thor.API.Exceptions.tcAPIException;
    import Thor.API.Exceptions.tcColumnNotFoundException;
    import Thor.API.Exceptions.tcFormNotFoundException;
    import Thor.API.Exceptions.tcInvalidValueException;
    import Thor.API.Exceptions.tcNotAtomicProcessException;
    import Thor.API.Exceptions.tcProcessNotFoundException;
    import Thor.API.Exceptions.tcRequiredDataMissingException;
    import Thor.API.Operations.tcFormInstanceOperationsIntf;
    public class UpdatingAccessPolicyFormData {
     public static void main(String[] args) throws tcAPIException, tcNotAtomicProcessException, tcFormNotFoundException, tcProcessNotFoundException, tcInvalidValueException, tcRequiredDataMissingException{
       tcFormInstanceOperationsIntf formInstanceIntf = Platform.getService(tcFormInstanceOperationsIntf.class);  
       long processInstanceKey= 793L;
         tcResultSet trs = formInstanceIntf.getProcessFormData(processInstanceKey);
         int count=trs.getRowCount();
         for(int i=0;i<count;i++){
                         trs.goToRow(i);     
                 String columnNames[] = trs.getColumnNames();
                 for (String string : columnNames)
                 {
                     try {
                         System.out.println(string + " - " + trs.getStringValue(string));
                     } catch (tcAPIException | tcColumnNotFoundException e)
                    {
                         e.printStackTrace();
                     }
                 }
          }    
         // Updating the For Column.
         String adColumnName="UD_ADUSER_ZIP";
         Map updateData=new HashMap();
         updateData.put(adColumnName, "1234");
         formInstanceIntf.setProcessFormData(processInstanceKey, updateData);
     }
    }

OIM API - to Get Process Instance Key


  1. package com.oimacademy.provision;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import com.oimacademy.connection.Platform;
  5. import Thor.API.tcResultSet;
  6. import Thor.API.Exceptions.tcAPIException;
  7. import Thor.API.Exceptions.tcColumnNotFoundException;
  8. import Thor.API.Exceptions.tcUserNotFoundException;
  9. import Thor.API.Operations.tcUserOperationsIntf;
  10. public class GetProcessInstanceKey {
  11.  public static void main(String[] args) throws tcAPIException, tcUserNotFoundException, tcColumnNotFoundException {  
  12.   tcUserOperationsIntf userOperationsIntf=Platform.getService(tcUserOperationsIntf.class);   
  13.   long userKey=1004L; 
  14.   Map<String,Long> resources= new HashMap<String,Long>();
  15.                   tcResultSet trs= userOperationsIntf.getObjects(userKey);
  16.                   if(trs != null)
  17.                   {
  18.                       int count=trs.getRowCount();
  19.                       for(int i=0;i<count;i++)
  20.                       {
  21.                           trs.goToRow(i);
  22.                           String objectName=trs.getStringValue("Objects.Name");
  23.                           String status=trs.getStringValue("Objects.Object Status.Status");

  24.                           if(status.equalsIgnoreCase("Provisioned") || status.equalsIgnoreCase("Enabled"))
  25.                           {
  26.                               resources.put(objectName,trs.getLongValue("Process Instance.Key"));
  27.                           }
  28.                       }
  29.                   }
  30.                   System.out.println("resources -> "+resources);
  31.  }
  32. }

API to Deserialize ORCHPROCESS table data


  1. package com.oimacademy.orchestration;
  2. import java.io.InputStream;
  3. import java.io.ObjectInputStream;
  4. import java.io.Serializable;
  5. import java.sql.Connection;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.ResultSetMetaData;
  9. import java.util.HashMap;
  10. import java.util.Iterator;
  11. import java.util.Map.Entry;
  12. import java.util.Set;
  13. import oracle.iam.platform.context.ContextAwareNumber;
  14. import oracle.iam.platform.context.ContextAwareString;
  15. import oracle.iam.platform.kernel.vo.EntityOrchestration;
  16. import oracle.iam.platform.kernel.vo.Orchestration;
  17. import oracle.iam.platform.kernel.vo.PostProcessOnlyBulkOrchestration;
  18. import com.oimacademy.connection.DataSource;
  19. public class DeserializeOrchestration {
  20.  public static void main(String[] args) throws Exception {
  21.   String statement1 = "select * from orchprocess where id=?";  
  22.   // String statement =
  23.   // "select id, orchestration from orchprocess where entitytype='User' and operation='CREATE' order by id";
  24.   // String statement =
  25.   // "select orchestration from orchprocess where id in (select processid from orchevents where name='UserModifyLDAPPreProcessHandler' and status='FAILED') order by id desc";
  26.   Connection conn = DataSource.getConnection();
  27.   System.out.println("Something");
  28.   // Read object from oracle
  29.   PreparedStatement pstmt = conn.prepareStatement(statement1);
  30.   pstmt.setLong(1, 138);
  31.   ResultSet rs = pstmt.executeQuery();
  32.   dumpRS(rs);
  33.   rs.close();
  34.   pstmt.close();
  35.   conn.close();
  36.   System.exit(0);
  37.  }
  38.  public static void dumpRS(ResultSet rs) throws Exception {
  39.   InputStream is = null;
  40.   ObjectInputStream oip = null;
  41.   rs.next();
  42.   ResultSetMetaData rsmd = rs.getMetaData();
  43.   for (int i = 0; i < rsmd.getColumnCount(); i++) {
  44.    String colName = rsmd.getColumnName(i + 1);
  45.    if (colName.equalsIgnoreCase("orchestration")) {
  46.     // is = rs.getBlob(1).getBinaryStream();
  47.     is = rs.getBinaryStream(colName);
  48.     oip = new ObjectInputStream(is);
  49.     Object o = oip.readObject();
  50.     if (o instanceof PostProcessOnlyBulkOrchestration) {
  51.      PostProcessOnlyBulkOrchestration object = (PostProcessOnlyBulkOrchestration) o;
  52.      System.out.println("Operation = " + object.getOperation());
  53.      System.out.println("Target = " + object.getTarget());
  54.      System.out.println("Action Result = " + object.getActionResult());
  55.      System.out.println("Context value = " + object.getContextVal());
  56.      printMap("Bulk Parameters: ", object.getBulkParameters());
  57.      printMap("Parameters: ", object.getParameters());
  58.      printMap("Inter event data: ", object.getInterEventData());
  59.     } else if (o instanceof EntityOrchestration) {
  60.      EntityOrchestration object = (EntityOrchestration) o;
  61.      System.out.println("EntityID = " + object.getEntityId());
  62.      System.out.println("EntityType = " + object.getEntityType());
  63.      System.out.println("Type = " + object.getType());
  64.      System.out.print("All Entity IDs: ");
  65.      for (int j = 0; j < object.getAllEntityId().length; j++) {
  66.       System.out.print(object.getAllEntityId()[j]);
  67.      }
  68.      System.out.println();
  69.     } else if (o instanceof Orchestration) {
  70.      Orchestration object = (Orchestration) o;
  71.      System.out.println("Operation = " + object.getOperation());
  72.      System.out.println("Target = " + object.getTarget());
  73.      // System.out.println("Action Result = " +
  74.      // object.getActionResult());
  75.      System.out.println("Context value = "+ object.getContextVal());
  76.      // printMap("Bulk Parameters: ",
  77.      // object.getBulkParameters());
  78.      printMap("Parameters: ", object.getParameters());
  79.      printMap("Inter event data: ", object.getInterEventData());
  80.     } else {
  81.      System.out.println("UNKNOWN ORCHESTRATION BLOB");
  82.     }
  83.    } else {
  84.     System.out.println(colName + " ===> " + rs.getString(colName));
  85.    }
  86.   }
  87.   oip.close();
  88.   is.close();
  89.  }
  90.  public static void printMap(String name,
  91.    HashMap<String, Serializable>[] marr) {
  92.   System.out.println("Dumping maps name = " + name);
  93.   for (int i = 0; i < marr.length; i++) {
  94.    System.out.println("Map element # " + i);
  95.    HashMap<String, Serializable> m = marr[i];
  96.    if (m == null) {
  97.     System.out.println("Null Map found");
  98.     continue;
  99.    }
  100.    Set<Entry<String, Serializable>> set = m.entrySet();
  101.    Iterator<Entry<String, Serializable>> it = set.iterator();
  102.    while (it.hasNext()) {
  103.     Entry<String, Serializable> e = it.next();
  104.     Object val = (Object) e.getValue();
  105.     String v = "";
  106.     if (val instanceof ContextAwareString) {
  107.      ContextAwareString cas = (ContextAwareString) val;
  108.      v = (String) cas.getObjectValue();
  109.     } else if (val instanceof ContextAwareNumber) {
  110.      ContextAwareNumber can = (ContextAwareNumber) val;
  111.      v = String.valueOf(((Long) can.getObjectValue()));
  112.     } else {
  113.      v = val.toString();
  114.     }
  115.     System.out.println("\t" + e.getKey() + " ---> " + v);
  116.    }
  117.   }
  118.  }
  119.  public static void printMap(String name, HashMap<String, Serializable> m) {
  120.   System.out.println("Dumping maps name = " + name);
  121.   if (m == null) {
  122.    System.out.println("Null Map found");
  123.    return;
  124.   }
  125.   Set<Entry<String, Serializable>> set = m.entrySet();
  126.   Iterator<Entry<String, Serializable>> it = set.iterator();
  127.   while (it.hasNext()) {
  128.    Entry<String, Serializable> e = it.next();
  129.    Object val = (Object) e.getValue();
  130.    String v = "";
  131.    if (val instanceof ContextAwareString) {
  132.     ContextAwareString cas = (ContextAwareString) val;
  133.     v = (String) cas.getObjectValue();
  134.    } else if (val instanceof ContextAwareNumber) {
  135.     ContextAwareNumber can = (ContextAwareNumber) val;
  136.     v = String.valueOf(((Long) can.getObjectValue()));
  137.    } else {
  138.     v = val.toString();
  139.    }
  140.    System.out.println("\t" + e.getKey() + " ---> " + v);
  141.   }
  142.  } 
  143. }

API to get Orchestration Event Exception from ORCHEVENTS table


  1. package com.oimacademy.orchestration;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ObjectInputStream;
  4. import java.sql.Connection;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7. import com.oimacademy.connection.DataSource;
  8. public class DumpOrchEventException {
  9.  public static void main(String[] args) throws Exception {
  10.   long orchEventKey = 10;
  11.   // Connect to the database  
  12.   Connection con = DataSource.getConnection();    
  13.   Statement stmt = con.createStatement();
  14.   String query = "select id, name, status, result from orchevents where id="
  15.     + orchEventKey;
  16.   ResultSet rs = stmt.executeQuery(query);
  17.   while (rs.next()) {
  18.    System.out.println("id = " + rs.getString("id"));
  19.    System.out.println("name = " + rs.getString("name"));
  20.    System.out.println("status = " + rs.getString("status"));
  21.    ByteArrayInputStream bais = new ByteArrayInputStream(
  22.      rs.getBytes("result"));
  23.    ObjectInputStream oip = new ObjectInputStream(bais);
  24.    Object o = oip.readObject();
  25.    Exception ex = (Exception) o;
  26.    ex.printStackTrace();
  27.    System.out.println("****************"+ex.getMessage());
  28.   }
  29.   stmt.close();
  30.   rs.close();
  31.   con.close();
  32.   System.exit(0);
  33.  }
  34. }

OIM Custom Pre Processor Add Email Plugin API


  1. package com.oimacademy.PluginAPIs;
  2. import java.io.Serializable;
  3. import java.util.HashMap;
  4. import oracle.iam.platform.kernel.spi.PreProcessHandler;
  5. import oracle.iam.platform.kernel.vo.AbstractGenericOrchestration;
  6. import oracle.iam.platform.kernel.vo.BulkEventResult;
  7. import oracle.iam.platform.kernel.vo.BulkOrchestration;
  8. import oracle.iam.platform.kernel.vo.EventResult;
  9. import oracle.iam.platform.kernel.vo.Orchestration;
  10. public class CustomPreprocessorAddEmail implements PreProcessHandler {
  11.     public EventResult execute(long processId, long eventId, Orchestration orchestration) {
  12.         HashMap < String, Serializable > orchParameters = orchestration.getParameters();
  13.         System.out.println("Orchestration Process Id  : " + processId);
  14.         System.out.println("Orchestration Event Id : " + eventId);
  15.         String operation = orchestration.getOperation();
  16.         System.out.println("Orchestration Operation : " + operation);
  17.         System.out.println("Orchestration Parameters : " + orchestration.toString());
  18.         String userKey = orchestration.getTarget().getEntityId();
  19.         System.out.println(" user user key will be: " + userKey);
  20.         String email = (String) orchParameters.get("Email");
  21.         String firstName = (String) orchParameters.get("Firstname");
  22.         String lastName = (String) orchParameters.get("Lastname");
  23.         EventResult eResult = new EventResult();
  24.         if ((email == null) || (email.isEmpty())) {
  25.             System.out.println("Email found as Empty.");
  26.             System.out.println("Setting Email to FirstName.LastName");
  27.             orchestration.addParameter("Email", firstName + "." + lastName + "@abc.com");
  28.         }
  29.         return eResult;
  30.     }
  31.     public BulkEventResult execute(long l, long l1, BulkOrchestration bo) {
  32.         throw new UnsupportedOperationException("Not supported yet.");
  33.         }
  34.     public boolean cancel(long l, long l1, AbstractGenericOrchestration ago) {
  35.         return false;
  36.     }
  37.     public void initialize(HashMap < String, String > hm) {}
  38.     public void compensate(long l, long l1, AbstractGenericOrchestration ago) {}
  39. }

OIM API to Decryption Password


  1. package com.oimacademy.password;
  2. import Thor.API.Security.XLClientSecurityAssociation;
  3. import com.oimacademy.connection.OIMConnection;
  4. import com.thortech.xl.dataaccess.tcDataBaseClient;
  5. import com.thortech.xl.dataaccess.tcDataProvider;
  6. import com.thortech.xl.dataaccess.tcDataSet;
  7. import com.thortech.xl.dataaccess.tcDataSetException;
  8. import java.util.Hashtable;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. /**
  12.  * This class gets the OIM Client and uses that to establish a
  13.  * connection to the OIM Schema. You can query the USR table and
  14.  * get the password in plain text. 
  15.  * NOTE: The administrator credential must be used for the OIM Client. 
  16.  */
  17. public class DecryptedOIMPassword 
  18. {
  19.     public static void main(String[] args)
  20.     {
  21.         tcDataProvider dbProvider = null;
  22.         try
  23.         { 
  24.             XLClientSecurityAssociation.setClientHandle(OIMConnection.getConnection());//Needed for database client
  25.             dbProvider = new tcDataBaseClient(); //Connection to OIM Schema
  26.             tcDataSet dataSet = new tcDataSet(); //Stores the result set of an executed query
  27.             String query = "SELECT * FROM USR"; //Query Users table
  28.             //String query = "SELECT * FROM PCQ"; //Query Users Challenge Question
  29.             dataSet.setQuery(dbProvider, query); //Set query and database provider
  30.             dataSet.executeQuery(); //execute query and store results into dataSet object
  31.             int records = dataSet.getTotalRowCount(); //Get total records from result set 
  32.             for(int i = 0; i < records; i++)
  33.             {
  34.                 dataSet.goToRow(i); //move pointer to next record
  35.                 String plainTextPassword = dataSet.getString("USR_PASSWORD");
  36.                 String userLogin = dataSet.getString("USR_LOGIN");
  37.                 String userStatus = dataSet.getString("USR_STATUS");
  38.                 System.out.printf("User Login: %s\nStatus: %s\nPassword: %s\n\n", userLogin, userStatus, plainTextPassword);   
  39.                 //Getting user challenge questions and answers
  40.                 //String usrKey = dataSet.getString("USR_KEY");
  41.                 //String question = dataSet.getString("PCQ_QUESTION");
  42.                 //String answer = dataSet.getString("PCQ_ANSWER");
  43.                 //System.out.printf("USR_KEY: %s\nQuestion: %s\nAnswer: %s\n", usrKey, question, answer);
  44.             }
  45.         }  
  46.         catch (tcDataSetException ex) 
  47.         { 
  48.       Logger.getLogger(DecryptedOIMPassword.class.getName()).log(Level.SEVERE, null, ex);
  49.         }
  50.         finally
  51.         {
  52.             //close connections
  53.             try{dbProvider.close();} catch(Exception e){}
  54.             try{XLClientSecurityAssociation.clearThreadLoginSession();} catch(Exception e){}
  55.            
  56.         }     
  57.     }//end main method   
  58. }//end class

OIM Reset Password As Xelsysadmin API


  1. package com.oimacademy.password;

  2. import oracle.iam.identity.exception.NoSuchUserException;
  3. import oracle.iam.identity.exception.UserManagerException;
  4. import oracle.iam.identity.usermgmt.api.UserManager;
  5. import oracle.iam.platform.authz.exception.AccessDeniedException;
  6. import com.oimacademy.connection.Platform;
  7. public class ResetPasswordAsXelsysadmin { 
  8.  public static void resetPassword(String userKey) throws NoSuchUserException, UserManagerException, AccessDeniedException{
  9.   UserManager userManager = (UserManager) Platform.getService(UserManager.class); 
  10.   userManager.changePassword(userKey,"Pass_12345".toCharArray() , false);  
  11.  }
  12.  public static void main(String[] args) throws NoSuchUserException, UserManagerException, AccessDeniedException {
  13.   resetPassword("11021");
  14.  }
  15. }

OIM Change Password API


  1. package com.oimacademy.password;
  2. import oracle.iam.identity.usermgmt.api.UserManager;
  3. import com.oimacademy.connection.Platform;
  4. public class Changepassword{
  5.   @SuppressWarnings("deprecation")
  6. public static void main(String[] args) throws Exception {
  7.        UserManager userManager = (UserManager)Platform.getService(UserManager.class);
  8.       try {
  9.         System.out.println("Changing the password to blank value");
  10.       userManager.changePassword("TUSER4", "Welcome1".toCharArray(), true);
  11.       //  userManager.changePassword("TESTUSER1", pwd.toCharArray(), true);
  12.         System.out.println("Changing the password done...");
  13.       } catch (Exception e) {
  14.         e.printStackTrace();
  15.         throw e;
  16.       }
  17.       System.out.println("Done");    
  18.   }
  19. }

OIM Delete Password Policy API


  1. package com.oimacademy.password;
  2. import com.oimacademy.connection.OIMConnection;
  3. import oracle.iam.passwordmgmt.api.PasswordMgmtService;
  4. import oracle.iam.passwordmgmt.vo.PasswordPolicyInfo;
  5. public class DeletePasswordPolicy {
  6.  static PasswordMgmtService passwordmgmtService = OIMConnection.getConnection().getService(PasswordMgmtService.class);
  7.  public static void main(String[] args) throws Exception {
  8.   // TODO Auto-generated method stub 
  9.   deletePolicy("PasswordPolicy90");
  10.  }
  11.  public static void deletePolicy(String name){
  12.   // passwordmgmtService.delete(name) ;
  13.   PasswordPolicyInfo passPolicyInfo = new PasswordPolicyInfo();
  14.      passPolicyInfo.setPasswordExpiresAfterInDays(null);
  15.   passPolicyInfo.setName("PasswordPolicy1");
  16.   passwordmgmtService.update(passPolicyInfo);
  17.    passPolicyInfo=passwordmgmtService.getDetails(passPolicyInfo.getName());
  18.    System.out.println(passPolicyInfo.getId());
  19.    System.out.println(passPolicyInfo.getPasswordExpiresAfterInDays());
  20.  }
  21. }

OIM Auto Generate Password API


  1. package com.oimacademy.password;
  2. import java.util.logging.Logger;
  3. import oracle.iam.identity.exception.NoSuchUserException;
  4. import oracle.iam.identity.exception.UserManagerException;
  5. import oracle.iam.identity.usermgmt.api.UserManager;
  6. import oracle.iam.platform.authz.exception.AccessDeniedException;
  7. import com.oimacademy.connection.Platform;
  8. public class AutoGeneratePassword {
  9.  private static Logger logger = Logger.getLogger("MASSIVEGAZE.DEMO");
  10.  public AutoGeneratePassword() {
  11.   }
  12.  public static void main(String[] args) throws NoSuchUserException, UserManagerException, AccessDeniedException {
  13.   autoResetMethod();
  14.  }
  15.  public static void autoResetMethod() throws NoSuchUserException,
  16.    UserManagerException, AccessDeniedException {
  17.   String userLogin = "TUSER";
  18.   UserManager userManager = (UserManager) Platform.getService(UserManager.class);
  19.   userManager.resetPassword(userLogin, true, true);
  20.   System.out.println("Password for user " + userLogin    + " has been reset successfully!");
  21.  }
  22. }

OIM Create Password Policy API


  1. package com.oimacademy.password;
  2. import com.oimacademy.connection.OIMConnection;
  3. import oracle.iam.passwordmgmt.api.PasswordMgmtService;
  4. import oracle.iam.passwordmgmt.vo.PasswordPolicyInfo;
  5. public class PasswordPolicy {
  6.  static PasswordMgmtService passwordmgmtService = OIMConnection.getConnection().getService(PasswordMgmtService.class);
  7.  public static void main(String[] args) throws Exception {
  8.   // TODO Auto-generated method stub
  9.   passwordPolicyCreate();
  10.   //deletePolicy("PasswordPolicy90");
  11.  } 
  12.  public static String passwordPolicyCreate() throws Exception {
  13.   //Create Password Policy
  14.         String name = "PasswordPolicy1" ; 
  15.         PasswordPolicyInfo passPolicyInfo = new PasswordPolicyInfo();
  16.         passPolicyInfo.setName(name);
  17.         passPolicyInfo.setShortDesc(name + " description");
  18.         passPolicyInfo.setPasswordExpiresAfterInDays(90);               
  19.         PasswordPolicyInfo searchPassPolicyInfo = new PasswordPolicyInfo();
  20.         passPolicyInfo = passwordmgmtService.create(passPolicyInfo);        
  21.         searchPassPolicyInfo = passwordmgmtService.getDetails(passPolicyInfo.getName());                 
  22.         System.out.println("Password Policy Key -> " +passPolicyInfo.getId()) ;
  23.         System.out.println("Search Password Policy Key -> "+searchPassPolicyInfo.getId()) ;  
  24.         System.out.println("getPasswordExpiresAfterInDays - >"+passPolicyInfo.getPasswordExpiresAfterInDays());
  25.         return passPolicyInfo.getId();
  26.  } 
  27.  public static void deletePolicy(String name){
  28.   // passwordmgmtService.delete(name) ;
  29.   PasswordPolicyInfo passPolicyInfo = new PasswordPolicyInfo();
  30.      passPolicyInfo.setPasswordExpiresAfterInDays(null);
  31.   passPolicyInfo.setName("PasswordPolicy1");
  32.   passwordmgmtService.update(passPolicyInfo);
  33.    passPolicyInfo=passwordmgmtService.getDetails(passPolicyInfo.getName());
  34.    System.out.println(passPolicyInfo.getId());
  35.    System.out.println(passPolicyInfo.getPasswordExpiresAfterInDays());
  36.  }
  37. }


OIM API for Authenticated SelfService Reset Password


  1. package com.oimacademy.password;
  2. import java.util.HashMap;
  3. import oracle.iam.identity.usermgmt.api.UserManagerConstants;
  4. import oracle.iam.platform.context.ContextManager;
  5. import oracle.iam.selfservice.self.selfmgmt.api.AuthenticatedSelfService;
  6. import com.oimacademy.connection.Platform;
  7. public class AuthenticatedSelfServiceResetPassword {  
  8.   private AuthenticatedSelfService m_authselfservice = Platform.getService(AuthenticatedSelfService.class);
  9.  public static void main(String[] args) {
  10.   try {
  11.    new AuthenticatedSelfServiceResetPassword().changePassword();
  12.   } catch (Exception e) {
  13.    // TODO Auto-generated catch block
  14.    e.printStackTrace();
  15.   }
  16.  }
  17. public void changePassword() throws Exception { 
  18.         String oldpwd ="Welcome1";
  19.         String newpwd = "Welcome2";
  20.         String confirmpwd = "Welcome2";
  21.   
  22. /*        UserManager userManager = platform.getService(UserManager.class);
  23.         HashMap<String, Object> createAttrsMap = new HashMap<String, Object>();
  24.        // createAttrsMap = utility.getAttributesInMap(m_authUserProps, "CREATE.createAttributes");
  25.         createAttrsMap.put("User Login", "TUSER10");
  26.         createAttrsMap.put("First Name", "TEST10");
  27.         createAttrsMap.put("Last Name", "USER10");
  28.         createAttrsMap.put("act_key", "1");
  29.         createAttrsMap.put("usr_password", "Welcome1");
  30.         createAttrsMap.put("Xellerate Type", "End-User");
  31.         createAttrsMap.put("Role","Full-Time");
  32.         long actkey = Long.parseLong(createAttrsMap.get("act_key").toString());     
  33.         createAttrsMap.put("act_key", actkey);
  34.         createAttrsMap.put(UserManagerConstants.AttributeName.PASSWORD.getId(), oldpwd.toCharArray());
  35.         createAttrsMap.put("Start Date", new java.util.Date());  
  36.         createAttrsMap.put("Email", "TEST.USER10@oracle.com");
  37.         UserManagerResult result = userManager.create(new User(null,createAttrsMap));
  38.         System.out.println("ENTITYID = " + result.getEntityId());        
  39.         String usrKey = result.getEntityId();*/
  40.        // setUserInContext("TUSER2", "6");
  41.         System.out.println("###################"+ContextManager.getOIMUser());       
  42.         try {           
  43.             //Attempt to change password 
  44.             m_authselfservice.changePassword(oldpwd.toCharArray(),newpwd.toCharArray(),confirmpwd.toCharArray());
  45.             //m_authselfservice.changePassword("10981", "Pass_12345".toCharArray(),false);  
  46.             ContextManager.clearContext();
  47.             System.out.println("###### PASSWORD UPDATED #############");             
  48.         } catch (Exception e) {
  49.             e.printStackTrace();            
  50.          } finally {
  51.            
  52.              ContextManager.clearContext();
  53.             }
  54.     }
  55.   public void setUserInContext(String userName, String userKey){
  56.       if(ContextManager.getContext() != null) {
  57.       ContextManager.popContext();
  58.     }
  59.     ContextManager.pushContext(null, null, null);
  60.     HashMap<String,String> map = new HashMap<String,String>();
  61.     map.put(UserManagerConstants.AttributeName.USER_KEY.getId(), userKey);
  62.     ContextManager.setOIMUser(userName);
  63.     ContextManager.setUserDetails(map);    
  64.   }
  65. }

OIM Create Bulk Organizations API


  1. package com.oimacademy.org;
  2. import java.util.Calendar;
  3. import oracle.iam.identity.orgmgmt.api.OrganizationManager;
  4. import oracle.iam.identity.orgmgmt.vo.Organization;
  5. import com.oimacademy.connection.Platform;
  6. import oracle.iam.platform.authopss.vo.AdminRole;
  7. import oracle.iam.platform.authopss.vo.AdminRoleMembership;
  8. import oracle.iam.platformservice.api.AdminRoleService;
  9. public class CreateOrganizations { 
  10.  protected static OrganizationManager m_orgManagerService ;
  11.   public static int getRandomNumber() {
  12.          java.util.Random r = new java.util.Random(Calendar.getInstance()
  13.                  .getTimeInMillis());
  14.          int randint = Math.abs(r.nextInt()) % 1000;     
  15.          return randint;
  16.      }
  17.  public static String createorg() throws Exception {
  18.   m_orgManagerService = (OrganizationManager) Platform.getService(OrganizationManager.class);
  19.   String result=null;
  20.   Organization org = new Organization();
  21.   for(int i=1; i< 1000;i++){
  22.   org.setAttribute("Organization Name", "TEST_ORG_"+i);
  23.   org.setAttribute("Organization Customer Type", "System");
  24.   org.setAttribute("Organization Status", "Active");  
  25.   result = m_orgManagerService.create(org);     
  26.   System.out.println("Organization   Key : " + result);   
  27.         AdminRoleService arsi = Platform.getService(AdminRoleService.class);  
  28.   AdminRole ar= arsi.getAdminRole("OrclOIMUserViewer");
  29.         AdminRoleMembership arm = new AdminRoleMembership("5", ar, result, true);
  30.         arsi.addAdminRoleMembership(arm);
  31.         AdminRole ar1= arsi.getAdminRole("OrclOIMOrgAdministrator");
  32.         AdminRoleMembership arm1 = new AdminRoleMembership("5", ar1, result, true);
  33.         arsi.addAdminRoleMembership(arm1);
  34.         System.out.println("done"+i);                
  35.   }
  36.   System.out.println("Done");
  37.   //System.out.println("Updated Password with key "+updateOrgPasswordPolicy(result));
  38.   return result; 
  39.  } 
  40.  public static void main(String[] args) throws Exception {
  41.   CreateOrganizations createorgObj = new CreateOrganizations();
  42.   createorgObj.createorg();  
  43.   //createorgObj.deleteOrganizations();  
  44.  }
  45. }