oracle-databaseoim

Move Organization Members from one to another using Oracle Identity Manager API


I am trying move Organization Members from a Parent Organization to its Child Organization through Oracle Identity Manager API. I have the orgkey for both of them. I have written the below code snippet. I am able to get the list of Parent Organization members in the variable srcOrgOrganizationMembers. Receiving an error

oracle.iam.identity.exception.ValidationFailedException: IAM-3056148 : usr_pwd_warn_date is a System Attribute and cannot be set through API

Can you pls suggest how to get rid of this issue. Thanks for your help in advance!

 OrganizationManager orgManager = oimClient.getService(OrganizationManager.class);


         List<String> childOrgList = new ArrayList<String>();

         String orgkey = "54";

         try {

                HashMap<String, Object> configParams = new HashMap<String, Object>();
                Set<String> retAttrs = new HashSet<String>();
                List<Organization> ChildOrg = new ArrayList<Organization>();

                ChildOrg = orgManager.getChildOrganizations(orgkey, retAttrs, configParams);

                List srcOrgOrganizationMembers = orgManager.getOrganizationMembers(orgkey, retAttrs, null, configParams);
                System.out.println("Child Organizations Details : " + ChildOrg);
                System.out.println("Parent Organization Users : " + srcOrgOrganizationMembers);



                   System.out.println("Child Organizations Details : " + ChildOrg);

                   if (ChildOrg != null) {

                          for (int s = 0; s < ChildOrg.size(); s++) {

                                String childorgkey = ChildOrg.get(s).getEntityId();
                                System.out.println("Child Org Key : " + childorgkey);

                                childOrgList.add(childorgkey);



                                List<Organization> grandChildOrg = new ArrayList<Organization>();
                                grandChildOrg = orgManager.getChildOrganizations(childorgkey, retAttrs, configParams);
                                if (grandChildOrg != null) {

                                       for (int a = 0; a < grandChildOrg.size(); a++) {

                                              String grandchildorgkey = grandChildOrg.get(a).getEntityId();
                                              System.out.println("Grand Child Org Key : " + grandchildorgkey);

                                              childOrgList.add(grandchildorgkey);

                                              List<Organization> garndgrandChildOrg = new ArrayList<Organization>();
                                              garndgrandChildOrg = orgManager.getChildOrganizations(grandchildorgkey, retAttrs,
                                                           configParams);
                                              if (garndgrandChildOrg != null) {

                                                    for (int b = 0; b < garndgrandChildOrg.size(); b++) {

                                                           String garndgrandchildorgkey = garndgrandChildOrg.get(b).getEntityId();
                                                           System.out.println("Grand Grand Child Org Key : " + garndgrandchildorgkey);

                                                           childOrgList.add(garndgrandchildorgkey);

                                                    }

                                              }

                                       }

                                }

                          }

                   }

                   System.out.println("Child Org List outside while: " + childOrgList);

                   UserManager orgUsrMgr = oimClient.getService(UserManager.class);
                   System.out.println("\n \n values in orgUsrMgr" + orgUsrMgr);

                   List<User> resultUsers = new ArrayList<User>();


                   for(String childOrgzKey : childOrgList){

                           UserManagerResult result = null; 

                           for(Object usrObj : srcOrgOrganizationMembers){

                            User fromUser = (User)usrObj; 
                            HashMap mapOfSrcUserAttribute = fromUser.getAttributes();
                            //System.out.println("Organization Names of the Users" + fromUser.getAttribute("Organization Name") );
                            //User toUser = new User("");


                            //fromUser.setAttribute("Organization Name", "Requests");

                          System.out.println("\n\n Values in Source User Hashmap :" + mapOfSrcUserAttribute );

                          /*
                           System.out.println("\n\n Values in Source User Hashmap Keys :" + mapOfSrcUserAttribute.keySet() );

                            for(Object attrName : mapOfSrcUserAttribute.keySet()){ 
                                toUser.setAttribute(attrName.toString(), mapOfSrcUserAttribute.get(attrName));
                            }
                            System.out.println("\n\n Values in toUser : " + toUser);*/

                           fromUser.setOrganizationKey(childOrgzKey);

                            try {
                                 result = orgUsrMgr.modify(fromUser);
                                 System.out.println(fromUser +"User Sucessfully got Created" + result);
                                 resultUsers.add(fromUser);

                                 } catch (Exception e) {
                                  System.out.print(e);
                            }

                       }
                   }

                  System.out.println("List of all created users = " + resultUsers);

Solution

  • You need to use the following to change the org

    User usr = new User(fromUser.getId());
    usr.setOrganizationKey(childOrgzKey);
    
    orgUserMgr.modify(user)