Tuesday, 7 November 2017

OIM query to find Request Justification of a Request

Below is the sql query to find request justification for a user for already provisioned resource in OIM:

SELECT REQUEST.REQUEST_JUSTIFICATION FROM REQUEST
WHERE REQUEST_ID =(SELECT REQUEST_KEY FROM UD_ADUSER
WHERE UPPER(UD_ADUSER_USERID)=UPPER(?)  //user login
AND ORC_KEY IN (SELECT OIU.ORC_KEY FROM OBJ,OBI,OIU,OST,USR
WHERE OBJ.OBJ_KEY=OBI.OBJ_KEY
AND OBI.OBI_KEY=OIU.OBI_KEY
AND OIU.USR_KEY=USR.USR_KEY
AND OIU.OST_KEY=OST.OST_KEY
AND OST.OBJ_KEY=OBJ.OBJ_KEY
AND OBJ.OBJ_NAME='Active Directory'
AND OST.OST_STATUS IN ('Enabled','Provisioned')));

Thursday, 26 October 2017

Assign Access Policy to Role

This post helps you to pro-grammatically assign an access policy to role.Below is the code snippet:

                /**
                 * Assign access policy to role
                 * @param roleName
                 */
     public void assignAccessPolicyToOIMRole(String roleName) {
                Role role = null;
                SearchCriteria criteria = null;
                List<Role> roles = null;
                tcAccessPolicyOperationsIntf accessPolicyOperationsIntf=null;
                try {         
                                accessPolicyOperationsIntf=Platform
                                                                .getService(tcAccessPolicyOperationsIntf.class);
                                criteria = new SearchCriteria(RoleManagerConstants.ROLE_NAME,
                                roleName, SearchCriteria.Operator.EQUAL);
                                roles = roleManager.search(criteria, null, null);
                                HashMap<String, Object> roleMapAttrs = new HashMap<String,  
                                 Object>();
                                Map<String, List<String>> accessPoliciesMap = new  
                                                                 HashMap<String,List<String>>();
                                List<String> accessPolicies = new ArrayList<String>();
                                String accessPolicyName="Test Access Policy";
                                String  accessPolicyKey                                     =getAccessPolicyKey(accessPolicyName,accessPolicyOperationsIntf);
                                accessPolicies.add(accessPolicyKey);
                                accessPoliciesMap.put("ADD",accessPolicies);
                                roleMapAttrs.put(RoleManagerConstants.ACCESS_POLICIES,
                                         accessPoliciesMap);
                                role = new Role(roleMapAttrs);
                                RoleManagerResult roleManagerResult = roleManager.modify(
                                           RoleManagerConstants.ROLE_NAME,  
                                        roleName, role);
                                } catch (RoleSearchException e) {
                                                e.printStackTrace();
                                } catch (AccessDeniedException e) {
                                                e.printStackTrace();
                                } catch (ValidationFailedException e) {
                                                e.printStackTrace();
                                } catch (RoleModifyException e) {
                                                e.printStackTrace();
                                } catch (NoSuchRoleException e) {
                                                e.printStackTrace();
                                } catch (RoleLookupException e) {
                                                e.printStackTrace();
                                }

Get access policy key:  

private String getAccessPolicyKey(String accessPolicyName,
                                                tcAccessPolicyOperationsIntf accessPolicyOperationsIntf) {
                Map <String,String> apAttributeList = new HashMap<String,String>();
                String accessPolicyKey = null;
                try {
                                apAttributeList.put("Access Policies.Name", accessPolicyName);
                                                tcResultSet resultSet = accessPolicyOperationsIntf
                                                                                .findAccessPolicies(apAttributeList);
                                                if (resultSet == null || resultSet.getRowCount() == 0) {
                                                                return accessPolicyKey;
                                                }
                                                for (int i = 0; i < resultSet.getRowCount(); i++) {
                                                                resultSet.goToRow(i);
                                                                accessPolicyKey = resultSet.getStringValue("Access 
                                                                             Policies.Key");
                                                }
                                } catch (tcAPIException | tcColumnNotFoundException e) {
                                                    e.printStackTrace();
                                }
               
                return accessPolicyKey;
}