Hi Team,
We have developed a rule to generate a unique UPN value for AD. However, we mistakenly set the rule type as AttributeGenerator. Now, we are using this rule within IdentityNow via a Transform (type: rule) to generate a unique UPN by validating it against AD.
Current Behavior:
- The rule successfully generates the required UPN value.
- However, it does not validate whether the UPN already exists in AD.
- Even if the same UPN exists in AD, it does not increment and simply returns the same value.
Expected Behavior:
- If the generated UPN already exists in AD, the rule should increment the extension (e.g.,
firstname.lastname@abc.com→firstname.lastname1@abc.com,firstname.lastname2@abc.com, etc.).
Below is the current rule implementation:
Rule:
xml
CopyEdit
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule name="UPNGenerator" type="AttributeGenerator">
<Description>Generate a unique Email.</Description>
<Source><![CDATA[
import sailpoint.tools.GeneralException;
import sailpoint.object.*;
import java.util.*;
import sailpoint.api.*;
import sailpoint.rule.*;
import org.apache.commons.lang.StringUtils;
import java.text.Normalizer;
log.debug("Starting UPN generation process");
int maxIteration = 1000;
int upnCount = 0;
List SEARCH_IN_SOURCE_IDS = new ArrayList(Arrays.asList(new String[] {"????"}));
log.debug("Search IDs initialized: " + SEARCH_IN_SOURCE_IDS);
String SEARCH_OP = "Equals";
String PROMOTED_ATTR_UPN = "userPrincipalName";
int extension = 0;
public int getDuplicateUpnCount(String upnValue) throws GeneralException {
log.debug("Checking duplicate UPN count for: " + upnValue);
List upnValueList = new ArrayList(Arrays.asList(new String[] {upnValue}));
upnCount = idn.attrSearchCountAccounts(SEARCH_IN_SOURCE_IDS, PROMOTED_ATTR_UPN, SEARCH_OP, upnValueList);
log.debug("Duplicate UPN count: " + upnCount);
return upnCount;
}
public String generateUpn(String firstName, String lastName, int extension) {
log.debug("Generating UPN...");
firstName = StringUtils.trimToNull(firstName);
lastName = StringUtils.trimToNull(lastName);
String upn = (extension > 0) ? firstName + "." + lastName + extension + "@abc.com"
: firstName + "." + lastName + "@abc.com";
upnCount = getDuplicateUpnCount(upn);
if (upnCount == 0) {
return upn;
} else if (upnCount < maxIteration) {
return generateUpn(firstName, lastName, extension + 1);
} else {
log.debug("Max iterations reached for UPN generation.");
return null;
}
}
return generateUpn(identity.getFirstname(), identity.getLastname(), extension);
]]></Source>
</Rule>
Questions for the Community:
Why is the rule not validating against AD properly?
Would appreciate any insights or guidance from the community.
Thanks in advance! ![]()