Hi All,
we are planning to generate a unique samaccount name with below logic.
1st letter of firstname + first 3 letters of lastname + some 3 random numeric value.
Example: John Smith
Expected outcome : jsmi587.
we have written a transform to achieve this. I would like to get suggestion whether it is a good move to use transform or write a rule to implement the logic.
Looking for inputs on this.
Thanks in Advance
Hello @Narendra Kumar,
Greetings of the day!
A transform might be more appropriate it can generating random numbers as required but if we use rule below are the pointers.
A rule might be a better choice because it offers more granular control over conditions (e.g., generating large numbers of samaccount names for many users), writing a rule can be more efficient, but it depends on how your system handles transforms. If you anticipate that the logic for generating samaccount name could evolve (e.g., adding additional complexity like handling duplicates), writing a rule might provide more long-term stability and flexibility.
Thank You
Mahesh
Hi Narendra !
With the logic you are trying to implement there might be errors for following scenarios:
- First name or Last Name don’t have enough characters
- While you generate random numeric numbers. , we cannot 100% assure it will be unique
The current approach may fail at some or other case . It is better to proceed with cloud rule : Account Profile Attribute Generator | SailPoint Developer Community
Thanks
Hi @sidharth_tarlapally @Mahesh_Mukku ,
Thanks for you inputs.
I am able to fulfill my requirements for the first 2 conditions, the only concern that I have is how I can write a logic to generate some random numeric values in the cloud rule.
It would be great if you have some insights on this please.
Thanks in Advance
Hi @bkumar592 ,
yes we can generate random numeric values , but why to generate random numbers ?
thanks
Here you go , this built on your logic . This is cloud rule of type : AttributeGenerator
- Build’s a pattern of your logic
- Checks if it is unique
- If not unique the rule throws error
- you can modify the code accordingly to resolve uniqueness by adding multiple patterns.
import sailpoint.tools.GeneralException;
import sailpoint.object.Identity;
import sailpoint.api.SailPointContext;
import org.apache.commons.lang.StringUtils;
import java.util.Random;
public String generateUsername(String firstName, String lastName) throws GeneralException {
firstName = StringUtils.trimToNull(firstName);
lastName = StringUtils.trimToNull(lastName);
String pattern = "";
if (lastName != null && firstName != null) {
if (lastName.length() >= 3 && firstName.length() >= 3) {
String lastNameThree = lastName.substring(0, 3);
String firstNameThree = firstName.substring(0, 3;
pattern = firstNameThree.concat(lastNameThree);
String randomNum = getRandomNumber(3);
pattern = pattern + getRandomNumber;
}
if (!pattern.isEmpty() && isUnique(pattern)) {
return pattern1;
}
} else {
throw new GeneralException("cannot generate unique samAccoutName");
}
}
public boolean isUnique(String username) throws GeneralException {
return !idn.accountExistsByDisplayName(application.getName(), username);
}
private String getRandomNumber(int length) throws GeneralException {
if (length <= 0) {
throw new GeneralException("Length must be a positive integer.");
}
Random random = new Random();
StringBuilder randomNumber = new StringBuilder(length); // Specify initial capacity
for (int i = 0; i < length; i++) {
randomNumber.append(random.nextInt(10));
}
return randomNumber.toString();
}
return generateUsername(identity.getFirstname(), identity.getLastname());
This should resolve your issue.
Thanks @sidharth_tarlapally , It should work for us, will update here once i have this rule deployed and tested.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.