Based on the below rule, I am generating mailnickname first name first letter middle name (if it exists) first-letter and lastname, but it is generating a random number like 160Tim, as shown in the screenshot below.
In user details tab first name middlename and last name
Any idea please.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC 'sailpoint.dtd' 'sailpoint.dtd'>
<Rule language='beanshell' name='Get Unique Mail Nickname' type='AttributeGenerator' >
<Description>Checks for mailnickname uniqueness across all Active Directory Domains</Description>
<Source><![CDATA[
import sailpoint.object.*;
import sailpoint.api.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Util;
// Used to generate a unique Mail Nickname ex. bcsmith, bsmith1, bsmith2 etc
public boolean isUnique (String value) {
boolean isValueUnique = false;
List sourceList = new ArrayList(Arrays.asList(new String[]{"39485455ca984adcafffb4c165dd2ec3", "7d9a231ce021467b9c88135e22e0c9d0"}));
List searchValue = new ArrayList(Arrays.asList(new String[]{value}));
try{
int identityCount = idn.attrSearchCountAccounts(sourceList, "mailNickname", "StartsWith", searchValue);
if(identityCount == 0)
isValueUnique = true;
}
catch(Exception e){
log.debug("SLHS Get Unique Mail Nickname Rule: Error Occurred during isUnique check : " + e);
return false;
}
return isValueUnique;
}
String mailnickname = "";
String firstName = null != identity.getStringAttribute("firstname") ? identity.getStringAttribute("firstname") : "";
String lastName = null != identity.getStringAttribute("lastname") ? identity.getStringAttribute("lastname").replaceAll("[^a-zA-Z]", "") : "";
String middleName = null != identity.getStringAttribute("middleName") ? identity.getStringAttribute("middleName") : "";
if(!firstName.isEmpty() && !middleName.isEmpty() && !lastName.isEmpty()){
mailnickname = firstName.charAt(0)+middleName.charAt(0)+lastName;
}
if(!firstName.isEmpty() && middleName.isEmpty() && !lastName.isEmpty()){
mailnickname = firstName.charAt(0)+lastName;
}
if(firstName.isEmpty() && !middleName.isEmpty() && !lastName.isEmpty()){
mailnickname = middleName.charAt(0)+lastName;
}
if(firstName.isEmpty() && middleName.isEmpty() && !lastName.isEmpty()){
mailnickname = lastName;
}
// Check if original without counter is unique
if (isUnique(mailnickname)) {
return mailnickname;
}
// Check mailnickname{counter} until unique
int iteration = 1;
int maxIteration = 10000;
while (iteration < maxIteration) {
if (isUnique(mailnickname + iteration)) {
return mailnickname + iteration;
}
iteration++;
}
return null;
]]></Source>
</Rule>