Sunday, January 9, 2022

Form AllowedValues rule to filter Identities with Active Regular Active Directory accounts and identity is active and correlated

 The rule type is AllowedValues.

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.object.Link;
import sailpoint.object.QueryOptions;
import sailpoint.api.SailPointContext;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


Logger log = Logger.getLogger("sailpoint.rules.FilterActiveRegularADAccounts");
log.setLevel(Level.DEBUG);
log.debug("-----------------------------------");

List identityList = new ArrayList();
QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.ne("inactive",true));
qo.addFilter(Filter.eq("correlated", true));
qo.add(Filter.eq("links.application.name","Active Directory"));
qo.add(Filter.eq("links.accounttype","Regular"));
log.debug("Get list of Identities");
Iterator iterator = context.search(Identity.class,qo);
while(iterator.hasNext()){
Identity identityObject = (Identity) iterator.next();
List linksList = identityObject.getLinks();
Link contractorADLink;
for (Link link : linksList){
if ("Active Directory".equalsIgnoreCase(link.getApplicationName())){
if (null!=link.getBooleanAttribute("IIQDisabled") &&
link.getBooleanAttribute("IIQDisabled")){
//do nothing
} else{
identityList.add(identityObject.getName());
}

}
}
}
Filter finalFilter = Filter.in("name", identityList);
field.setFilterString(finalFilter.toString());
log.debug("-------------------------------------");

}

Saturday, January 8, 2022

IdentitySelectorConfiguration to add more filter attributes for Identity fields in form

 Requirement: In a form which has field type as Identity, by deafult sailpoint allows seach using username, first name, last name and display name. We need to enable seach by employeeid. This can be acheived by adding employeeid field in the IdentitySelectorConfiguration.


1. Open SailPoint in debug console.

2. Search for Configuration objects and select IdentitySelectorConfiguration.

3. Locate the Global parameter.

4. Update the filter string by adding employeeid.



Rule to read a custom object and insert values into Database table

The custom object contain a hashmap with list of values. Read the list and insert into DB table.


import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import sailpoint.object.Custom;
import sailpoint.plugin.PluginBaseHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;


Logger log = Logger.getLogger("sailpoint.rules.InsertIntoDBTable");
log.setLevel(Level.DEBUG);
log.debug("-----------------------------------");

Custom customObj = context.getObject(Custom.class, "custom_object_name");
HashMap hashMap = customObj.getAttributes();
List list = hashMap.get("list_name");
Connection connection = PluginBaseHelper.getConnection();
log.debug("Connection established to DB: " + connection.getCatalog());
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;

for(String value : list)
{
try {
String insertQuery = "INSERT INTO TABLE_NAME (COLUMN_NAME) VALUES(?);";
preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.setString(1, value);
log.debug("Executing the query: " + insertQuery);
resultSet = preparedStatement.execute()

} catch (Exception e) {
log.error("Exception occurred: " + e);
}
}
connection.close();

Rule to Read Database Table


import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import sailpoint.plugin.PluginBaseHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

Logger log = Logger.getLogger("sailpoint.rules.ReadDBTable");
log.setLevel(Level.DEBUG);
log.debug("-----------------------------------");

Connection connection = PluginBaseHelper.getConnection();
log.debug("Connection established to DB: " + connection.getCatalog());
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try{

String selectQuery = "SELECT COLUMN_NAME FROM TABLE_NAME; ";
preparedStatement = connection.prepareStatement(selectQuery);
log.debug("Executing the query: " +selectQuery);
resultSet = preparedStatement.executeQuery();

while(resultSet.next()){
String column_value = resultSet.getString("COLUMN_NAME");
log.debug(column_value);
}

} catch(Exception e){
log.error("Exception occurred: " +e);
}
connection.close();

Rule to create a table in database

import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import sailpoint.plugin.PluginBaseHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


Logger log = Logger.getLogger("sailpoint.rules.CreatePluginDBTable");
log.setLevel(Level.DEBUG);
log.debug("-----------------------------------");

ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try{
Connection connection = PluginBaseHelper.getConnection();
log.debug("Connection established to DB: " + connection.getCatalog());
String createTableQuery = "CREATE TABLE Tablename(column1 varchar(255)); ";
preparedStatement = connection.prepareStatement(createTableQuery);
log.debug("Executing the query: " +createTableQuery);
preparedStatement.execute();
} catch(Exception e){
log.error("Exception occurred: " +e);
}
connection.close();

Form AllowedValues rule to filter Identities with Active Regular Active Directory accounts and identity is active and correlated

 The rule type is AllowedValues. import org.apache.log4j.Level ; import org.apache.log4j.Logger ; import sailpoint.object.Filter ; import sa...