Happy New Year everyone,
I am working on updating some rules that have been causing issues in our tenant s. I am trying to follow the official documentation on the RDT (Rule Development Kit | SailPoint Developer Community). I get to the point of mocking up data and I am left scratching my head as to how I would mock the data up there is not a lot of detail in the example provided on the page.
I have created the .java and .xml files for the logic I want to test. I am not stuck on what I should do next in order to start testing out my new logic that was built. Any pointers on how to complete the next steps in the document would be really helpful thank you.
for reference here is the logic I have built out.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import sailpoint.object.Application;
import sailpoint.object.Field;
import sailpoint.object.Identity;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;
import sailpoint.object.Identity;
public class GenerateNetworkID
{
Logger log = LogManager.getLogger(GenerateNetworkID.class);
IdnRuleUtil idn;
Identity identity = new Identity();
/**
* Remove all special characters, prefix, and suffix from the inputted string.
*
* @param name The first or last name of an identity.
* @return The inputted string without special characters, prefix, or suffix
*/
public String FirstIntial(String FirstName)
{
log.debug("Filtering substring of FirstName to extract First Char.");
if(FirstName != null)
{
String FirstIntial = FirstName.substring(0,1);
return FirstIntial;
}
else
{
log.error("No input data was entered. Please imput a string value.");
return "ERROR";
}
}
public String LastNameSubString(String LastName)
{
log.debug("Filtering the Lastname to the first 5 chars.");
if(LastName != null)
{
String LastName5Char = LastName.substring(0,6);
return LastName5Char;
}
else
{
log.error("No input data was entered. Please imput a string value.");
return "ERROR";
}
}
public String GetUID()
{
String UID = identity.getStringAttribute("uid");
if(UID != null)
{
return UID;
}
else
{
log.error("No Value returned for UID.");
return "ERROR";
}
}
public String GetcloudAuthoritativeSource()
{
String cloudAuthoritativeSource = identity.getStringAttribute("cloudAuthoritativeSource");
if(cloudAuthoritativeSource != null)
{
return cloudAuthoritativeSource;
}
else
{
log.error("No value returned for cloudAuthoritativeSource");
return "ERROR";
}
}
public String SamAccountName()
{
String firstName = FirstIntial(identity.getFirstname().toLowerCase());
String lastName = LastNameSubString(identity.getLastname().toLowerCase());
if(firstName != null && lastName != null)
{
return firstName + lastName;
}
else
{
log.error("A value returned Null please verify Identity");
return "ERROR";
}
}
public boolean IsUnique( String SamAccountName)
{
List SOURCE_IDS = new ArrayList(Arrays.asList(new String[]{ "2c9180857f221d2b017f23154bbe1644", "2c91808983e6f7250183f66daa0237a9"}));
String PROMOTED_ATTR_NAME = "newSamAccountName";
String SEARCH_OP = "Equals";
List SEARCH_VALUES = new ArrayList( Arrays.asList( new String[]{ SamAccountName } ) );
int count = idn.attrSearchCountAccounts( SOURCE_IDS, PROMOTED_ATTR_NAME, SEARCH_OP, SEARCH_VALUES );
return count == 0;
}
public String CreateSamAccountName()
{
String SamAccountName = SamAccountName();
String CloudAuthoritativeSource = GetcloudAuthoritativeSource();
int usernameIdentifier;
int uniqueIndex;
if ( CloudAuthoritativeSource.contains( "2c9180837fdb5fe6017ffa27a7081a5e" ) || CloudAuthoritativeSource.contains( "2c9180888222e5a701823b3c70940398" ) ) {
usernameIdentifier = 9;
uniqueIndex = 1;
}
else {
usernameIdentifier = 0;
uniqueIndex = 2;
}
while(IsUnique(SamAccountName + Integer.toString(usernameIdentifier) + Integer.toString(uniqueIndex)) == false)
{
uniqueIndex ++;
}
return SamAccountName + Integer.toString(usernameIdentifier) + Integer.toString( uniqueIndex );
}
}
Here is what I want it to replace:
import sailpoint.tools.Util;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.object.Link;
import sailpoint.object.Application;
import sailpoint.thunderbolt.service.LDAPConnectorService;
import sailpoint.thunderbolt.service.module.ServiceModule;
import sailpoint.thunderbolt.service.ConnectorService;
import sailpoint.object.Field;
import sailpoint.tools.GeneralException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class SamAccountNameGenerator{
Logger log = LogManager.getLogger(SamAccountNameGenerator.class);
//debug("[ENTERING] AttributeGenerator :: Generate sAMAccountName.");
/**
* Remove all special characters, prefix, and suffix from the inputted string.
*
* @param name The first or last name of an identity.
* @return The inputted string without special characters, prefix, or suffix
*/
public String cleanupName( String name ) {
log.debug("Entering cleanupName( \""+ name +"\" )" );
if ( name != null) {
if ( name.contains( " " ) ) {
log.debug( "Space in " + name + " detected....checking for suffix" );
String [] split = name.split(" ");
String cleanName = "";
for ( int i = 0; i < split.length; i++ ) {
log.debug( "split[" + i + "] = " + split[i] );
if ( split[i].matches( "jr|jr.|jR|jR.|JR|JR.|Jr|Jr.|sr|sr.|sR|sR.|SR|SR.|Sr|Sr.|ii|iii|iv|v|II|III|IV|V" ) ) {
split[i] = "";
}
cleanName += split[i];
}
name = cleanName;
log.debug( "Suffix Detected....Removing" );
log.debug( "Updated Name" );
}
name = name.replaceAll( "[^a-zA-Z0-9_-]", "" );
}
log.debug( "Name : " + name );
return name;
}
/**
* check all AD applications.
*
* @param sAMAccountName - The generated value for testing.
* @return true if the count is 0, false if the count is greater than 0.
*/
public boolean isUnique( String sAMAccountName ) {
List SOURCE_IDS = new ArrayList( Arrays.asList( new String[]{ "2c9180857f221d2b017f23154bbe1644", "2c91808983e6f7250183f66daa0237a9" } ) );
String PROMOTED_ATTR_NAME = "newSamAccountName";
String SEARCH_OP = "Equals";
List SEARCH_VALUES = new ArrayList( Arrays.asList( new String[]{ sAMAccountName } ) );
int count = idn.attrSearchCountAccounts( SOURCE_IDS, PROMOTED_ATTR_NAME, SEARCH_OP, SEARCH_VALUES );
return count == 0;
}
//Create the sAMAccountName using the first 5 character of the lastname + firstname initial
String firstName = cleanupName( identity.getFirstname().toLowerCase() );
String lastName = cleanupName( identity.getLastname().toLowerCase() );
String accountLastname = lastName.length() > 5 ?
lastName.substring( 0, 5 ) : lastName;
String samFirstname = firstName.substring( 0, 1 );
String sAMAccountName = identity.getAttribute( "uid" );
String cloudAuthoritativeSource = identity.getAttribute( "cloudAuthoritativeSource" );
String usernameIdentifier = "";
int uniqueIndex = 0;
if ( cloudAuthoritativeSource.contains( "2c9180837fdb5fe6017ffa27a7081a5e" ) || cloudAuthoritativeSource.contains( "2c9180888222e5a701823b3c70940398" ) ) {
usernameIdentifier = "9";
uniqueIndex = 1;
} else {
usernameIdentifier = "0";
uniqueIndex = 2;
}
while ( !isUnique( sAMAccountName ) && 99 > uniqueIndex ) {
sAMAccountName = samFirstname + accountLastname + usernameIdentifier + Integer.toString( uniqueIndex );
uniqueIndex++;
}
log.debug( "sAMAccountName :: returning \"" + sAMAccountName + "\"." );
log.debug( "[EXITING] AttributeGenerator :: Generate sAMAccountName." );
return sAMAccountName;
}