@Test public void testCannotAccessAll() { List<String> descs = Arrays.asList("Just Cause", "Armaggedon", "Awareness"); Set<String> cohortIds = new HashSet<String>(); for (String desc : descs) { cohortIds.add(this.generateCohort(USER_ID, desc)); } Assert.assertFalse(val.validate(EntityNames.COHORT, cohortIds).size() == cohortIds.size()); for (String id : cohortIds) { Assert.assertFalse(val.validate(EntityNames.COHORT, Collections.singleton(id)).size() == 1); } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } validIds.retainAll(ids); return validIds; }
TeacherToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } validIds.retainAll(ids); return validIds; } }
TeacherToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } validIds.retainAll(ids); return validIds; }  }
TeacherToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } validIds.retainAll(ids); return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } validIds.retainAll(ids); return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }