@Test public void testBuildEdOrgContextualRoles () { Set<Entity> seoas = new HashSet<Entity>(); seoas.add(createSEOA("LEA1", "IT Admin")); seoas.add(createSEOA("LEA1", "Educator")); seoas.add(createSEOA("LEA2", "Educator")); seoas.add(createSEOA("LEA2", "Educator")); Set<Role> edOrg1RolesSet = new HashSet<Role>(); edOrg1RolesSet.add(createRole("Educator")); edOrg1RolesSet.add(createRole("IT Admin")); Mockito.when(resolver.mapRoles(tenant, realmId, Arrays.asList("Educator", "IT Admin"), false)).thenReturn(edOrg1RolesSet); Mockito.when(resolver.mapRoles(tenant, realmId, Arrays.asList("IT Admin", "Educator"), false)).thenReturn(edOrg1RolesSet); Set<Role> edOrg2RolesSet = new HashSet<Role>(); edOrg2RolesSet.add(createRole("Educator")); Mockito.when(resolver.mapRoles(tenant, realmId, Arrays.asList("Educator"), false)).thenReturn(edOrg2RolesSet); Mockito.when(edorgHelper.locateNonExpiredSEOAs(staffId)).thenReturn(seoas); Map<String, List<String>> edOrgRoles = edOrgRoleBuilder.buildValidStaffRoles(realmId, staffId,tenant, samlRoles); Assert.assertNotNull(edOrgRoles); Assert.assertEquals(2,edOrgRoles.size()); List<String> edOrg1Roles = edOrgRoles.get("LEA1"); Assert.assertNotNull(edOrg1Roles); Assert.assertEquals(2, edOrg1Roles.size()); Assert.assertTrue(edOrg1Roles.contains("IT Admin")); Assert.assertTrue(edOrg1Roles.contains("Educator")); List<String> edOrg2Roles = edOrgRoles.get("LEA2"); Assert.assertNotNull(edOrg2Roles); Assert.assertEquals(1, edOrg2Roles.size()); Assert.assertTrue(edOrg2Roles.contains("Educator")); }
private Map<String, List<String>> buildEdOrgContextualRoles(Set<Entity> seoas, Set<String> samlRoleSet) { Map<String, List<String>> edOrgRoles = new HashMap<String, List<String>>(); if (seoas != null) { for (Entity seoa : seoas) { String edOrgId = (String) seoa.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE); String role = (String) seoa.getBody().get(ParameterConstants.STAFF_EDORG_ASSOC_STAFF_CLASSIFICATION); if(isValidRole(role, samlRoleSet)) { if (edOrgRoles.get(edOrgId) == null) { edOrgRoles.put(edOrgId, new ArrayList<String>()); edOrgRoles.get(edOrgId).add(role); } else if (!edOrgRoles.get(edOrgId).contains(role)) { edOrgRoles.get(edOrgId).add(role); } } } } return edOrgRoles; }
EdOrgContextualRoleBuilder { private Map<String, List<String>> buildEdOrgContextualRoles(Set<Entity> seoas, Set<String> samlRoleSet) { Map<String, List<String>> edOrgRoles = new HashMap<String, List<String>>(); if (seoas != null) { for (Entity seoa : seoas) { String edOrgId = (String) seoa.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE); String role = (String) seoa.getBody().get(ParameterConstants.STAFF_EDORG_ASSOC_STAFF_CLASSIFICATION); if(isValidRole(role, samlRoleSet)) { if (edOrgRoles.get(edOrgId) == null) { edOrgRoles.put(edOrgId, new ArrayList<String>()); edOrgRoles.get(edOrgId).add(role); } else if (!edOrgRoles.get(edOrgId).contains(role)) { edOrgRoles.get(edOrgId).add(role); } } } } return edOrgRoles; } }
EdOrgContextualRoleBuilder { private Map<String, List<String>> buildEdOrgContextualRoles(Set<Entity> seoas, Set<String> samlRoleSet) { Map<String, List<String>> edOrgRoles = new HashMap<String, List<String>>(); if (seoas != null) { for (Entity seoa : seoas) { String edOrgId = (String) seoa.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE); String role = (String) seoa.getBody().get(ParameterConstants.STAFF_EDORG_ASSOC_STAFF_CLASSIFICATION); if(isValidRole(role, samlRoleSet)) { if (edOrgRoles.get(edOrgId) == null) { edOrgRoles.put(edOrgId, new ArrayList<String>()); edOrgRoles.get(edOrgId).add(role); } else if (!edOrgRoles.get(edOrgId).contains(role)) { edOrgRoles.get(edOrgId).add(role); } } } } return edOrgRoles; }  }
EdOrgContextualRoleBuilder { private Map<String, List<String>> buildEdOrgContextualRoles(Set<Entity> seoas, Set<String> samlRoleSet) { Map<String, List<String>> edOrgRoles = new HashMap<String, List<String>>(); if (seoas != null) { for (Entity seoa : seoas) { String edOrgId = (String) seoa.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE); String role = (String) seoa.getBody().get(ParameterConstants.STAFF_EDORG_ASSOC_STAFF_CLASSIFICATION); if(isValidRole(role, samlRoleSet)) { if (edOrgRoles.get(edOrgId) == null) { edOrgRoles.put(edOrgId, new ArrayList<String>()); edOrgRoles.get(edOrgId).add(role); } else if (!edOrgRoles.get(edOrgId).contains(role)) { edOrgRoles.get(edOrgId).add(role); } } } } return edOrgRoles; }  Map<String, List<String>> buildValidStaffRoles(String realmId, String staffId, String tenant, List<String> roles); }
EdOrgContextualRoleBuilder { private Map<String, List<String>> buildEdOrgContextualRoles(Set<Entity> seoas, Set<String> samlRoleSet) { Map<String, List<String>> edOrgRoles = new HashMap<String, List<String>>(); if (seoas != null) { for (Entity seoa : seoas) { String edOrgId = (String) seoa.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE); String role = (String) seoa.getBody().get(ParameterConstants.STAFF_EDORG_ASSOC_STAFF_CLASSIFICATION); if(isValidRole(role, samlRoleSet)) { if (edOrgRoles.get(edOrgId) == null) { edOrgRoles.put(edOrgId, new ArrayList<String>()); edOrgRoles.get(edOrgId).add(role); } else if (!edOrgRoles.get(edOrgId).contains(role)) { edOrgRoles.get(edOrgId).add(role); } } } } return edOrgRoles; }  Map<String, List<String>> buildValidStaffRoles(String realmId, String staffId, String tenant, List<String> roles);  }