@SuppressWarnings("unchecked") @Test public void testBuildEntityEdOrgDualContextRights() { Set<String> edOrgs = new HashSet<String>(); edOrgs.add("edOrg1"); edOrgs.add("edOrg2"); edOrgs.add("edOrg3"); edOrgs.add("edOrg4"); Entity entity = Mockito.mock(Entity.class); Mockito.when(entity.getType()).thenReturn("student"); Mockito.when(edOrgOwnershipArbiter.determineHierarchicalEdorgs(Matchers.anyList(), Matchers.anyString())).thenReturn(edOrgs); Collection<GrantedAuthority> grantedAuthorities = entityEdOrgRightBuilder.buildEntityEdOrgContextRights(edOrgContextRights, entity, SecurityUtil.UserContext.DUAL_CONTEXT, false); Assert.assertEquals(6, grantedAuthorities.size()); Assert.assertTrue(grantedAuthorities.contains(READ_PUBLIC)); Assert.assertTrue(grantedAuthorities.contains(READ_GENERAL)); Assert.assertTrue(grantedAuthorities.contains(READ_RESTRICTED)); Assert.assertTrue(grantedAuthorities.contains(WRITE_GENERAL)); Assert.assertTrue(grantedAuthorities.contains(STAFF_CONTEXT)); Assert.assertTrue(grantedAuthorities.contains(TEACHER_CONTEXT)); Assert.assertFalse(grantedAuthorities.contains(WRITE_RESTRICTED)); Assert.assertFalse(grantedAuthorities.contains(AGGREGATE_READ)); Assert.assertFalse(grantedAuthorities.contains(WRITE_PUBLIC)); Assert.assertFalse(grantedAuthorities.contains(AGGREGATE_WRITE)); }
public Collection<GrantedAuthority> buildEntityEdOrgContextRights(final EdOrgContextRightsCache edOrgContextRights, final Entity entity, final SecurityUtil.UserContext context, boolean isRead) { Collection<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); Set<String> edorgs = edOrgOwnershipArbiter.determineHierarchicalEdorgs(Arrays.asList(entity), entity.getType()); edorgs.retainAll(edOrgContextRights.keySet()); if (edorgs.isEmpty()) { edorgs = getEdOrgsForStudent(edOrgContextRights.keySet(), entity, isRead); } for (String edorg : edorgs) { switch (context) { case DUAL_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; case STAFF_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); break; case TEACHER_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; } if(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name()) != null) { authorities.addAll(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name())); } } return authorities; }
EntityEdOrgRightBuilder { public Collection<GrantedAuthority> buildEntityEdOrgContextRights(final EdOrgContextRightsCache edOrgContextRights, final Entity entity, final SecurityUtil.UserContext context, boolean isRead) { Collection<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); Set<String> edorgs = edOrgOwnershipArbiter.determineHierarchicalEdorgs(Arrays.asList(entity), entity.getType()); edorgs.retainAll(edOrgContextRights.keySet()); if (edorgs.isEmpty()) { edorgs = getEdOrgsForStudent(edOrgContextRights.keySet(), entity, isRead); } for (String edorg : edorgs) { switch (context) { case DUAL_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; case STAFF_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); break; case TEACHER_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; } if(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name()) != null) { authorities.addAll(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name())); } } return authorities; } }
EntityEdOrgRightBuilder { public Collection<GrantedAuthority> buildEntityEdOrgContextRights(final EdOrgContextRightsCache edOrgContextRights, final Entity entity, final SecurityUtil.UserContext context, boolean isRead) { Collection<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); Set<String> edorgs = edOrgOwnershipArbiter.determineHierarchicalEdorgs(Arrays.asList(entity), entity.getType()); edorgs.retainAll(edOrgContextRights.keySet()); if (edorgs.isEmpty()) { edorgs = getEdOrgsForStudent(edOrgContextRights.keySet(), entity, isRead); } for (String edorg : edorgs) { switch (context) { case DUAL_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; case STAFF_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); break; case TEACHER_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; } if(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name()) != null) { authorities.addAll(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name())); } } return authorities; }  }
EntityEdOrgRightBuilder { public Collection<GrantedAuthority> buildEntityEdOrgContextRights(final EdOrgContextRightsCache edOrgContextRights, final Entity entity, final SecurityUtil.UserContext context, boolean isRead) { Collection<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); Set<String> edorgs = edOrgOwnershipArbiter.determineHierarchicalEdorgs(Arrays.asList(entity), entity.getType()); edorgs.retainAll(edOrgContextRights.keySet()); if (edorgs.isEmpty()) { edorgs = getEdOrgsForStudent(edOrgContextRights.keySet(), entity, isRead); } for (String edorg : edorgs) { switch (context) { case DUAL_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; case STAFF_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); break; case TEACHER_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; } if(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name()) != null) { authorities.addAll(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name())); } } return authorities; }  Collection<GrantedAuthority> buildEntityEdOrgRights(final Map<String, Collection<GrantedAuthority>> edOrgRights, final Entity entity, boolean isRead); Collection<GrantedAuthority> buildEntityEdOrgContextRights(final EdOrgContextRightsCache edOrgContextRights, final Entity entity,
                                                                      final SecurityUtil.UserContext context, boolean isRead); void setEdOrgOwnershipArbiter(EdOrgOwnershipArbiter edOrgOwnershipArbiter); }
EntityEdOrgRightBuilder { public Collection<GrantedAuthority> buildEntityEdOrgContextRights(final EdOrgContextRightsCache edOrgContextRights, final Entity entity, final SecurityUtil.UserContext context, boolean isRead) { Collection<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); Set<String> edorgs = edOrgOwnershipArbiter.determineHierarchicalEdorgs(Arrays.asList(entity), entity.getType()); edorgs.retainAll(edOrgContextRights.keySet()); if (edorgs.isEmpty()) { edorgs = getEdOrgsForStudent(edOrgContextRights.keySet(), entity, isRead); } for (String edorg : edorgs) { switch (context) { case DUAL_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; case STAFF_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.STAFF_CONTEXT.name())); break; case TEACHER_CONTEXT: authorities.addAll(edOrgContextRights.get(edorg).get(Right.TEACHER_CONTEXT.name())); break; } if(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name()) != null) { authorities.addAll(edOrgContextRights.get(edorg).get(Right.APP_AUTHORIZE.name())); } } return authorities; }  Collection<GrantedAuthority> buildEntityEdOrgRights(final Map<String, Collection<GrantedAuthority>> edOrgRights, final Entity entity, boolean isRead); Collection<GrantedAuthority> buildEntityEdOrgContextRights(final EdOrgContextRightsCache edOrgContextRights, final Entity entity,
                                                                      final SecurityUtil.UserContext context, boolean isRead); void setEdOrgOwnershipArbiter(EdOrgOwnershipArbiter edOrgOwnershipArbiter);  }