import java.util.HashMap;
import java.util.Map;
public class OrgRole {
Map<String,String> custom=new HashMap<>();
Map<String,String> identityRoles=new HashMap<>();
Map<String,Integer> tempMap=new HashMap<>();
void ValidatingRole(){
custom.put("OrgR1", "OR1");
custom.put("OrgR2", "OR2");
custom.put("OrgR3", "OR3");
custom.put("OrgR4", "OR4");
identityRoles.put("OrgKey1", "OR4");
identityRoles.put("OrgKey2", "OR4");
identityRoles.put("OrgKey3", "OR4");
identityRoles.put("OrgKey4", "OR2");
identityRoles.put("OrgKey5", "OR2");
int OrgCount = 0;
for (Map.Entry<String,String> orgRole : custom.entrySet()) {
for (Map.Entry<String,String> identityRole : identityRoles.entrySet()) {
if(orgRole.getValue().equalsIgnoreCase(identityRole.getValue())) {
OrgCount++;
}
}
if(OrgCount >= 2){
tempMap.put(orgRole.getValue(), OrgCount);
}
OrgCount=0;
}
for (Map.Entry<String,Integer> entry : tempMap.entrySet())
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
public static void main(String[] args) {
new OrgRole().ValidatingRole();
}
}
====================================================================================================================================================
HashMap hashMap = null;
Custom custom = context.getObjectByName(Custom.class, "Container - SODRoles Custom Object");
attributes = custom.getAttributes();
List SODRolekeys = attributes.getKeys();
for (String containerRolekey : SODRolekeys) {
hashMap.put(containerRolekey, custom.get(containerRolekey));
}
====================================================================================================================================================
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AdvPolicyViolation {
List<String> duplicateReq = new ArrayList<>();
Map<String, String> customOrg = new HashMap<>();
Map<String, String> identityRoles = new HashMap<>();
Map<String, String> requestRoles = new HashMap<>();
Map<String, Integer> tempMap = new HashMap<>();
void ValidatingRole() {
customOrg.put("orgO1", "Organization One DName");
customOrg.put("orgO2", "Organization two DName");
identityRoles.put("BR1", "orgO1");
identityRoles.put("BR5", "orgO2");
identityRoles.put("BR9", "orgO3");
identityRoles.put("BR12", "orgO4");
requestRoles.put("BR2", "orgO1");
requestRoles.put("BR5", "orgO2");
requestRoles.put("BR10", "orgO4");
requestRoles.put("BR11", "orgO5");
if (requestRoles.size() == 1) {
System.out.println("One request role found");
validateRoleCount(identityRoles, requestRoles);
} else {
System.out.println("Multiple request roles are found");
List<String> listOfReqRoles = new ArrayList<>(requestRoles.values());
for (int i = 0; i < requestRoles.size(); i++) {
for (int j = i + 1; j < listOfReqRoles.size(); j++) {
if (listOfReqRoles.get(i).equalsIgnoreCase(listOfReqRoles.get(j))) {
duplicateReq.add(listOfReqRoles.get(i));
}
}
}
if (!duplicateReq.isEmpty()) {
for (int i = 0; i < duplicateReq.size(); i++) {
if (customOrg.containsKey(duplicateReq.get(i))) {
System.out.println("Requested Roles found Duplicate Org " + duplicateReq.get(i));
// return duplicates found
} else {
System.out.println("Requeste role not found in Org . Processing Request");
// process request
}
}
} else {
System.out.println("No duplicate found. Processing request.");
validateRoleCount(identityRoles, requestRoles);
}
}
}
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 AdvPolicyViolation().ValidatingRole();
}
}
No comments:
Post a Comment