@Test public void testIndexerAll() throws Exception { Privilege indexerAll = create(new KeyValue("indexer", ALL)); Privilege indexer1 = create(new KeyValue("indexer", "ind1")); assertTrue(indexerAll.implies(indexer1)); assertTrue(indexer1.implies(indexerAll)); Privilege allWrite = create(new KeyValue("indexer", ALL), new KeyValue("action", "write")); Privilege allRead = create(new KeyValue("indexer", ALL), new KeyValue("action", "read")); Privilege ind1Write = create(new KeyValue("indexer", "ind1"), new KeyValue("action", "write")); Privilege ind1Read = create(new KeyValue("indexer", "ind1"), new KeyValue("action", "read")); assertTrue(allWrite.implies(ind1Write)); assertTrue(allRead.implies(ind1Read)); assertTrue(ind1Write.implies(allWrite)); assertTrue(ind1Read.implies(allRead)); assertFalse(allWrite.implies(ind1Read)); assertFalse(ind1Write.implies(ind1Read)); assertFalse(allRead.implies(ind1Write)); assertFalse(ind1Read.implies(allWrite)); assertFalse(allWrite.implies(allRead)); assertFalse(allRead.implies(allWrite)); assertFalse(ind1Write.implies(ind1Read)); assertFalse(ind1Read.implies(ind1Write)); assertTrue(indexerAll.implies(allWrite)); assertTrue(indexerAll.implies(allRead)); assertTrue(indexerAll.implies(ind1Write)); assertTrue(indexerAll.implies(ind1Read)); assertFalse(allWrite.implies(indexerAll)); assertFalse(allRead.implies(indexerAll)); assertFalse(ind1Write.implies(indexerAll)); assertFalse(ind1Read.implies(indexerAll)); }
@Override public boolean implies(Privilege p) { if (!(p instanceof IndexerWildcardPrivilege)) { return false; } IndexerWildcardPrivilege wp = (IndexerWildcardPrivilege) 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(IndexerConstants.ALL)) { return false; } } return true; }
IndexerWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof IndexerWildcardPrivilege)) { return false; } IndexerWildcardPrivilege wp = (IndexerWildcardPrivilege) 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(IndexerConstants.ALL)) { return false; } } return true; } }
IndexerWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof IndexerWildcardPrivilege)) { return false; } IndexerWildcardPrivilege wp = (IndexerWildcardPrivilege) 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(IndexerConstants.ALL)) { return false; } } return true; } IndexerWildcardPrivilege(String wildcardString); }
IndexerWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof IndexerWildcardPrivilege)) { return false; } IndexerWildcardPrivilege wp = (IndexerWildcardPrivilege) 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(IndexerConstants.ALL)) { return false; } } return true; } IndexerWildcardPrivilege(String wildcardString); @Override boolean implies(Privilege p); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
IndexerWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof IndexerWildcardPrivilege)) { return false; } IndexerWildcardPrivilege wp = (IndexerWildcardPrivilege) 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(IndexerConstants.ALL)) { return false; } } return true; } IndexerWildcardPrivilege(String wildcardString); @Override boolean implies(Privilege p); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }