Saturday, August 25, 2018

Run Sailpoint Client Code from Eclipse

To run Sailpoint client code from Eclipse the below structure should be there in eclipes
1. src
     - spclient .java (given in this blog)

     - iiq.properties  ( copy from C:\<application server>\webapps\identityiq\WEB-INF\classes\ path)

     - iiqBeans.xml  ( unzip C:\<application server>\webapps\identityiq\WEB-INF\lib\identityiq.jar and copy iiqBeans.xml in Eclipes Src folder)


2. Lib
     - Copy all jar from C:\<application server>\webapps\identityiq\WEB-INF\lib\
     - Add all jars in java build path.

Please note: The IIQ path mentioned in the code should be accessible by Eclipse.

Hit the run button :)

Source code:

import sailpoint.api.SailPointContext;
import sailpoint.api.SailPointFactory;
import sailpoint.object.Identity;
import sailpoint.spring.SpringStarter;
import sailpoint.tools.GeneralException;

public class spclient {
      
       /**
        * Create Sailpoint context
        * @return
        */

       private SailPointContext getSailpointContext() {
              SailPointContext context =null;
              String override=null;
              SpringStarter ss= new SpringStarter ("iiqBeans.xml",override);
              String configFile=ss.getConfigFile();
              System.out.println("config File::"+configFile);
              String[] services = {"Task","Request"};
              SpringStarter.setSuppressedServices(services);
              SpringStarter.suppressSchedulers();
              SpringStarter.setSuppressVersionChecker(true);
              ss.start();
              System.out.println("HERE");

              try {
                     context= SailPointFactory.createContext("identityiq");
                     if(context !=null) {
                           System.out.println("Got Connection "+context);
                           context.authenticate("spadmin", "admin"); //Provide current id password.
                     }else {
                           System.out.println("null Connection ");
                     }
              }catch(Exception e) {
                     e.printStackTrace();
              }
              return context;
       }
       /**
        * Search Identity
        * @param context
        * @param identiyName
        * @return
        */

       private Identity searchIdentity (SailPointContext context, String identiyName) {
              Identity identity =null;
              Boolean inactivityflag=true;
              System.out.println("Nirupam");

              try {
                     identity= context.getObject(Identity.class,identiyName);
                     System.out.println("First Name::"+identity.getFirstname());
                     System.out.println("Last Name::"+identity.getLastname());
                     inactivityflag=(Boolean) identity.getAttribute("inactive");
                     System.out.println("inactivityflag::"+inactivityflag);
              } catch (GeneralException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
              }
              return identity;
       }

       public static void main (String[] args) {
          String path= "C:\\Tomcat8\\webapps\\identityiq"; // provide the path from your install Directory
              System.setProperty("SPHOME",path);
              System.setProperty("SP_HOME",path); 
              System.setProperty("sailpoint.home",path);
              SailPointContext context =null;
              System.out.println("Establishing Connection ");
              spclient sc=new spclient();
              context =sc.getSailpointContext();
              sc.searchIdentity(context,"spadmin");
              try {
                     context.close();
              } catch (GeneralException e) {
                     e.printStackTrace();
              }
       }

}

Saturday, February 10, 2018

Start a Service in windows using script

Save the below lines of code in a .bat file. I am trying to start MySQL57 service if its not running already.


for /F "tokens=3 delims=: " %%H in ('sc query MySQL57 ^| findstr " STATE"') do ( if /I "%%H" NEQ "RUNNING" ( net start MySQL57 ) )