Custom scheduled task in Sailpoint
Check If all associated entitlements not find in particular account for a identity, then the account end date is update using custom task in sailpoint.
1. First we have to create task_defination.xml .
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE sailpoint PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<sailpoint>
<TaskDefinition executor="sailpoint.custom.task.DeleteAccountTask" name="Delete account task" progressInterval="5000" progressMode="String" resultAction="Rename" template="true" type="Generic">
<Description>
Check If all associated entitlements not find in particular account for a identity, then the account end date is update using custom task in sailpoint.
</Description>
<Signature>
<!-- If you need to pass any input parameters to custom task user below tags in xml-->
<!-- <Inputs>
<Returns>
<Argument name="success" type="boolean">
<Prompt>Success: </Prompt>
</Argument>
<Argument name="messages" type="string">
<Prompt>Messages: </Prompt>
</Argument>
</Returns>
</Signature>
</TaskDefinition>
</sailpoint>
2. Create a class file using eclipse IDE.
package sailpoint.custom.task;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import sailpoint.api.SailPointContext;
import sailpoint.object.Application;
import sailpoint.object.Attributes;
import sailpoint.object.Filter;
import sailpoint.object.Link;
import sailpoint.object.QueryOptions;
import sailpoint.object.TaskResult;
import sailpoint.object.TaskSchedule;
import sailpoint.task.AbstractTaskExecutor;
import sailpoint.task.TaskMonitor;
import sailpoint.tools.GeneralException;
public class DeleteAccountTask extends AbstractTaskExecutor {
Logger logger = Logger.getLogger("DeleteAccountTask");
private boolean isSuccess = false;
private String messages = null;
public boolean isSuccess() {
return isSuccess;
}
public void setSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
public String getMessages() {
return messages;
}
public void setMessages(String messages) {
this.messages = messages;
}
/**
* method that will be executed when the task executes
*/
@Override
public void execute(SailPointContext paramSailPointContext, TaskSchedule paramTaskSchedule,
TaskResult paramTaskResult, Attributes<String, Object> paramAttributes) throws Exception {
// TODO Auto-generated method stub
TaskMonitor localTaskMonitor = new TaskMonitor(paramSailPointContext, paramTaskResult);
setMonitor(localTaskMonitor);
localTaskMonitor.updateProgress("Parsing Arguments");
/**
*check If all associated entitlements in
* account end date is reached for a identity, then the account validity should also be end dated.
*/
try {
List<Application> applications = paramSailPointContext.getObjects(Application.class);
for (Application applicationList : applications) {
String appType = applicationList.getType();
logger.info("Application Type::::"+appType +"Application Name::::::"+applicationList.getName());
if ("AppType".equalsIgnoreCase(appType)) {
List<Link> links=getLinkAccounts(paramSailPointContext,applicationList.getName());
logger.info("AppType:Start"+links);
if (links != null && links.size() > 0) {
for (Link link : links) {
logger.info("Identiy's "+link.getIdentity());
if (!link.isEntitlements()) {
Date date = new Date();
Date myDate = addOrSubtractDays(date, -1);
link.setAttribute("validDate", myDate);
paramSailPointContext.saveObject(link);
paramSailPointContext.commitTransaction();
logger.info("Account End Date is updated sucessfully for AppType!!");
}
}
}
}else{
logger.info("Any App type is not matching!!");
}
}
} catch (Exception e) {
e.printStackTrace();
}
setSuccess(true);
localTaskMonitor.updateProgress("Finished.");
logger.debug("Finished!!");
populateTaskResult(paramTaskResult);
}
/**
*
* @param paramSailPointContext
* @param appName
* @return the list of the identity and linked entitlements for the application
*/
public List<Link> getLinkAccounts(SailPointContext paramSailPointContext,String appName){
List<Link> links=null;
try {
Application application = paramSailPointContext.getObjectByName(Application.class, appName);
Filter filter = Filter.eq("application", application);
QueryOptions query = new QueryOptions();
query.addFilter(filter);
links =paramSailPointContext.getObjects(Link.class, query);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return links;
}
/**
*
* @param date
* @param days
* @return
*/
public Date addOrSubtractDays(Date date, int days)
{
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, days); //minus number would decrement the days
logger.debug("Date method ::::::"+cal.getTime());
return cal.getTime();
}
/**
*
* @param paramTaskResult
*/
private void populateTaskResult(TaskResult paramTaskResult) {
paramTaskResult.setAttribute("success", Boolean.valueOf(isSuccess()));
paramTaskResult.setAttribute("messages", getMessages());
}
@Override
public boolean terminate() {
// TODO Auto-generated method stub
return false;
}
}
3. Import task_defination.xml file using IIQ console.
Go to identityiq\WEB-INF\bin folder and run ./iiq console
>import task_defination.xml
4. Create DeleteAccountTask.class file and copy the .class file into the identityiq\WEB-INF\classes\sailpoint\custom\task folder and restart the server.
Goto Setup -> Tasks--> New Task and configure your custom task and schedule if required.
1. First we have to create task_defination.xml .
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE sailpoint PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<sailpoint>
<TaskDefinition executor="sailpoint.custom.task.DeleteAccountTask" name="Delete account task" progressInterval="5000" progressMode="String" resultAction="Rename" template="true" type="Generic">
<Description>
Check If all associated entitlements not find in particular account for a identity, then the account end date is update using custom task in sailpoint.
</Description>
<Signature>
<!-- If you need to pass any input parameters to custom task user below tags in xml-->
<!-- <Inputs>
<Argument name="appName" type="string">
<Prompt>Application Name:</Prompt>
</Argument>
</Inputs>-->
<Returns>
<Argument name="success" type="boolean">
<Prompt>Success: </Prompt>
</Argument>
<Argument name="messages" type="string">
<Prompt>Messages: </Prompt>
</Argument>
</Returns>
</Signature>
</TaskDefinition>
</sailpoint>
2. Create a class file using eclipse IDE.
package sailpoint.custom.task;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import sailpoint.api.SailPointContext;
import sailpoint.object.Application;
import sailpoint.object.Attributes;
import sailpoint.object.Filter;
import sailpoint.object.Link;
import sailpoint.object.QueryOptions;
import sailpoint.object.TaskResult;
import sailpoint.object.TaskSchedule;
import sailpoint.task.AbstractTaskExecutor;
import sailpoint.task.TaskMonitor;
import sailpoint.tools.GeneralException;
public class DeleteAccountTask extends AbstractTaskExecutor {
Logger logger = Logger.getLogger("DeleteAccountTask");
private boolean isSuccess = false;
private String messages = null;
public boolean isSuccess() {
return isSuccess;
}
public void setSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
public String getMessages() {
return messages;
}
public void setMessages(String messages) {
this.messages = messages;
}
/**
* method that will be executed when the task executes
*/
@Override
public void execute(SailPointContext paramSailPointContext, TaskSchedule paramTaskSchedule,
TaskResult paramTaskResult, Attributes<String, Object> paramAttributes) throws Exception {
// TODO Auto-generated method stub
TaskMonitor localTaskMonitor = new TaskMonitor(paramSailPointContext, paramTaskResult);
setMonitor(localTaskMonitor);
localTaskMonitor.updateProgress("Parsing Arguments");
/**
*check If all associated entitlements in
* account end date is reached for a identity, then the account validity should also be end dated.
*/
try {
List<Application> applications = paramSailPointContext.getObjects(Application.class);
for (Application applicationList : applications) {
String appType = applicationList.getType();
logger.info("Application Type::::"+appType +"Application Name::::::"+applicationList.getName());
if ("AppType".equalsIgnoreCase(appType)) {
List<Link> links=getLinkAccounts(paramSailPointContext,applicationList.getName());
logger.info("AppType:Start"+links);
if (links != null && links.size() > 0) {
for (Link link : links) {
logger.info("Identiy's "+link.getIdentity());
if (!link.isEntitlements()) {
Date date = new Date();
Date myDate = addOrSubtractDays(date, -1);
link.setAttribute("validDate", myDate);
paramSailPointContext.saveObject(link);
paramSailPointContext.commitTransaction();
logger.info("Account End Date is updated sucessfully for AppType!!");
}
}
}
}else{
logger.info("Any App type is not matching!!");
}
}
} catch (Exception e) {
e.printStackTrace();
}
setSuccess(true);
localTaskMonitor.updateProgress("Finished.");
logger.debug("Finished!!");
populateTaskResult(paramTaskResult);
}
/**
*
* @param paramSailPointContext
* @param appName
* @return the list of the identity and linked entitlements for the application
*/
public List<Link> getLinkAccounts(SailPointContext paramSailPointContext,String appName){
List<Link> links=null;
try {
Application application = paramSailPointContext.getObjectByName(Application.class, appName);
Filter filter = Filter.eq("application", application);
QueryOptions query = new QueryOptions();
query.addFilter(filter);
links =paramSailPointContext.getObjects(Link.class, query);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return links;
}
/**
*
* @param date
* @param days
* @return
*/
public Date addOrSubtractDays(Date date, int days)
{
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, days); //minus number would decrement the days
logger.debug("Date method ::::::"+cal.getTime());
return cal.getTime();
}
/**
*
* @param paramTaskResult
*/
private void populateTaskResult(TaskResult paramTaskResult) {
paramTaskResult.setAttribute("success", Boolean.valueOf(isSuccess()));
paramTaskResult.setAttribute("messages", getMessages());
}
@Override
public boolean terminate() {
// TODO Auto-generated method stub
return false;
}
}
3. Import task_defination.xml file using IIQ console.
Go to identityiq\WEB-INF\bin folder and run ./iiq console
>import task_defination.xml
4. Create DeleteAccountTask.class file and copy the .class file into the identityiq\WEB-INF\classes\sailpoint\custom\task folder and restart the server.
Goto Setup -> Tasks--> New Task and configure your custom task and schedule if required.
Comments
Post a Comment