package com.example.custompph;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.logging.Logger;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.vo.Identity;
import oracle.iam.platform.Platform;
import oracle.iam.platform.context.ContextAware;
import oracle.iam.platform.kernel.OrchestrationEngine;
import oracle.iam.platform.kernel.spi.PostProcessHandler;
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;
public class CustomPostProcessEventHandle implements PostProcessHandler {
private Logger logger = Logger.getLogger("oim_server1-diagnostic");
public CustomPostProcessEventHandle() {
super();
}
@Override
public EventResult execute(long l, long l2, Orchestration orchestration) {
return new EventResult();
}
@Override
public BulkEventResult execute(long l, long l2,
BulkOrchestration orchestration) {
UserManager userOperationsService = Platform.getService(UserManager.class);
String dPassword = null;
logger.info("BulkEventResult NEW");
try {
Identity[] newUserState = (Identity[])getNewUserStates(orchestration);
logger.info("newUserState :: " + newUserState);
String usrLogin = null;
for (int y = 0; y < newUserState.length; y++) {
usrLogin = newUserState[y].getAttribute("User Login").toString();
userOperationsService.changePassword(usrLogin,
newUserState[y].getAttribute("Common Name").toString().toCharArray(),
true); //Update Password Using Common Name
}
for (int u = 0; u < newUserState.length; u++) {
HashMap<String, Object> userAttrMap = newUserState[u].getAttributes();
Iterator iterator = userAttrMap.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next().toString();
Object value = userAttrMap.get(key);
}
}
Identity[] oldUserState = (Identity[])getOldUserStates(orchestration);
for (int y = 0; y < oldUserState.length; y++) {
logger.info(y + " . " + oldUserState[y]);
}
for (int u = 0; u < oldUserState.length; u++) {
HashMap<String, Object> userAttrMap = oldUserState[u].getAttributes();
Iterator iterator = userAttrMap.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next().toString();
Object value = userAttrMap.get(key);
}
}
} catch (Exception e) {
logger.info("In Catch");
logger.info("ERROR :: " + e.getMessage());
}
logger.info("Exiting BulkEvent");
return new BulkEventResult();
}
@Override
public void compensate(long l, long l2,
AbstractGenericOrchestration abstractGenericOrchestration) {
logger.info("Compensate");
}
@Override
public boolean cancel(long l, long l2,
AbstractGenericOrchestration abstractGenericOrchestration) {
return false;
}
@Override
public void initialize(HashMap<String, String> hashMap) {
logger.info("Initialize");
}
/**
* Get Parameters Valus
* @param parameters
* @param key
* @return
*/
private String getParamaterValue(HashMap<String, Serializable> parameters,
String key) {
String value =
(parameters.get(key) instanceof ContextAware) ? (String)((ContextAware)parameters.get(key)).getObjectValue() :
(String)parameters.get(key);
return value;
}
/**
* Judge Is Empty or null
* @param str
* @return
*/
private boolean isNullOrEmpty(String str) {
return str == null || str.isEmpty();
}
/**
* Get UserKey
* @param processID
* @param orchestration
* @return
*/
private String getUserKey(long processID, BulkOrchestration orchestration) {
String userKey;
String entityType = orchestration.getTarget().getType();
EventResult result = new EventResult();
if (!orchestration.getOperation().equals("CREATE")) {
userKey = orchestration.getTarget().getEntityId();
} else {
OrchestrationEngine orchEngine =
Platform.getService(OrchestrationEngine.class);
logger.info("The process ID is : " + processID);
userKey = (String)orchEngine.getActionResult(processID);
}
return userKey;
}
/**
* Get Random String
* @param n
* @return
*/
private static String getRandomString(int n) {
char[] pw = new char[n];
int c = ‘A’;
int r1 = 0;
for (int i = 0; i < n; i++) {
r1 = (int)(Math.random() * 3);
switch (r1) {
case 0:
c = ‘0’ + (int)(Math.random() * 10);
break;
case 1:
c = ‘a’ + (int)(Math.random() * 26);
break;
case 2:
c = ‘A’ + (int)(Math.random() * 26);
break;
}
pw[i] = (char)c;
}
return new String(pw);
}
/**
*
* @param orchestration
* @return
*/
private Object getNewUserStates(BulkOrchestration orchestration) {
Object newUserStates = null;
HashMap interEventData = orchestration.getInterEventData();
if (interEventData != null)
newUserStates = interEventData.get("NEW_USER_STATE");
return newUserStates;
}
/**
*
* @param orchestration
* @return
*/
private Object getOldUserStates(BulkOrchestration orchestration) {
Object oldUserStates = null;
HashMap interEventData = orchestration.getInterEventData();
if (interEventData != null)
oldUserStates = interEventData.get("CURRENT_USER");
return oldUserStates;
}
}
|