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();  }
@Test public void testSimpleNoAction() throws Exception { Privilege indexer1 = create(new KeyValue("indexer", "ind1")); Privilege indexer2 = create(new KeyValue("indexer", "ind2")); Privilege indexer1Case = create(new KeyValue("indeXeR", "inD1")); assertTrue(indexer1.implies(indexer1)); assertTrue(indexer2.implies(indexer2)); assertTrue(indexer1.implies(indexer1Case)); assertTrue(indexer1Case.implies(indexer1)); assertFalse(indexer1.implies(indexer2)); assertFalse(indexer1Case.implies(indexer2)); assertFalse(indexer2.implies(indexer1)); assertFalse(indexer2.implies(indexer1Case)); }
@Test public void testSimpleAction() throws Exception { Privilege read = create(new KeyValue("indexer", "ind1"), new KeyValue("action", "read")); Privilege write = create(new KeyValue("indexer", "ind1"), new KeyValue("action", "write")); Privilege readCase = create(new KeyValue("indeXeR", "iNd1"), new KeyValue("AcTiOn", "ReAd")); assertTrue(read.implies(read)); assertTrue(write.implies(write)); assertTrue(read.implies(readCase)); assertTrue(readCase.implies(read)); assertFalse(read.implies(write)); assertFalse(readCase.implies(write)); assertFalse(write.implies(read)); assertFalse(write.implies(readCase)); }
@Test public void testRoleShorterThanRequest() throws Exception { Privilege indexer1 = create(new KeyValue("indexer", "ind1")); Privilege read = create(new KeyValue("indexer", "ind1"), new KeyValue("action", "read")); Privilege write = create(new KeyValue("indexer", "ind1"), new KeyValue("action", "write")); Privilege all = create(new KeyValue("indexer", "ind1"), new KeyValue("action", ALL)); assertTrue(indexer1.implies(read)); assertTrue(indexer1.implies(write)); assertTrue(indexer1.implies(all)); assertFalse(read.implies(indexer1)); assertFalse(write.implies(indexer1)); assertTrue(all.implies(indexer1)); }
@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)); }
@Test public void testActionAll() throws Exception { Privilege ind1All = create(new KeyValue("indexer", "index1"), new KeyValue("action", ALL)); Privilege ind1Write = create(new KeyValue("indexer", "index1"), new KeyValue("action", "write")); Privilege ind1Read = create(new KeyValue("indexer", "index1"), new KeyValue("action", "read")); assertTrue(ind1All.implies(ind1All)); assertTrue(ind1All.implies(ind1Write)); assertTrue(ind1All.implies(ind1Read)); assertFalse(ind1Write.implies(ind1All)); assertFalse(ind1Read.implies(ind1All)); Privilege ind1 = create(new KeyValue("indexer", "index1")); assertTrue(ind1All.implies(ind1)); assertTrue(ind1.implies(ind1All)); }