Provision Account
Generally, you come across scenario where to provision user accounts through API based on customer requirements.Oracle Identity Manager allows you to provision account using the OIM API. Sometimes you will need give account from remote operations (web service or some remote connector).
For this, firstly you need to find out the right application instance for the provisioning account. To find the right application instance, Oracle has pre-defined API
findApplicationInstanceByName method of oracle.iam.provisioning.api.ApplicationInstanceService
Once you are able to find the right application instance then use the same for provisioning account. To provision account, use the oracle.iam.provisioning.api.ProvisioningService
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import oracle.iam.platform.Platform;
import oracle.iam.provisioning.api.ApplicationInstanceService;
import oracle.iam.provisioning.api.ProvisioningService;
import oracle.iam.provisioning.exception.ApplicationInstanceNotFoundException;
import oracle.iam.provisioning.exception.GenericAppInstanceServiceException;
import oracle.iam.provisioning.exception.GenericProvisioningException;
import oracle.iam.provisioning.exception.UserNotFoundException;
import oracle.iam.provisioning.vo.Account;
import oracle.iam.provisioning.vo.AccountData;
import oracle.iam.provisioning.vo.ApplicationInstance;
import oracle.iam.provisioning.vo.FormInfo;
/** ProvisionAccount.java
*
* illustrates how to provision account
* based on ApplicationInstance Name
* @author Nagaraju Gorrepati
*/
public class ProvisionAccount {
protected static Logger logger = Logger.getLogger("ProvisionAccount");
/*Make sure Log Handler is configued on ProvisonAccount*/
private static String classname;
public ProvisionAccount() {
classname = getClass().getName();
}
/**
* This method is used to provisionAccount
* @param userKey
* @throws UserNotFoundException
* @throws ApplicationInstanceNotFoundException
* @throws GenericProvisioningException
*/
public void provisionAccount(String userKey) {
String methodName =
Thread.currentThread().getStackTrace()[1].getMethodName();
logger.finest(classname + "::" + methodName + "::started");
/**@param serverName ProcessFormFiledName
*/
String serverName = null;
/**
* @param itResourceName
* The ITResource Name for application that needs to be provisioned
* It holds the connection information to connect the target system
* from OIM
*/
String itResourceName = null;
ApplicationInstance appInstance = null;
ProvisioningService service =
Platform.getService(ProvisioningService.class);
try {
appInstance = findApplicationInstanceByName("XXXXXX");
// XXXXXX represents Application Instance Name
} catch (ApplicationInstanceNotFoundException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
} catch (GenericAppInstanceServiceException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
}
FormInfo formInfo = appInstance.getAccountForm();
Map parentData = new HashMap();
parentData.put(serverName, itResourceName);
//serverName example : UD_ADUSER_SERVER
//itResourceName example : Active Directory
//Add data that needs to populate for the account
String formKey = String.valueOf(formInfo.getFormKey());
AccountData accountData = new AccountData(formKey, null, parentData);
Account account = new Account(appInstance, accountData);
account.setAccountType(Account.ACCOUNT_TYPE.Primary);
try {
service.provision(userKey, account);
} catch (UserNotFoundException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
} catch (ApplicationInstanceNotFoundException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
} catch (GenericProvisioningException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
}
logger.finest(classname + "::" + methodName + "::Finished");
}
/**
* This method is used to findfindApplicationInstanceByName
* @param applicationInstanceName
* @throws ApplicationInstanceNotFoundException
* @throws GenericAppInstanceServiceException
* @return
*/
public ApplicationInstance findApplicationInstanceByName(String applicationInstanceName) {
String methodName =
Thread.currentThread().getStackTrace()[1].getMethodName();
logger.finest(classname + "::" + methodName + "::started");
ApplicationInstanceService service =
Platform.getService(ApplicationInstanceService.class);
ApplicationInstance appInstance = null;
try {
appInstance =
service.findApplicationInstanceByName(applicationInstanceName);
} catch (ApplicationInstanceNotFoundException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
} catch (GenericAppInstanceServiceException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
}
return appInstance;
logger.finest(classname + "::" + methodName + "::Finished");
}
}
import java.util.Map;
import java.util.logging.Logger;
import oracle.iam.platform.Platform;
import oracle.iam.provisioning.api.ApplicationInstanceService;
import oracle.iam.provisioning.api.ProvisioningService;
import oracle.iam.provisioning.exception.ApplicationInstanceNotFoundException;
import oracle.iam.provisioning.exception.GenericAppInstanceServiceException;
import oracle.iam.provisioning.exception.GenericProvisioningException;
import oracle.iam.provisioning.exception.UserNotFoundException;
import oracle.iam.provisioning.vo.Account;
import oracle.iam.provisioning.vo.AccountData;
import oracle.iam.provisioning.vo.ApplicationInstance;
import oracle.iam.provisioning.vo.FormInfo;
/** ProvisionAccount.java
*
* illustrates how to provision account
* based on ApplicationInstance Name
* @author Nagaraju Gorrepati
*/
public class ProvisionAccount {
protected static Logger logger = Logger.getLogger("ProvisionAccount");
/*Make sure Log Handler is configued on ProvisonAccount*/
private static String classname;
public ProvisionAccount() {
classname = getClass().getName();
}
/**
* This method is used to provisionAccount
* @param userKey
* @throws UserNotFoundException
* @throws ApplicationInstanceNotFoundException
* @throws GenericProvisioningException
*/
public void provisionAccount(String userKey) {
String methodName =
Thread.currentThread().getStackTrace()[1].getMethodName();
logger.finest(classname + "::" + methodName + "::started");
/**@param serverName ProcessFormFiledName
*/
String serverName = null;
/**
* @param itResourceName
* The ITResource Name for application that needs to be provisioned
* It holds the connection information to connect the target system
* from OIM
*/
String itResourceName = null;
ApplicationInstance appInstance = null;
ProvisioningService service =
Platform.getService(ProvisioningService.class);
try {
appInstance = findApplicationInstanceByName("XXXXXX");
// XXXXXX represents Application Instance Name
} catch (ApplicationInstanceNotFoundException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
} catch (GenericAppInstanceServiceException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
}
FormInfo formInfo = appInstance.getAccountForm();
Map parentData = new HashMap();
parentData.put(serverName, itResourceName);
//serverName example : UD_ADUSER_SERVER
//itResourceName example : Active Directory
//Add data that needs to populate for the account
String formKey = String.valueOf(formInfo.getFormKey());
AccountData accountData = new AccountData(formKey, null, parentData);
Account account = new Account(appInstance, accountData);
account.setAccountType(Account.ACCOUNT_TYPE.Primary);
try {
service.provision(userKey, account);
} catch (UserNotFoundException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
} catch (ApplicationInstanceNotFoundException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
} catch (GenericProvisioningException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
}
logger.finest(classname + "::" + methodName + "::Finished");
}
/**
* This method is used to findfindApplicationInstanceByName
* @param applicationInstanceName
* @throws ApplicationInstanceNotFoundException
* @throws GenericAppInstanceServiceException
* @return
*/
public ApplicationInstance findApplicationInstanceByName(String applicationInstanceName) {
String methodName =
Thread.currentThread().getStackTrace()[1].getMethodName();
logger.finest(classname + "::" + methodName + "::started");
ApplicationInstanceService service =
Platform.getService(ApplicationInstanceService.class);
ApplicationInstance appInstance = null;
try {
appInstance =
service.findApplicationInstanceByName(applicationInstanceName);
} catch (ApplicationInstanceNotFoundException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
} catch (GenericAppInstanceServiceException e) {
logger.severe(classname + "::" + methodName + e.getMessage());
}
return appInstance;
logger.finest(classname + "::" + methodName + "::Finished");
}
}
No comments:
Post a Comment