Sample transformation script for AD users and group memberships
The text for transformation script (with comments) to get users and their group memberships for Active Directory instances with a connector is given below.
import org.openiam.base.AttributeOperationEnumimport org.openiam.idm.searchbeans.GroupSearchBeanimport org.openiam.idm.srvc.auth.dto.Loginimport org.openiam.idm.srvc.continfo.dto.EmailAddressimport org.openiam.idm.srvc.synch.dto.LineObjectimport org.openiam.idm.srvc.user.dto.UserStatusEnumimport org.openiam.provision.dto.ProvisionUserimport org.openiam.provision.type.Attributeimport org.openiam.idm.srvc.grp.dto.Groupimport org.apache.commons.collections.CollectionUtilsimport org.openiam.sync.service.impl.service.AbstractUserTransformScriptpublic class ADPowerShellTransformation extends AbstractUserTransformScript {@Overrideint execute(LineObject rowObj, ProvisionUser pUser) {populateObject(rowObj, pUser)pUser.status = UserStatusEnum.ACTIVEpUser.mdTypeId = "DEFAULT_USER"// Add default roleaddUserRoleByName(pUser, "End User", null, null, null, null, null)pUser.setSkipPreprocessor(false)pUser.setSkipPostProcessor(false)return NO_DELETE}@Overridevoid init() {}private void populateObject(LineObject rowObj, ProvisionUser pUser) {def attrValMap<String, Attribute> columnMap = rowObj.columnMap/* for (Map.Entry<String, Attribute> entry : columnMap.entrySet()) {addAttribute(pUser, entry.value)}*/attrVal = columnMap.get("Name")if (attrVal) {addUserAttribute(pUser, attrVal.getName(), attrVal.getValue())}attrVal = columnMap.get("GivenName")if (attrVal) {pUser.firstName = attrVal.value}attrVal = columnMap.get("Surname")if (attrVal) {pUser.middleInit = attrVal.value}attrVal = columnMap.get("DisplayName")if (attrVal) {pUser.setNickname(attrVal?.value);}attrVal = columnMap.get("Surname")if (attrVal) {pUser.lastName = attrVal.value}//uncomment this line to send email notification to the user/* if(isNewUser){pUser.emailCredentialsToNewUsers = true;}*/def memberOf = columnMap.get("memberOf");if (memberOf) {final Set<String> groupSet = new HashSet<>();if (memberOf.isMultiValued()) {groupSet.addAll(memberOf.getValueList());} else {groupSet.add(memberOf.getValue());}for (String dn : groupSet) {addUserGroupByAttribute(pUser, "DistinguishedName", dn, CERTIFIED_RIGHT_SET, null, null, null);}}List<Group> currentGroups = new ArrayList<>();if (pUser.getId()) {final Set<String> usrIds = new HashSet<>();usrIds.add(pUser.getId());final GroupSearchBean gsb = new GroupSearchBean();gsb.setUserIdSet(usrIds);gsb.setMetadataTypes(Set.of("AD_GROUP"));currentGroups = groupRabbitMQService.findBeans(gsb, null, 0, Integer.MAX_VALUE);}if (CollectionUtils.isNotEmpty(currentGroups)) {currentGroups.forEach{ Group current ->if (pUser.getGroup(current.getId()) && (pUser.getGroup(current.getId()).getOperation() == AttributeOperationEnum.NO_CHANGE ||//if rights are not empty - it means user either admin or owner selected for the access certificationCollectionUtils.isEmpty(pUser.getGroup(current.getId()).getRights())) && pUser.getGroup(current.getId()).getEndDate() == null) {println("Removing group: " + current.getName());pUser.removeGroup(current);}}}attrVal = columnMap.get("EmailAddress")if (!attrVal) {attrVal = columnMap.get("UserPrincipalName")}if (attrVal) {// Processing email addressaddUserAttribute(pUser, attrVal.getName(), attrVal.getValue())def emailAddress = new EmailAddress()emailAddress.name = "PRIMARY_EMAIL"emailAddress.default = trueemailAddress.active = trueemailAddress.emailAddress = attrVal.valueemailAddress.mdTypeId = "PRIMARY_EMAIL"addUserEmailAddress(pUser, emailAddress)}attrVal = columnMap.get(config.getMatchSrcFieldName())if (isNewUser) {//attrVal = columnMap.get("sAMAccountName")if (attrVal) {// PRE-POPULATE THE USER LOGIN. IN SOME CASES THE COMPANY WANTS// TO KEEP THE LOGIN THAT THEY HAVE// THIS SHOWS HOW WE CAN DO THATdef lg = new Login()lg.operation = AttributeOperationEnum.ADDlg.login = attrVal.valuelg.managedSysId = "0"lg.setActive(true)pUser.principalList.add(lg)/*Login lg2 = new Login()lg2.operation = AttributeOperationEnum.ADDlg2.login = attrVal.valuelg2.managedSysId = config.getManagedSysId()lg2.setActive(true)pUser.principalList.add(lg2)*/}}}}