@Test public void testMangleSpecificFailedQuery() { DefaultQueryMangler mangler = new DefaultQueryMangler(); NeutralQuery query = new NeutralQuery(); NeutralCriteria baseCriteria = new NeutralCriteria("_id", NeutralCriteria.CRITERIA_IN, Arrays.asList(new String[] {"1", "2", "3"})); query.addCriteria(baseCriteria); NeutralCriteria secureCriteria = new NeutralCriteria("_id", NeutralCriteria.CRITERIA_IN, Arrays.asList(new String[] {"4", "5"})); SecurityCriteria securityCriteria = new SecurityCriteria(); securityCriteria.setCollectionName("students"); securityCriteria.setSecurityCriteria(secureCriteria); NeutralQuery finalQuery = mangler.mangleQuery(query, secureCriteria); assertEquals(finalQuery.getOrQueries().size(), 0); }
public NeutralQuery mangleQuery(NeutralQuery query, NeutralCriteria securityCriteria) { LOG.debug(">>>DefaultQueryMangler.mangleQuery()"); setTheQuery(query); setSecurityCriteria(securityCriteria); boolean isList = true; boolean isQueried = false; NeutralCriteria idCriteria = null; for (NeutralCriteria criteria : query.getCriteria()) { if (criteria.getKey().equals("_id")) { idCriteria = criteria; isList = false; } } if (isList) { if (!isQueried) { adjustSecurityForPaging(); } query.addOrQuery(new NeutralQuery(securityCriteria)); return query; } else { Set<String> finalIdSet = new HashSet<String>((Collection) securityCriteria.getValue()); finalIdSet.retainAll((Collection) idCriteria.getValue()); finalIdSet = new HashSet<String>(adjustIdListForPaging(new ArrayList<String>(finalIdSet))); query.removeCriteria(idCriteria); if (finalIdSet.size() > 0) { idCriteria.setValue(new ArrayList<String>(finalIdSet)); query.addOrQuery(new NeutralQuery(idCriteria)); } return query; } }
DefaultQueryMangler extends Mangler { public NeutralQuery mangleQuery(NeutralQuery query, NeutralCriteria securityCriteria) { LOG.debug(">>>DefaultQueryMangler.mangleQuery()"); setTheQuery(query); setSecurityCriteria(securityCriteria); boolean isList = true; boolean isQueried = false; NeutralCriteria idCriteria = null; for (NeutralCriteria criteria : query.getCriteria()) { if (criteria.getKey().equals("_id")) { idCriteria = criteria; isList = false; } } if (isList) { if (!isQueried) { adjustSecurityForPaging(); } query.addOrQuery(new NeutralQuery(securityCriteria)); return query; } else { Set<String> finalIdSet = new HashSet<String>((Collection) securityCriteria.getValue()); finalIdSet.retainAll((Collection) idCriteria.getValue()); finalIdSet = new HashSet<String>(adjustIdListForPaging(new ArrayList<String>(finalIdSet))); query.removeCriteria(idCriteria); if (finalIdSet.size() > 0) { idCriteria.setValue(new ArrayList<String>(finalIdSet)); query.addOrQuery(new NeutralQuery(idCriteria)); } return query; } } }
DefaultQueryMangler extends Mangler { public NeutralQuery mangleQuery(NeutralQuery query, NeutralCriteria securityCriteria) { LOG.debug(">>>DefaultQueryMangler.mangleQuery()"); setTheQuery(query); setSecurityCriteria(securityCriteria); boolean isList = true; boolean isQueried = false; NeutralCriteria idCriteria = null; for (NeutralCriteria criteria : query.getCriteria()) { if (criteria.getKey().equals("_id")) { idCriteria = criteria; isList = false; } } if (isList) { if (!isQueried) { adjustSecurityForPaging(); } query.addOrQuery(new NeutralQuery(securityCriteria)); return query; } else { Set<String> finalIdSet = new HashSet<String>((Collection) securityCriteria.getValue()); finalIdSet.retainAll((Collection) idCriteria.getValue()); finalIdSet = new HashSet<String>(adjustIdListForPaging(new ArrayList<String>(finalIdSet))); query.removeCriteria(idCriteria); if (finalIdSet.size() > 0) { idCriteria.setValue(new ArrayList<String>(finalIdSet)); query.addOrQuery(new NeutralQuery(idCriteria)); } return query; } }  }
DefaultQueryMangler extends Mangler { public NeutralQuery mangleQuery(NeutralQuery query, NeutralCriteria securityCriteria) { LOG.debug(">>>DefaultQueryMangler.mangleQuery()"); setTheQuery(query); setSecurityCriteria(securityCriteria); boolean isList = true; boolean isQueried = false; NeutralCriteria idCriteria = null; for (NeutralCriteria criteria : query.getCriteria()) { if (criteria.getKey().equals("_id")) { idCriteria = criteria; isList = false; } } if (isList) { if (!isQueried) { adjustSecurityForPaging(); } query.addOrQuery(new NeutralQuery(securityCriteria)); return query; } else { Set<String> finalIdSet = new HashSet<String>((Collection) securityCriteria.getValue()); finalIdSet.retainAll((Collection) idCriteria.getValue()); finalIdSet = new HashSet<String>(adjustIdListForPaging(new ArrayList<String>(finalIdSet))); query.removeCriteria(idCriteria); if (finalIdSet.size() > 0) { idCriteria.setValue(new ArrayList<String>(finalIdSet)); query.addOrQuery(new NeutralQuery(idCriteria)); } return query; } }  NeutralQuery mangleQuery(NeutralQuery query, NeutralCriteria securityCriteria); }
DefaultQueryMangler extends Mangler { public NeutralQuery mangleQuery(NeutralQuery query, NeutralCriteria securityCriteria) { LOG.debug(">>>DefaultQueryMangler.mangleQuery()"); setTheQuery(query); setSecurityCriteria(securityCriteria); boolean isList = true; boolean isQueried = false; NeutralCriteria idCriteria = null; for (NeutralCriteria criteria : query.getCriteria()) { if (criteria.getKey().equals("_id")) { idCriteria = criteria; isList = false; } } if (isList) { if (!isQueried) { adjustSecurityForPaging(); } query.addOrQuery(new NeutralQuery(securityCriteria)); return query; } else { Set<String> finalIdSet = new HashSet<String>((Collection) securityCriteria.getValue()); finalIdSet.retainAll((Collection) idCriteria.getValue()); finalIdSet = new HashSet<String>(adjustIdListForPaging(new ArrayList<String>(finalIdSet))); query.removeCriteria(idCriteria); if (finalIdSet.size() > 0) { idCriteria.setValue(new ArrayList<String>(finalIdSet)); query.addOrQuery(new NeutralQuery(idCriteria)); } return query; } }  NeutralQuery mangleQuery(NeutralQuery query, NeutralCriteria securityCriteria);  }