Here you go
{
"jwsHeader": "eyJhbGciOiJFUzI1NiJ9",
"jwsSignature": "3_SEHnszWclLitXyPCrwILF40FQam1SXt60QKvRqI5myaZIKvhKk5WxxwNd4FD3j5nboBAJpF02tEhvBQgGg8A",
"version": 1,
"self": {
"type": "RULE",
"id": "38d5c9a466934eaeada0f31e6c9ccbb8",
"name": "Agloan_Active Directory BeforeProvisioning"
},
"object": {
"description": "",
"type": "BeforeProvisioning",
"signature": {
"input": [],
"output": null
},
"sourceCode": {
"version": "2024-10-17 03:08:06",
"script": "\n \n import java.util.*;\n import org.apache.commons.lang.StringUtils;\n import sailpoint.object.Identity;\n import sailpoint.object.ProvisioningPlan;\n import sailpoint.object.ProvisioningPlan.AccountRequest;\n import sailpoint.object.ProvisioningPlan.AttributeRequest;\n import sailpoint.object.*;\n import sailpoint.rule.Account;\n import sailpoint.tools.GeneralException;\n import sailpoint.tools.Util;\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n import java.text.Normalizer;\n import java.text.Normalizer.Form;\n import java.text.DateFormat;\n import java.text.ParseException;\n import java.text.SimpleDateFormat;\n import java.util.Calendar;\n import java.util.Date;\n\n\n\n Identity identity = plan.getIdentity();\n\n String domainGroup = \"Domain Users\";\n\n String name=(String) identity.getName();\n String appName = application.getName();\n String attributeToSearch = \"mail\";\n String initialCalculation= \"NA\";\n\n public AttributeRequest getAttributeRequest(String attributeName, Object attributeValue) {\n AttributeRequest attributeRequest = new ProvisioningPlan.AttributeRequest();\n attributeRequest.setOperation(ProvisioningPlan.Operation.Set);\n attributeRequest.setName(attributeName);\n attributeRequest.setValue(attributeValue);\n return attributeRequest;\n }\n\n\n\n // Add AttributeRequest\n public AttributeRequest newAttributeRequest(String attributeName, Object attributeValue) {\n AttributeRequest attributeRequest = new ProvisioningPlan.AttributeRequest();\n attributeRequest.setName(attributeName);\n attributeRequest.setOperation(ProvisioningPlan.Operation.Set);\n attributeRequest.setValue(attributeValue);\n return attributeRequest;\n }\n\n \n\n //Remove AttributeRequest\n public AttributeRequest newAttributeRemoveRequest(String attributeName, Object attributeValue) {\n AttributeRequest attributeRequest = new ProvisioningPlan.AttributeRequest();\n attributeRequest.setName(attributeName);\n attributeRequest.setOperation(ProvisioningPlan.Operation.Remove);\n attributeRequest.setValue(attributeValue);\n return attributeRequest;\n }\n\n public Account getAccount(AccountRequest accountRequest) {\n String appName = accountRequest.getApplicationName();\n String nativeId = accountRequest.getNativeIdentity();\n Account account = idn.getAccountByNativeIdentity(appName,nativeId);\n return account;\n }\n\n public String calculateActiveOU(AccountRequest accountRequest, String employeeType) {\n if(employeeType.equalsIgnoreCase(\"Employee\")) {\n return employeeOu;\n } else if(employeeType.equalsIgnoreCase(\"Consultant\")) {\n return consultantOu;\n } else if(employeeType.equalsIgnoreCase(\"Staffing Agency Worker\")) {\n return agencyWorkerOu;\n } else if(employeeType.equalsIgnoreCase(\"Board of Director\")) {\n return bodOu;\n } \n }\n\n\n\n public void addAttributeToAccountRequestArguments(AccountRequest accountRequest, String attributeName, Object attributeValue) {\n if(accountRequest != null && attributeName != null) {\n Map arguments = accountRequest.getArguments();\n if(arguments == null){\n arguments = new HashMap();\n }\n arguments.put(attributeName, attributeValue);\n accountRequest.setArguments(new Attributes(arguments));\n }\n }\n\n\n // Generate the initial password based on the first two characters of firstname, the last four digit SN, first two characters of the lastname\n public String getInitialPassword(String firstname, String lastname, String lastFourDigit) {\n String initialPassword = \"\";\n if(firstname !=null && lastname !=null && lastFourDigit !=null && !firstname.isEmpty() && !lastname.isEmpty() && !lastFourDigit.isEmpty()){\n //sometimes the HR data can contain the firstname/preferred name or lastname with only one character.\n // If firstname is single char, try to use the legalFirstName, else use duplicate the firstname first character for the password generation calculation\n if(firstname.length() == 1){\n \n //If firstname is less than two characters, duplicate the firstname first character twice to make it a two character value (i.e F becomes FF)\n firstname = firstname + firstname;\n }\n //If lastname is less than two characters, duplicate the lastname first character twice to make it a two character value (i.e F becomes FF)\n if(lastname.length() == 1){\n lastname = lastname + lastname;\n }\n initialPassword = firstname.substring(0, 2).toUpperCase() + lastFourDigit + lastname.substring(0, 2).toLowerCase();\n }\n return initialPassword;\n }\n\n\n \n //Return a randomly generated string for password \n public String getRandomGeneratedString() {\n String randomString = \"\";\n String charset = \"ABNCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_+-={}[]:;<>?,./\";\n int index;\n int len;\n Random rnd = new Random();\n len = charset.length();\n for (int count = 0; count < 18; count++) {\n index = rnd.nextInt(len);\n randomString += charset.charAt(index);\n }\n return randomString;\n }\n\n\n/* ******* MAIN **** */\n\n String currentLcs = \"\";\n String calculatedOu = \"\";\n String employeeOu =\"\";\n String bodOu = \"\";\n String consultantOu=\"\";\n String terminatedOu=\"\";\n String lastFourDigit=\"\";\n String agencyWorkerOu=\"\";\n String loaOu=\"\";\n\n String firstname = \"\";\n String lastname = \"\";\n\n\n String nativeIdentity = \"\";\n String employeeType = \"\";\n String nonEmployeeLast4SSN = \"\";\n String employeeId = \"\";\n String adMailNickName = \"\";\n\n \n\n if (plan != null)\n {\n \n if(identity != null)\n {\n \n terminatedOu = \"OU=Deprovisioned,OU=Users,OU=Managed Objects,DC=agloan,DC=ads\";\n employeeOu = \"OU=Zone1,OU=Users,OU=Managed Objects,DC=agloan,DC=ads\";\n bodOu = \"OU=BOD,OU=Zone2,OU=Users,OU=Managed Objects,DC=agloan,DC=ads\";\n consultantOu = \"OU=NonEmployees,OU=Zone1,OU=Users,OU=Managed Objects,DC=agloan,DC=ads\";\n agencyWorkerOu = \"OU=NonEmployees,OU=Zone1,OU=Users,OU=Managed Objects,DC=agloan,DC=ads\";\n loaOu = \"OU=LOA,OU=Users,OU=Managed Objects,DC=agloan,DC=ads\";\n \n\n currentLcs = (String) identity.getAttribute(\"cloudLifecycleState\");\n \n lastFourDigit = identity.getAttribute(\"lastFourDigit\");\n\n employeeType = identity.getAttribute(\"employeeType\");\n\n firstname = identity.getStringAttribute(\"firstname\");\n lastname = identity.getStringAttribute(\"lastname\");\n\n calculatedOu = identity.getAttribute(\"adoulocation\");\n \n }\n\n //If plan is not null then get the account request\n List accountRequests = plan.getAccountRequests();\n\n if(accountRequests != null)\n {\n for(AccountRequest accountRequest : accountRequests)\n { \n AccountRequest.Operation op = accountRequest.getOperation();\n log.debug(\"Nchs AD Provisioning Rule: currentLcs state: \"+currentLcs);\n nativeIdentity = accountRequest.getNativeIdentity();\n\n String samaccountname = identity.getStringAttribute(\"adloginid\");\n if(samaccountname == null && accountRequest.getAttributeRequest(\"sAMAccountName\") != null) {\n samaccountname = accountRequest.getAttributeRequest(\"sAMAccountName\").getValue();\n } \n\n //store it on the arguments of the account request for connector after rules\n if(samaccountname != null && !samaccountname.isEmpty()) {\n addAttributeToAccountRequestArguments(accountRequest, \"samaccountname\", samaccountname);\n }\n\n //Request Email\n if((AccountRequest.Operation.Create == op || AccountRequest.Operation.Modify == op) && (\"newemployee\".equalsIgnoreCase(currentLcs) || \"active\".equalsIgnoreCase(currentLcs) || \"prehire\".equalsIgnoreCase(currentLcs))) {\n AttributeRequest memberOfReq = accountRequest.getAttributeRequest(\"memberOf\");\n \n }\n\n if((AccountRequest.Operation.Create == op) && (\"newemployee\".equalsIgnoreCase(currentLcs) || \"active\".equalsIgnoreCase(currentLcs) || \"prehire\".equalsIgnoreCase(currentLcs))) {\n\n accountRequest.add(getAttributeRequest(\"AC_NewParent\", calculateActiveOU(accountRequest, employeeType)));\n \n String password = getInitialPassword(firstname, lastname, lastFourDigit);\n \n }\n\n \n\n //MODIFY\n if(op != null && AccountRequest.Operation.Modify.equals(op)){\n AttributeRequest memberOfReq = accountRequest.getAttributeRequest(\"memberOf\");\n \n \n }\n\n //Move OU if any of the following is change: employeeType\n if(\"active\".equalsIgnoreCase(currentLcs) && AccountRequest.Operation.Modify.equals(op)) {\n AttributeRequest employeeTypeReq = accountRequest.getAttributeRequest(\"employeeType\");\n if( employeeTypeReq != null && employeeTypeReq.getValue().toString().equalsIgnoreCase(\"Employee\") )\n {\n log.info(\"AgLoan AD Before Provisioning change OU\");\n accountRequest.add(newAttributeRequest(\"AC_NewParent\", calculatedOu)); //moving OU when employeeType changes to Employee\n }\n }\n\n\n if(op != null && AccountRequest.Operation.Enable.equals(op))\n {\n \n log.info(\"AgLoan AD Before Provisioning change OU Rehire\");\n accountRequest.add(newAttributeRequest(\"AC_NewParent\", calculatedOu)); //moving OU when rehire \n \n }\n \n\n if(op != null && \"loa\".equalsIgnoreCase(currentLcs) && AccountRequest.Operation.Modify.equals(op))\n {\n \n log.info(\"AgLoan AD Before Provisioning change OU loa\");\n accountRequest.add(newAttributeRequest(\"AC_NewParent\", loaOu)); //moving OU when loa \n \n }\n\n\n // DISABLE\n if(op != null && AccountRequest.Operation.Disable.equals(op))\n {\n \n Object currentGroups = idn.getRawAccountAttribute(accountRequest.getApplicationName(), accountRequest.getNativeIdentity(), \"memberOf\");\n \n accountRequest.add(newAttributeRequest(\"AC_NewParent\", terminatedOu));\n \n // Set termination date in the description\n Date date = new Date();\n \n SimpleDateFormat descriptionDateFormatter = new SimpleDateFormat(\"MM/dd/yyyy HH:mm:ss\");\n String descriptionDate = descriptionDateFormatter.format(date);\n accountRequest.add(newAttributeRequest(\"description\", \"Deprovisioned on \" + descriptionDate + \" by AGLOAN\\\\svc_IQService\" ));\n \n \n //Scramble the password \n String scrambledPassword = getRandomGeneratedString();\n accountRequest.add(newAttributeRequest(\"password\", scrambledPassword)); \n \n }\n }\n } \n log.info(\"Agloan AD Provisioning Rule is complete\");\n }\n \n "
},
"attributes": {
"sourceVersion": "2024-10-17 03:08:06"
},
"id": "38d5c9a466934eaeada0f31e6c9ccbb8",
"name": "Agloan_Active Directory BeforeProvisioning",
"created": "2024-10-11T14:15:43.849Z",
"modified": "2024-10-17T03:08:07.320Z"
}
}