Developing custom APIs through the plugin framework

Description

Adam Creaney, Director of Technology Alliances, walks us through the IdentityIQ Plugin Framework and how to develop your own, custom APIs.

2 Likes

Hi. Where can I find the source code for the sample plugin created in this session? -Thanks

We have a good example plugin for reference located here: https://community.sailpoint.com/t5/Plugin-Framework/TodoPlugin-V3-zip/ta-p/79764

But also, below is the simple example REST class used:

package com.sailpoint.plugin.exampleplugin.rest;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.Map;
import java.util.Iterator;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import sailpoint.object.*;
import sailpoint.api.*;
import sailpoint.rest.plugin.BasePluginResource;
import sailpoint.rest.plugin.RequiredRight;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Util;

/**
 * @author Adam Creaney
 * 
 *         Class to manage all rest api calls.
 */
@Path("PluginExample")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RequiredRight("examplePluginRight")
public class ExamplePluginRestManager extends BasePluginResource {
	
	private static final Log	log	= LogFactory.getLog(ExamplePluginRestManager.class);
	private Response			response;
	
	public String getPluginName() {
		
		return "Example Plugin";
	}

	
	@GET
	@Path("example/{name}")
	public Response getExample(@PathParam("name") String name) throws GeneralException, SQLException {
		
		log.trace("Entering getExample...");
		SailPointContext context = SailPointFactory.getCurrentContext();
		int count = 0;
		try {
			QueryOptions qo = new QueryOptions();
			Iterator it = context.search(SyslogEvent.class, qo);
			while(it.hasNext()){
				SyslogEvent sle = (SyslogEvent) it.next();
			}
			String responseString = "UH OH";
			response = Response.status(Response.Status.OK).entity(responseString).build();
		} catch (GeneralException ge){
			response = Response.status(Response.Status.BAD_REQUEST).entity(ge.toString()).build();
		}


		log.trace("Exiting getExample...");

		return response;
	}
	
	@POST
	@Path("example")
	@RequiredRight("examplePluginRightWrite")
	public Response postExample(Map<String, Object> request) throws GeneralException, SQLException, ParseException {
		log.trace("Entering postExample...");
		Object country = "";
		Object job = "";

		try{
			country = request.get("country");
			job = request.get("job");
			if(country == null || job == null ){
				throw new GeneralException("Missing required value!");
			}

			response = Response.status(Response.Status.OK)
					.entity("The input country was: " + country + ", and the job was: " + job +"!").build();

		} catch (GeneralException e){
			response = Response.status(Response.Status.BAD_REQUEST)
					.entity(e.getMessage()).build();
		}

		log.trace("Exiting postExample...");
		
		return response;
	}

	/*
		SailPointContext context = SailPointFactory.getCurrentContext();

		QueryOptions qo = new QueryOptions();
		Iterator it = context.search(SyslogEvent.class, qo);
		while(it.hasNext()){
			SyslogEvent sle = (SyslogEvent) it.next();

		}
	*/
}

2 Likes

Hi, I implemented a new plugin from the example plugin. The new plugin works correctly and REST calls are executed successfully.
The infrastructure used is composed of four Taskservers that share a single database. However, REST calls are only successful if made on the server where the plugin was loaded, even though the plugin is visible from the other servers. Could there be some missing configuration or is there something I should do to solve this problem?

Thanks!

as plugins are loaded in database so it should work from all servers, you can try restarting the server and then test.

3 Likes

Thanks, this worked for me.

1 Like