AttributeGenerator Rule

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

I took a look at the username generator transform docs, and I think you could try increasing your cloudMaxUniqueChecks to 4. The docs I shared have a cloudMaxUniqueChecks value that is one greater than the total number of patterns. I see you have a few switch statements, but the one with the most patterns has a total of 3, so a unique check value of 4 might do the trick.

@Sushant Is the solution mentioned by @colin_mckibben worked for you. we’ve something similar requirement for sAMAccountName uniqueness generation

I am writing attribute generator for below:

  1. samaccountName
  2. displayName

I need to use output of 1 inside 2 attribute generator rule. could you please guide us. Thank you !

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.