I have written the below AttributeGenerator Rule to create samAccountName during AD account provisioning. I dont see the attribute getting generated. What could be the issue?
public String generateUsername(String fName, String lName, String mI) {
String samAccName = "";
String modSamAccName = "";
if((mI == null) || "".equals(mI))
mI = "x";
if((fName == null) || (lName == null)){
return null;
}
else if((fName != null) && (lName != null)){
if(lName.length()>=6)
samAccName = (fName.substring(0,1)+mI.substring(0,1)+lName.substring(0,6)).toLowerCase();
else
samAccName = (fName.substring(0,1)+mI.substring(0,1)+lName.substring(0,lName.length())).toLowerCase();
}
samAccName = samAccName.replaceAll("[^a-zA-Z0-9]", "");
modSamAccName = samAccName;
for(int i=2;modSamAccName !="" && modSamAccName != null;i++)
{
boolean samAccExistsAD = false;
samAccExistsAD = isUniqueInAD(modSamAccName);
if(!samAccExistsAD)
break;
else
{
modSamAccName = samAccName;
if(modSamAccName.length() == 8)
{
modSamAccName = samAccName.substring(0,7)+ i ;
}
if(modSamAccName.length() < 8)
{
modSamAccName = samAccName.substring(0,samAccName.length())+ i ;
}
}
}
return modSamAccName;
}
//Check Active Directory for uniqueness
public boolean isUniqueInAD ( String samAccName) {
if( samAccName != null ) {
LDAPConnectorService ldap = ServiceModule.getService( LDAPConnectorService.class );
String generated = null;
Field field = new Field();
field.setName( "sAMAccountName" );
field.setAttribute( "template", samAccName );
field.setAttribute( "cloudToUpperCase", false );
field.setType( "String" );
field.setAttribute( "cloudMaxUniqueChecks", 1 );
try {
generated = ldap.generateUniqueLDAPAttribute( context, application, identity, field, null );
}
catch(Exception e) {
// Account found, need to generate second attempt
}
//if generation failed or a new sAMAccountName string was created via uniqueness counter, return false
if( generated == null ) {
return false;
} else if ( !generated.equals( samAccName ) ) {
return false;
} else {
return true;
}
} else {
return false;
}
}
String fName=identity.getFirstname();
String lName=identity.getLastname();
String mI=(String)identity.getAttribute("middleInitial");
return generateUsername(fName, lName, mI);