@Test public void testSimpleAction() throws Exception { Privilege query = create(new KeyValue("collection", "coll1"), new KeyValue("action", "query")); Privilege update = create(new KeyValue("collection", "coll1"), new KeyValue("action", "update")); Privilege queryCase = create(new KeyValue("colleCtIon", "coLl1"), new KeyValue("AcTiOn", "QuERy")); assertTrue(query.implies(query)); assertTrue(update.implies(update)); assertTrue(query.implies(queryCase)); assertTrue(queryCase.implies(query)); assertFalse(query.implies(update)); assertFalse(queryCase.implies(update)); assertFalse(update.implies(query)); assertFalse(update.implies(queryCase)); }
@Override public boolean implies(Privilege p) { if (!(p instanceof SearchWildcardPrivilege)) { return false; } SearchWildcardPrivilege wp = (SearchWildcardPrivilege) p; List<KeyValue> otherParts = wp.parts; if(equals(wp)) { return true; } int index = 0; for (KeyValue otherPart : otherParts) { if (parts.size() - 1 < index) { return true; } else { KeyValue part = parts.get(index); if(!part.getKey().equalsIgnoreCase(otherPart.getKey())) { return false; } if (!impliesKeyValue(part, otherPart)) { return false; } index++; } } for (; index < parts.size(); index++) { KeyValue part = parts.get(index); if (!part.getValue().equals(SearchConstants.ALL)) { return false; } } return true; }
SearchWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof SearchWildcardPrivilege)) { return false; } SearchWildcardPrivilege wp = (SearchWildcardPrivilege) p; List<KeyValue> otherParts = wp.parts; if(equals(wp)) { return true; } int index = 0; for (KeyValue otherPart : otherParts) { if (parts.size() - 1 < index) { return true; } else { KeyValue part = parts.get(index); if(!part.getKey().equalsIgnoreCase(otherPart.getKey())) { return false; } if (!impliesKeyValue(part, otherPart)) { return false; } index++; } } for (; index < parts.size(); index++) { KeyValue part = parts.get(index); if (!part.getValue().equals(SearchConstants.ALL)) { return false; } } return true; } }
SearchWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof SearchWildcardPrivilege)) { return false; } SearchWildcardPrivilege wp = (SearchWildcardPrivilege) p; List<KeyValue> otherParts = wp.parts; if(equals(wp)) { return true; } int index = 0; for (KeyValue otherPart : otherParts) { if (parts.size() - 1 < index) { return true; } else { KeyValue part = parts.get(index); if(!part.getKey().equalsIgnoreCase(otherPart.getKey())) { return false; } if (!impliesKeyValue(part, otherPart)) { return false; } index++; } } for (; index < parts.size(); index++) { KeyValue part = parts.get(index); if (!part.getValue().equals(SearchConstants.ALL)) { return false; } } return true; } SearchWildcardPrivilege(String wildcardString); }
SearchWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof SearchWildcardPrivilege)) { return false; } SearchWildcardPrivilege wp = (SearchWildcardPrivilege) p; List<KeyValue> otherParts = wp.parts; if(equals(wp)) { return true; } int index = 0; for (KeyValue otherPart : otherParts) { if (parts.size() - 1 < index) { return true; } else { KeyValue part = parts.get(index); if(!part.getKey().equalsIgnoreCase(otherPart.getKey())) { return false; } if (!impliesKeyValue(part, otherPart)) { return false; } index++; } } for (; index < parts.size(); index++) { KeyValue part = parts.get(index); if (!part.getValue().equals(SearchConstants.ALL)) { return false; } } return true; } SearchWildcardPrivilege(String wildcardString); @Override boolean implies(Privilege p); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
SearchWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof SearchWildcardPrivilege)) { return false; } SearchWildcardPrivilege wp = (SearchWildcardPrivilege) p; List<KeyValue> otherParts = wp.parts; if(equals(wp)) { return true; } int index = 0; for (KeyValue otherPart : otherParts) { if (parts.size() - 1 < index) { return true; } else { KeyValue part = parts.get(index); if(!part.getKey().equalsIgnoreCase(otherPart.getKey())) { return false; } if (!impliesKeyValue(part, otherPart)) { return false; } index++; } } for (; index < parts.size(); index++) { KeyValue part = parts.get(index); if (!part.getValue().equals(SearchConstants.ALL)) { return false; } } return true; } SearchWildcardPrivilege(String wildcardString); @Override boolean implies(Privilege p); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }