@Test public void testMakeEntityBody() { Treatment treatment1 = Mockito.mock(Treatment.class); Treatment treatment2 = Mockito.mock(Treatment.class); List<Treatment> treatments = new ArrayList<Treatment>(); treatments.add(treatment1); treatments.add(treatment2); Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>(); auths.add(Right.READ_GENERAL); Entity student = createStudentEntity(EntityNames.STUDENT, STUDENT_ID); Entity staff = createStaffEntity(EntityNames.STAFF, STAFF_ID); student.getEmbeddedData().put("studentSchoolAssociation", Arrays.asList(staff)); EntityBody sb = new EntityBody(student.getBody()); EntityBody staffBody = new EntityBody(staff.getBody()); Mockito.when(treatment1.toExposed(Matchers.any(EntityBody.class), Matchers.any(EntityDefinition.class), Matchers.any(Entity.class))).thenReturn(sb, staffBody); Mockito.when(treatment2.toExposed(Matchers.any(EntityBody.class), Matchers.any(EntityDefinition.class), Matchers.any(Entity.class))).thenReturn(sb, staffBody); EntityDefinition definition = Mockito.mock(EntityDefinition.class); Mockito.when(definition.getType()).thenReturn("student"); EntityBody res = entityRightsFilter.makeEntityBody(student, treatments, definition, false, auths, SecurityUtil.UserContext.STAFF_CONTEXT); Assert.assertNotNull(res); List<EntityBody> ssa = (List<EntityBody>) res.get("studentSchoolAssociation"); Assert.assertNotNull(ssa); Assert.assertEquals(1, ssa.size()); Assert.assertEquals(STAFF_ID, ssa.get(0).get(ParameterConstants.STAFF_UNIQUE_STATE_ID)); }
public EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn, boolean isSelf, Collection<GrantedAuthority> nonSelfAuths, SecurityUtil.UserContext context) { Collection<GrantedAuthority> selfAuths; if (isSelf) { selfAuths = rightAccessValidator.getContextualAuthorities(isSelf, entity, context, true); } else { selfAuths = nonSelfAuths; } return makeEntityBody(entity, treamts, defn, nonSelfAuths, selfAuths); }
EntityRightsFilter { public EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn, boolean isSelf, Collection<GrantedAuthority> nonSelfAuths, SecurityUtil.UserContext context) { Collection<GrantedAuthority> selfAuths; if (isSelf) { selfAuths = rightAccessValidator.getContextualAuthorities(isSelf, entity, context, true); } else { selfAuths = nonSelfAuths; } return makeEntityBody(entity, treamts, defn, nonSelfAuths, selfAuths); } }
EntityRightsFilter { public EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn, boolean isSelf, Collection<GrantedAuthority> nonSelfAuths, SecurityUtil.UserContext context) { Collection<GrantedAuthority> selfAuths; if (isSelf) { selfAuths = rightAccessValidator.getContextualAuthorities(isSelf, entity, context, true); } else { selfAuths = nonSelfAuths; } return makeEntityBody(entity, treamts, defn, nonSelfAuths, selfAuths); }  }
EntityRightsFilter { public EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn, boolean isSelf, Collection<GrantedAuthority> nonSelfAuths, SecurityUtil.UserContext context) { Collection<GrantedAuthority> selfAuths; if (isSelf) { selfAuths = rightAccessValidator.getContextualAuthorities(isSelf, entity, context, true); } else { selfAuths = nonSelfAuths; } return makeEntityBody(entity, treamts, defn, nonSelfAuths, selfAuths); }  EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn, boolean isSelf,
                                     Collection<GrantedAuthority> nonSelfAuths, SecurityUtil.UserContext context); EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn,
            Collection<GrantedAuthority> nonSelfAuths, Collection<GrantedAuthority> selfAuths); EntityBody exposeTreatments(Entity entity, List<Treatment> treatments, EntityDefinition defn); void setRightAccessValidator(RightAccessValidator rightAccessValidator); }
EntityRightsFilter { public EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn, boolean isSelf, Collection<GrantedAuthority> nonSelfAuths, SecurityUtil.UserContext context) { Collection<GrantedAuthority> selfAuths; if (isSelf) { selfAuths = rightAccessValidator.getContextualAuthorities(isSelf, entity, context, true); } else { selfAuths = nonSelfAuths; } return makeEntityBody(entity, treamts, defn, nonSelfAuths, selfAuths); }  EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn, boolean isSelf,
                                     Collection<GrantedAuthority> nonSelfAuths, SecurityUtil.UserContext context); EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn,
            Collection<GrantedAuthority> nonSelfAuths, Collection<GrantedAuthority> selfAuths); EntityBody exposeTreatments(Entity entity, List<Treatment> treatments, EntityDefinition defn); void setRightAccessValidator(RightAccessValidator rightAccessValidator);  }