OIM API For Custom ProcessHandler sample

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.massiveGaze.provision;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;

import oracle.iam.platform.Platform;
import oracle.iam.platform.kernel.ValidationException;
import oracle.iam.platform.kernel.ValidationFailedException;
import oracle.iam.platform.kernel.spi.ConditionalEventHandler;
import oracle.iam.platform.kernel.spi.PreProcessHandler;
import oracle.iam.platform.kernel.vo.AbstractGenericOrchestration;
import oracle.iam.platform.kernel.vo.BulkEventResult;
import oracle.iam.platform.kernel.vo.BulkOrchestration;
import oracle.iam.platform.kernel.vo.EventResult;
import oracle.iam.platform.kernel.vo.Orchestration;
import oracle.iam.provisioning.api.ApplicationInstanceService;
import oracle.iam.provisioning.util.Constants;
import oracle.iam.provisioning.vo.ApplicationInstance;
import oracle.iam.provisioning.vo.Entitlement;


public class AccessPreProcessHandler implements PreProcessHandler, ConditionalEventHandler {
 String handlerName;
 String _appInstName;

 private void log(String msg) {
  System.out.println("[***" +handlerName+ "***]" + msg);
 }

 @Override
 public void initialize(HashMap<String, String> arg0) {
  handlerName = getClass().getSimpleName();
 }
 
 
 
 private boolean checkIfApplicable(AbstractGenericOrchestration orchn){
  String appInstName;
  appInstName = getAppInstanceName(orchn);

  if(appInstName == null) 
   return false;

  _appInstName = appInstName;
  log("Enhanced check: AppInstName [" + appInstName + "] is configured for BreakGlass");
  return true;
 }



 private String getAppInstanceName(AbstractGenericOrchestration orchn) {
  HashMap<String, Serializable> orchParams = orchn.getParameters();
  String appInstanceId = (String)orchParams.get(Constants.ORCH_PARAM_APPINSTANCE_KEY);
  ApplicationInstance appInst = getApplicationInstance(appInstanceId);
  if(appInst == null) 
   return null;
  log("App instance name for this ENT is: " + appInst.getApplicationInstanceName());
  return appInst.getApplicationInstanceName();
 }

 private ApplicationInstance getApplicationInstance(String appInstanceId){
  ApplicationInstance ai = null;
  try {
   ApplicationInstanceService aiService = getService(ApplicationInstanceService.class);
   if(aiService == null) 
    return null;
   if (appInstanceId != null) {
    ai = aiService.findApplicationInstanceByKey(new Long(appInstanceId)); 
   }
  } catch (Exception e) {
   log("Exception getting AppInst based on Id: " + appInstanceId + ". Error: " + e);
  }
  return ai;
 }


 @Override
 public boolean isApplicable(AbstractGenericOrchestration orchn) {
  return checkIfApplicable(orchn);
 }

 @Override
 public boolean cancel(long arg0, long arg1,
   AbstractGenericOrchestration arg2) {
  return false;
 }

 @Override
 public void compensate(long arg0, long arg1,
   AbstractGenericOrchestration arg2) {
 }


 @Override
 public EventResult execute(long processId, long eventId, Orchestration orchestration) throws ValidationException, ValidationFailedException {
  try {
   log("In execute()");
   if(!checkIfApplicable(orchestration))
    return new EventResult();
   
   HashMap<String, Serializable> orchParams = orchestration.getParameters();
   Entitlement entitlement = (Entitlement) orchParams.get(Constants.ORCH_PARAM_ENTITLEMENT);
   String entitlementDisplayName = entitlement.getEntitlementValue();
   String beneficiaryKey = (String) orchParams.get(Constants.ORCH_PARAM_BENEFICIARY_KEY);
   HashMap orchParamsChildDataMap = (HashMap)orchParams.get(Constants.ORCH_PARAM_CHILD_DATA);
   String mins = "15";
   if(mins == null) {
    log(entitlementDisplayName + " is setup without prefixing AppInstName tilde. Pls check.");
    return new EventResult();
   }
   Date endDate = getEntitlementEndDate(mins);
   log("Benefeciary: " + beneficiaryKey);
   log("Entitlement assigned: " + entitlementDisplayName);
   log("Entitlement END DATE is set to value:  " + endDate);
   orchParamsChildDataMap.put("endDate", endDate);
   return new EventResult();
  } catch (Exception exc) {
   return new EventResult();
  }
 }

 
 private Date getEntitlementEndDate(String minsToRevoke){
  int mins = Integer.parseInt(minsToRevoke);
  Calendar calender = new GregorianCalendar();
  log("GENERIC CODE - CURRENT DATE: " + calender.getTime());
  calender.add(Calendar.MINUTE, mins);
  return calender.getTime();
  
  
 }



 private <T> T getService(Class<T> serviceClass) {
  return Platform.getService(serviceClass);
 }

 @Override
 public BulkEventResult execute(long arg0, long arg1, BulkOrchestration arg2) {
  log("REQUEST CAME IN BULK ORCHESTRATION. NUMBER OF REQUEST PARAMS ARE: " + arg2.getBulkParameters().length);
  return new BulkEventResult();
 } 
 
}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts