Tuesday, March 9, 2021

Move AD account from People OU to Disable OU & vice versa (Enable) in IIQ

public ProvisioningPlan buildMoveADAccountsPlan(WorkflowContext wfc) 

        throws GeneralException {


        Logger ruleLog = Logger.getLogger("RuleLog");

        if (ruleLog.isDebugEnabled()) ruleLog.debug("Entering into buildMoveADAccountsPlan rule");

        Attributes args = wfc.getArguments();      

        String op = Util.getString(args, "op");


        if ( op == null ){

           throw new GeneralException("Operation (op) must be specified.");

   }    

        Custom settings = context.getObjectByName(Custom.class, "Custom Settings");

        ProvisioningPlan plan = new ProvisioningPlan();

        String identityName = Util.getString(args, "identityName");

        if (ruleLog.isDebugEnabled()) ruleLog.debug("Processing identity " + identityName);

        Identity identity = context.getObjectByName(Identity.class, identityName);        


        if (null != identity) {

           plan.setIdentity(identity);         


           // Get a list of AD applications 

           List appList = getADApps();       

           IdentityService identityService = new IdentityService(context);

           for (Application app : appList) {

              List links = identityService.getLinks(identity, app);

              if ((null != links) && !links.isEmpty()) {

                for (Link link : links) {

                   String nativeIdentity = link.getNativeIdentity();

                   String newOU = null;

                   if (op.equals("Disable")) {

                      if (nativeIdentity.toLowerCase().endsWith("dc=mightypedia,dc=com")){

                         newOU = settings.get("pediaADDisabledUsersOU");

}                 

                   } 

      }

             }

                   if (ruleLog.isDebugEnabled()) {

   ruleLog.debug("Moving to " + newOU);

   }

                   if (null != newOU && ! newOU.equalsIgnoreCase(getParentContainerDN(nativeIdentity))) {

                      AccountRequest acctReq = new AccountRequest();

                      acctReq.setApplication(link.getApplicationName());

                      acctReq.setInstance(link.getInstance());

                      acctReq.setNativeIdentity(link.getNativeIdentity());

                      acctReq.setOperation(AccountRequest.Operation.Modify);

      AttributeRequest attReq = new AttributeRequest();


                      attReq.setName("AC_NewParent");

                      attReq.setValue(newOU);

                      attReq.setOp(ProvisioningPlan.Operation.Set);

                      acctReq.add(attReq);

                      plan.add(acctReq);

                   }           

                }

             }

           }

        }

        if (ruleLog.isDebugEnabled()) {

ruleLog.debug("Returning plan: " + plan.toXml());

}

        return plan;

    }

---------------------------------------------################----------------------------------------------

 public List getADApps() {    

        Logger ruleLog = Logger.getLogger("RuleLog");

        List appList = new ArrayList();

        QueryOptions qo = new QueryOptions();

        qo.addFilter(Filter.eq("connector", "sailpoint.connector.ADLDAPConnector"));      

        Iterator it = context.search(Application.class, qo);

        while (it.hasNext()) {

           Application thisApplication = it.next();

           if (ruleLog.isDebugEnabled()) ruleLog.debug("Found Active Directory application " + thisApplication.getName());

           appList.add(thisApplication);

        }         

        if (appList.isEmpty()) {

           ruleLog.warn("No Active Directory applications found");

        }

        return appList;

    }

No comments:

Post a Comment

Fetch Members from Workgroup

  import java.util.ArrayList;   import java.util.Iterator;   import java.util.List;   import sailpoint.api.ObjectUtil;   import sailpoint.ob...