Requirement is to read a csv file with contains identity's displayname, nationality and relation attributes in first, fifth and sixth columns of the file.
Below is the Rule:
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule created="" id="" language="beanshell" modified="" name="Read CSV file">
<Description>Identity creation rules are used to set attributes on new Identity objects when they are created. New identities may be created during the aggregation of application accounts, or optionally created after pass-through authentication.
One common operation is to change the name property of the identity when the default application name is complex (such as a directory DN).
Another common operation is to assign a set of initial capabilities based on the attributes pulled from the application account.</Description>
<Signature returnType="void"/>
<Source>
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
log.error("Running Rule: Read CSV file");
String line = "";
QueryOptions identityQuery = new QueryOptions();
try
{
BufferedReader br = new BufferedReader(new FileReader("C:\\SailPoint\\VendorsWithNationality.csv"));
br.readLine();
while ((line = br.readLine()) != null)
{
String[] data = line.split(",");
log.error("----"+ data[0] + "----"+ data[4] + "------" + data[5]);
String dname = data[0];
String nationality = data[4];
String relation = data[5];
Filter idFilter = Filter.eq("displayName", dname);
Identity identity = context.getUniqueObject(Identity.class, idFilter);
log.error(identity);
if(identity != null){
log.error("Display name: "+identity.getDisplayName());
if(identity.getDisplayName()!=null && identity.getDisplayName().equalsIgnoreCase(dname)){
identity.setAttribute("nationality",nationality);
identity.setAttribute("relation", relation);
log.error("Identity "+identity.getDisplayName()+" Nationality: "+nationality + " Relation: "+ relation);
context.saveObject(identity);
context.commitTransaction();
}else {
log.error("************ Update skipped for user ************" + dname);
}
}else {
log.error("************ Update skipped for user ************" + dname);
}
}
} catch (IOException e)
{
log.error(e);
}
log.error("End of Rule: Read CSV file");
</Source>
</Rule>
<Rule created="" id="" language="beanshell" modified="" name="Read CSV file">
<Description>Identity creation rules are used to set attributes on new Identity objects when they are created. New identities may be created during the aggregation of application accounts, or optionally created after pass-through authentication.
One common operation is to change the name property of the identity when the default application name is complex (such as a directory DN).
Another common operation is to assign a set of initial capabilities based on the attributes pulled from the application account.</Description>
<Signature returnType="void"/>
<Source>
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
log.error("Running Rule: Read CSV file");
String line = "";
QueryOptions identityQuery = new QueryOptions();
try
{
BufferedReader br = new BufferedReader(new FileReader("C:\\SailPoint\\VendorsWithNationality.csv"));
br.readLine();
while ((line = br.readLine()) != null)
{
String[] data = line.split(",");
log.error("----"+ data[0] + "----"+ data[4] + "------" + data[5]);
String dname = data[0];
String nationality = data[4];
String relation = data[5];
Filter idFilter = Filter.eq("displayName", dname);
Identity identity = context.getUniqueObject(Identity.class, idFilter);
log.error(identity);
if(identity != null){
log.error("Display name: "+identity.getDisplayName());
if(identity.getDisplayName()!=null && identity.getDisplayName().equalsIgnoreCase(dname)){
identity.setAttribute("nationality",nationality);
identity.setAttribute("relation", relation);
log.error("Identity "+identity.getDisplayName()+" Nationality: "+nationality + " Relation: "+ relation);
context.saveObject(identity);
context.commitTransaction();
}else {
log.error("************ Update skipped for user ************" + dname);
}
}else {
log.error("************ Update skipped for user ************" + dname);
}
}
} catch (IOException e)
{
log.error(e);
}
log.error("End of Rule: Read CSV file");
</Source>
</Rule>