@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)); }
@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();  }