Tuesday, February 6, 2024

Adv Policy Java

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

public class Policy{

Map<String, String> identityRoles = new HashMap<>();

Map<String, String> requestRoles = new HashMap<>();

Map<String, Integer> tempMap = new HashMap<>();

List<String> duplicateReq = new ArrayList<>();

Map<String, String> customOrg = new HashMap<>();


public void validationInProcess() {

customOrg.put("orgO1", "Organization One DName");

customOrg.put("orgO2", "Organization two DName");


identityRoles.put("BR1", "orgO1");

identityRoles.put("BR2", "orgO2");

identityRoles.put("BR9", "orgO3");

identityRoles.put("BR12", "orgO4");


requestRoles.put("BR2", "orgO1");

requestRoles.put("BR1", "orgO2");

requestRoles.put("BR10", "orgO4");

requestRoles.put("BR11", "orgO5");


if (!requestRoles.isEmpty() && identityRoles.isEmpty()) {

if (requestRoles.size() == 1) {

System.out.println("Requested one role and no assigned roles found. Processing request. ");

} else {

System.out.println("Requested multiple Roles. Undergoing Organization duplicate valdiation.");

List<String> listOfReqRoles = new ArrayList<>(requestRoles.values());

List<String> duplicateReq = validateDuplicateOrg(listOfReqRoles);

processRequest(duplicateReq);

}

} else if (!identityRoles.isEmpty() && requestRoles.isEmpty()) {

if (requestRoles.size() == 1) {

System.out.println("Requested one role and no assigned roles found. Processing request. ");

} else {

System.out.println("Requested multiple Roles. Undergoing Organization duplicate valdiation.");

List<String> listOfDetRoles = new ArrayList<>(identityRoles.values());

List<String> duplicateDet = validateDuplicateOrg(listOfDetRoles);

processRequest(duplicateDet);

}

} else if (!identityRoles.isEmpty() && !requestRoles.isEmpty()) {

if (requestRoles.size() == 1) {

System.out.println("Requested One Role");

validateRoleCount(identityRoles, requestRoles);

} else {

List<String> listOfReqRoles = new ArrayList<>(requestRoles.values());

List<String> duplicateReq = validateDuplicateOrg(listOfReqRoles);

if (processRequest(duplicateReq)) {

validateRoleCount(identityRoles, requestRoles);

}

}

}

}

public List<String> validateDuplicateOrg(List<String> listOfRoles) {

List<String> duplicate = new ArrayList<>();

System.out.println("Validating Duplication. Requested Role's Organization : " + listOfRoles.toString());

for (int i = 0; i < listOfRoles.size(); i++) {

for (int j = i + 1; j < listOfRoles.size(); j++) {

if (listOfRoles.get(i).equalsIgnoreCase(listOfRoles.get(j))) {

duplicate.add(listOfRoles.get(i));

}

}

}

return duplicate;

}

public boolean processRequest(List<String> processList) {

boolean flag = false;

if (!processList.isEmpty()) {

for (int i = 0; i < processList.size(); i++) {

if (customOrg.containsKey(processList.get(i))) {

System.out.println("Requested Roles found Duplicate Org : " + processList.get(i));

flag = false;

} else {

System.out.println("Requeste role not found in Org . Processing Request");

flag = true;

}

}

} else {

System.out.println("No duplicate found. Processing request.");

flag = true;

}

return flag;

}

public Map<String, Integer> validateRoleCount(Map<String, String> identityRoles, Map<String, String> requestRoles) {

int OrgCount = 0;

for (Map.Entry<String, String> identityRole : identityRoles.entrySet()) {

for (Map.Entry<String, String> requestRole : requestRoles.entrySet()) {

if (customOrg.containsKey(identityRole.getValue()) && customOrg.containsKey(requestRole.getValue())) {

if (identityRole.getValue().equalsIgnoreCase(requestRole.getValue())) {

OrgCount++;

}

}

}

if (OrgCount >= 1) {

for (Map.Entry<String, String> customRole : customOrg.entrySet()) {

if (customRole.getKey().equalsIgnoreCase(identityRole.getValue())) {

OrgCount += 1;

tempMap.put(customRole.getKey(), OrgCount);

}

}

}

OrgCount = 0; }

for (Map.Entry<String, Integer> entry : tempMap.entrySet())

System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());

return tempMap;

}

public static void main(String[] args) {

new Policy().validationInProcess();

}

}


No comments:

Post a Comment

Fetch Members from Workgroup

  import java.util.ArrayList;   import java.util.Iterator;   import java.util.List;   import sailpoint.api.ObjectUtil;   import sailpoint.ob...