Hi All,
I am working on the AttributeGenerator rule to generate the unique value for the “userPrincipalName” while provisioning new accounts in Active Directory. The rule is working fine while provisioning the first account but I am getting an error while provisioning the second account. (java.lang.IllegalStateException: Unable to generate a unique value for Source[sourcename] Field [userPrincipalName] after 1 retries. BSF info: Generate Upn at line: 0 column: columnNo).
Can anyone please let me know what changes do I need to make to get it working
Here is the rule:
public String normalizeInput(String inputString)
{
if (inputString!=null && !inputString.isEmpty())
{
// Remove any non-alphanumerics
inputString=inputString.replaceAll("[^A-Za-z0-9]", "");
// Strip off any non-printables
inputString=StringUtils.trimToNull(inputString);
}
return inputString;
}
//Check Active Directory for uniqueness
public boolean isUnique(String upn) {
log.error("Entering isUnique, userPrincipalName is:" + upn);
LDAPConnectorService ldapService = ServiceModule.getService( LDAPConnectorService.class );
Field field = new Field();
field.setName("userPrincipalName");
field.setAttribute("cloudMaxSize", "99" );
field.setAttribute("cloudMaxUniqueChecks", "1" );
field.setType("String");
field.setAttribute("cloudRequired", "true");
field.setAttribute("cloudToUpperCase",false);
field.setAttribute("template", upn);
String generated = ldapService.generateUniqueLDAPAttribute( context, application, identity, field, null );
log.error("Generated value is:" + generated);
if(generated == null || !generated.equals(upn)) {
return false;
}
else {
return true;
}
}
public String generateupnAddress (String firstName, String middleName, String lastName, String domainForEmailCreation)
{
// set some variables we'll use later
String fi;
String mi;
String alias = null;
String upn = null;
int iterator = 0;
int counter = 1;
if ( ( firstName == null ) || ( lastName == null )){
return null;
}
else if (( middleName != null ) && ( middleName != "" ) ) {
mi = middleName.substring(0,1);
do
{
switch ( iterator )
{
case 0:
alias = firstName + "." + lastName;
break;
case 1:
alias = firstName + "." + mi + "." + lastName;
break;
default:
alias = firstName + "." + lastName + String.valueOf(counter);
counter++;
break;
}
iterator++;
upn = alias + "@" + domainForEmailCreation;
} while ( !(isUnique(upn) ) && ( iterator < 999 ) );
// Don't let the it loop forever if something goes wrong
if( ( iterator >= 999) || (upn.isEmpty()) || upn == null )
return null;
else
return upn;
}
else {
do
{
switch ( iterator )
{
case 0:
alias = firstName + "." + lastName;
break;
default:
alias = firstName + "." + lastName + String.valueOf(counter);
counter++;
break;
}
iterator++;
upn = alias + "@" + domainForEmailCreation;
} while ( !(isUnique(upn) ) && ( iterator < 999 ) );
// Don't let the loop forever if something goes wrong
if( ( iterator >= 999) || (upn.isEmpty()) || upn == null )
return null;
else
return upn;
}
}
if(identity != null && identity != void)
{
String firstName = normalizeInput(identity.getAttribute("firstname"));
String middleName = normalizeInput(identity.getAttribute("middleName"));
String lastName = normalizeInput(identity.getAttribute("lastname"));
String domainForEmailCreation = identity.getAttribute("domainForEmailCreation");
return generateupnAddress(firstName, middleName, lastName, domainForEmailCreation);
}
else
return null;
Thank you,
Sushant