We have attribute generator rule for mail and proxyAddresses uniqueness check.
For some reason it is not working.
we have existing user Vernica, Reyes and new user also came with same name
Existing user email and proxyAdresses below
email - [email protected]
proxyAdresses - smtp:[email protected]
proxyAdresses - SMTP:[email protected]
New user email and proxyAdresses created like below
email - [email protected]
proxyAdresses - SMTP: [email protected]
But expected is it should increment by 1
email - Vernica.Reyes1@company.org
proxyAdresses - SMTP: Vernica.Reyes1@company.org
Any issue in the logic.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import sailpoint.object.Identity;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;
int maxIteration = 1000;
public boolean isUnique ( String email ) throws GeneralException {
boolean isValueUnique = false;
List sourceList = new ArrayList(Arrays.asList(new String[]{ "6817f2c135d54e3dbd3df1893fe735bc", "cef2b610fc8e486d94a70d23703bc22d", "08e1b20edea4458083d66d7622a91853", "70ec8ee3b4444ad282a59ab7890b6ae0", "eed4472784514a2fa9392d66c2b770ea", "e8e667ecafa5497688ddc4309d584a77"}));
List emailValue = new ArrayList(Arrays.asList(new String[]{email}));
try{
int identityCount = idn.attrSearchCountAccounts(sourceList, "promotedsEmail", "Equals", emailValue);
// Check on the AD and SMTP email addresses (StartsWith)
int smtpFound = idn.attrSearchCountAccounts(sourceList, "promotedSmtpAddresses", "StartsWith", new ArrayList(Arrays.asList(new String[] {"smtp:" + email})));
int SMTPFound = idn.attrSearchCountAccounts(sourceList, "promotedSmtpAddresses", "StartsWith", new ArrayList(Arrays.asList(new String[] {"SMTP:" + email})));
if(identityCount == 0 && smtpFound == 0 && SMTPFound == 0)
{
isValueUnique = true;
}
}
catch (GeneralException exception) {
throw new GeneralException("Error in isUnique Method in Generate Email ::" + exception);
}
return isValueUnique;
}
public String generateUniqueEmail(String firstname, String lastname) throws GeneralException {
String email = "";
String domain = "@company.org";
if (!firstname.isEmpty() && !lastname.isEmpty()) {
email = firstname + "." + lastname;
}
if (!firstname.isEmpty() && lastname.isEmpty()) {
email = firstname;
}
if (firstname.isEmpty() && !lastname.isEmpty()) {
email = lastname;
}
try {
String emailWithDomain = email + domain;
if (isUnique(emailWithDomain)) {
return emailWithDomain;
}
String updatedEmail = "";
for (int n = 1; n <= maxIteration; n++) {
updatedEmail = email + n;
String updatedEmailWithDomain = updatedEmail + domain;
if (isUnique(updatedEmailWithDomain)) {
return updatedEmailWithDomain;
}
}
}catch (GeneralException exception) {
throw new GeneralException("Error in generateUniqueEmail Method in Generate Email::" + exception);
}
return email;
}
String firstname = null != identity.getFirstname() ? identity.getFirstname().replaceAll("[^a-zA-Z]", "") : "";
String lastname = null != identity.getLastname() ? identity.getLastname().replaceAll("[^a-zA-Z]", "") : "";
return generateUniqueEmail(firstname,lastname);