OIM Custom Revoke Entitlement Validation Handler API


  1. package com.oimacamedy.provision;
  2. import java.io.Serializable;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import java.util.logging.Level;
  6. import oracle.core.ojdl.logging.ODLLogger;
  7. import oracle.iam.platform.Platform;
  8. import oracle.iam.platform.authopss.exception.AccessDeniedException;
  9. import oracle.iam.platform.kernel.ValidationException;
  10. import oracle.iam.platform.kernel.ValidationFailedException;
  11. import oracle.iam.platform.kernel.spi.ValidationHandler;
  12. import oracle.iam.platform.kernel.vo.BulkOrchestration;
  13. import oracle.iam.platform.kernel.vo.Orchestration;
  14. import oracle.iam.provisioning.api.ProvisioningService;
  15. import oracle.iam.provisioning.exception.EntitlementInstanceNotFoundException;
  16. import oracle.iam.provisioning.exception.EntitlementNotProvisionedException;
  17. import oracle.iam.provisioning.resources.LRB;
  18. import oracle.iam.provisioning.util.ProvisioningUtil;
  19. import oracle.iam.provisioning.vo.EntitlementInstance;
  20. import com.thortech.xl.dataaccess.tcClientDataAccessException;
  21. import com.thortech.xl.dataaccess.tcDataProvider;
  22. import com.thortech.xl.dataaccess.tcDataSet;
  23. import com.thortech.xl.dataaccess.tcDataSetException;
  24. import com.thortech.xl.dataobj.PreparedStatementUtil;
  25. import com.thortech.xl.dataobj.util.XLDatabase;
  26. import com.thortech.xl.orb.dataaccess.tcDataAccessException;
  27. public class CustomRevokeEntitlementValidationHandler implements ValidationHandler { 
  28.  String className = "CustomRevokeEntitlementValidationHandler :";
  29.  public ODLLogger logger = ODLLogger.getODLLogger("com.massiveGaze.provision");
  30.  private String userEntitlementsQuery = "SELECT COUNT(*) AS COUNT FROM ENT_ASSIGN, USR WHERE ENT_ASSIGN.USR_KEY = USR.USR_KEY AND ENT_ASSIGN.ENT_STATUS='Provisioned' AND ENT_ASSIGN.ENT_ASSIGN_KEY=? AND USR.USR_KEY=?";
  31.  @Override
  32.  public void initialize(HashMap<String, String> arg0) {
  33.   // TODO Auto-generated method stub
  34.  }
  35.  @Override
  36.  public void validate(long processId, long eventId, Orchestration orchestration)
  37.    throws ValidationException, ValidationFailedException {
  38.   String METHOD_NAME = "validate()::", userId="",entitlementInstanceId="";
  39.   logger.entering(className, METHOD_NAME);
  40.   HashMap orchParameters = orchestration.getParameters();
  41.   long entitlementInstanceKey;
  42.   Serializable[] params = null;
  43.   logger.log(Level.FINE, "processid: "+processId+" eventId: "+eventId+" Orchestration parameters: "+orchParameters);
  44.   try
  45.      {
  46.        userId = (String)orchParameters.get("BeneficiaryKey");
  47.        logger.logp(Level.INFO, getClass().getName(), METHOD_NAME, "userId: " + userId);
  48.      }
  49.      catch (Exception e)
  50.      {
  51.        params = new Serializable[] { getClass().getName(), userId, e.getMessage() };
  52.        logger.logp(Level.SEVERE, getClass().getName(), METHOD_NAME, "IAM-4060000", params);
  53.        throw ProvisioningUtil.createValidationFailedException("IAM-4060000", null, processId, e, params);
  54.      }
  55.       try
  56.      {
  57.        entitlementInstanceId = (String)orchParameters.get("EntitlementInstanceKey");
  58.        logger.logp(Level.INFO, getClass().getName(), METHOD_NAME, "entitlementInstanceId: " + entitlementInstanceId);
  59.        entitlementInstanceKey = Long.parseLong(entitlementInstanceId);
  60.      }
  61.      catch (Exception e)
  62.      {
  63.        params = new Serializable[] { getClass().getName(), entitlementInstanceId, e.getMessage() };
  64.        logger.logp(Level.SEVERE, getClass().getName(), METHOD_NAME, "IAM-40600011", params);
  65.        throw ProvisioningUtil.createValidationFailedException("IAM-40600011", null, processId, e, params);
  66.      }
  67.     tcDataProvider dataProvider = this.getOIMDataProviderInstance(logger);
  68.      try {
  69.    if(this.isEntitlementAssignedToUser(userId, entitlementInstanceId, dataProvider)){
  70.     ProvisioningService provisioningService = Platform.getService(ProvisioningService.class);
  71.     EntitlementInstance entitlementInstance = provisioningService.getEntitlementInstance(entitlementInstanceKey);
  72.     logger.logp(Level.INFO, getClass().getName(), METHOD_NAME, "Found EntitlementInstance for entitlementInstanceId: " + entitlementInstanceId);
  73.     logger.logp(Level.FINE, getClass().getName(), METHOD_NAME, "EntitlementInstance retrieved: "+entitlementInstance);
  74.     if(entitlementInstance!=null){
  75.      orchestration.addParameter("EntitlementInstance", entitlementInstance);
  76.     }else{
  77.      params = new Serializable[] { getClass().getName(), entitlementInstanceId, userId };
  78.            logger.logp(Level.SEVERE, getClass().getName(), METHOD_NAME, "IAM-40600013", params);
  79.            String errorMessage = LRB.DEFAULT.getString("IAM-40600013", params);
  80.            throw new EntitlementNotProvisionedException("IAM-40600013", errorMessage, params);
  81.     }    
  82.    }else{
  83.     params = new Serializable[] { getClass().getName(), entitlementInstanceId, userId };
  84.           logger.logp(Level.SEVERE, getClass().getName(), METHOD_NAME, "IAM-40600013", params);
  85.           String errorMessage = LRB.DEFAULT.getString("IAM-40600013", params);
  86.           throw new EntitlementNotProvisionedException("IAM-40600013", errorMessage, params);
  87.    }
  88.   } catch (tcDataAccessException e) {
  89.    params = new Serializable[] { getClass().getName(), entitlementInstanceId, userId };
  90.    logger.log(Level.SEVERE, "tcDataAccessException",e);
  91.       throw ProvisioningUtil.createValidationFailedException("IAM-40600014", null, processId, e, params);
  92.   } catch (SQLException e) {
  93.    params = new Serializable[] { getClass().getName(), entitlementInstanceId, userId };
  94.    logger.log(Level.SEVERE, "SQLException",e);
  95.       throw ProvisioningUtil.createValidationFailedException("IAM-40600014", null, processId, e, params);
  96.   } catch (tcDataSetException e) {
  97.    params = new Serializable[] { getClass().getName(), entitlementInstanceId, userId };
  98.    logger.log(Level.SEVERE, "tcDataSetException",e);
  99.       throw ProvisioningUtil.createValidationFailedException("IAM-40600014", null, processId, e, params);
  100.   } catch (AccessDeniedException e) {
  101.    params = new Serializable[] { getClass().getName(), entitlementInstanceId, userId };
  102.    logger.log(Level.SEVERE, "AccessDeniedException",e);
  103.       throw ProvisioningUtil.createValidationFailedException("IAM-40600014", null, processId, e, params);
  104.   } catch (EntitlementInstanceNotFoundException e) {
  105.    params = new Serializable[] { getClass().getName(), entitlementInstanceId, userId };
  106.    logger.log(Level.SEVERE, "EntitlementInstanceNotFoundException",e);
  107.       throw ProvisioningUtil.createValidationFailedException("IAM-40600014", null, processId, e, params);
  108.   } catch (Exception e) {
  109.    params = new Serializable[] { getClass().getName(), entitlementInstanceId, userId };
  110.    logger.log(Level.SEVERE, "GenericProvisioningException",e);
  111.       throw ProvisioningUtil.createValidationFailedException("IAM-40600014", null, processId, e, params);
  112.   }finally{
  113.    if(dataProvider!=null){
  114.     this.closeDataProvider(dataProvider, logger);
  115.    }
  116.   }     
  117.  } 
  118.  public tcDataProvider getOIMDataProviderInstance(ODLLogger logger){
  119.   String methodName = "getOIMDataProviderInstance()::";
  120.   tcDataProvider dataProvider = null;
  121.   logger.entering(this.getClass().getName(), methodName);
  122.   logger.log(Level.FINE, " Instantiating tcBaseUtility class...");
  123.   XLDatabase database = XLDatabase.getInstance();
  124.   dataProvider = database.getDataBase();
  125.   logger.log(Level.FINE, " Getting dataProvider instance....");
  126.   logger.exiting(this.getClass().getName(), methodName);
  127.   return dataProvider;
  128.  } 
  129.  public void closeDataProvider(tcDataProvider dataProvider, ODLLogger logger){
  130.   String methodName = "closeDataProvider()::";
  131.   logger.entering(this.getClass().getSimpleName(), methodName);
  132.   try {
  133.    if(dataProvider!=null && dataProvider.isOpen()){
  134.     dataProvider.close();
  135.     logger.log(Level.FINE, "tcDataProvider instance closed successfully.");
  136.    }
  137.   } catch (tcDataAccessException e) {
  138.    logger.log(Level.SEVERE, "tcDataAccessException", e);
  139.   } catch (tcClientDataAccessException e) {
  140.    logger.log(Level.SEVERE, "tcClientDataAccessException", e);
  141.   }
  142.   logger.exiting(this.getClass().getSimpleName(), methodName);
  143.  } 
  144.  /**
  145.   * @param userDetails
  146.   * @return
  147.   * @throws SQLException
  148.   * @throws tcDataSetException 
  149.   * @throws tcDataAccessException 
  150.   * @throws Exception
  151.   */
  152.  public boolean isEntitlementAssignedToUser(String userKey, String entitlementAssignmentKey, tcDataProvider dataProvider) throws SQLException, tcDataSetException, tcDataAccessException {
  153.   String methodName = "isEntitlementAssignedToUser()::";
  154.   tcDataSet dataSet = null;
  155.   boolean entitlementAssignedToUser=false;
  156.   PreparedStatementUtil preparedStatementUtil = new PreparedStatementUtil();
  157.   logger.entering(this.getClass().getSimpleName(), methodName);
  158.   logger.log(Level.FINE,"Parameters passed to the method userKey: "+userKey+" entitlementAssignmentKey: "+entitlementAssignmentKey+", dataprovider: "+dataProvider);
  159.   try {
  160.     if(userKey!=null && userKey.trim().length()>0 && entitlementAssignmentKey!=null && entitlementAssignmentKey.trim().length()>0
  161.       && dataProvider!=null){
  162.      dataSet = new tcDataSet();
  163.      String dbQuery = this.userEntitlementsQuery;
  164.      preparedStatementUtil.setStatement(dataProvider, dbQuery);
  165.      preparedStatementUtil.setLong(1, Long.parseLong(entitlementAssignmentKey));
  166.      preparedStatementUtil.setLong(2, Long.parseLong(userKey));
  167.      logger.log(Level.FINE, " Query to be executed is: "+dbQuery);
  168.      preparedStatementUtil.execute();
  169.      dataSet = preparedStatementUtil.getDataSet();
  170.      if(!dataSet.isEmpty()){
  171.       logger.log(Level.FINE, " Number of records fetched are: "+dataSet.getRowCount());
  172.       if(dataSet.getString("COUNT").equalsIgnoreCase("1")){
  173.        entitlementAssignedToUser=true;
  174.       }else{
  175.        logger.logp(Level.SEVERE, getClass().getName(), methodName, "Entitlement assignment key "+entitlementAssignmentKey+" is not assigned to user "+userKey);
  176.       }
  177.      }
  178.     }else{
  179.      logger.log(Level.SEVERE, " Invalid parameters passed to the method - [userKey: "+userKey+" entitlementKey: "+entitlementAssignmentKey+" dataProvider: "+dataProvider+"]");
  180.     }
  181.   } catch (tcDataSetException e) {
  182.    logger.log(Level.SEVERE, "tcDataSetException", e);
  183.    throw e;
  184.   }finally{
  185.    if(dataSet!=null){
  186.     dataSet = null;
  187.    }
  188.   }
  189.   logger.exiting(this.getClass().getSimpleName(), methodName);
  190.   return entitlementAssignedToUser;
  191.  } 
  192.  @Override
  193.  public void validate(long arg0, long arg1, BulkOrchestration arg2)
  194.    throws ValidationException, ValidationFailedException {
  195.   // TODO Auto-generated method stub  
  196.  }
  197. }

No comments:

Post a Comment