@Test public void testRoleShorterThanRequest() throws Exception { assertTrue(ROLE_SERVER_SERVER1.implies(REQUEST_SERVER1_DB1)); assertTrue(ROLE_SERVER_SERVER1.implies(REQUEST_SERVER1_DB2)); assertFalse(ROLE_SERVER_SERVER1.implies(REQUEST_SERVER2_DB1)); assertFalse(ROLE_SERVER_SERVER1.implies(REQUEST_SERVER2_DB2)); assertTrue(ROLE_SERVER_ALL_DB_ALL.implies(REQUEST_SERVER1)); assertFalse(ROLE_SERVER_ALL_DB_DB1.implies(REQUEST_SERVER1)); }
@Override public boolean implies(Privilege p) { if (!(p instanceof DBWildcardPrivilege)) { return false; } DBWildcardPrivilege wp = (DBWildcardPrivilege) 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("action") && !(otherPart.getKey().equalsIgnoreCase("action"))) { continue; } 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(AccessConstants.ALL)) { return false; } } return true; }
DBWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof DBWildcardPrivilege)) { return false; } DBWildcardPrivilege wp = (DBWildcardPrivilege) 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("action") && !(otherPart.getKey().equalsIgnoreCase("action"))) { continue; } 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(AccessConstants.ALL)) { return false; } } return true; } }
DBWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof DBWildcardPrivilege)) { return false; } DBWildcardPrivilege wp = (DBWildcardPrivilege) 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("action") && !(otherPart.getKey().equalsIgnoreCase("action"))) { continue; } 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(AccessConstants.ALL)) { return false; } } return true; } DBWildcardPrivilege(String wildcardString); }
DBWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof DBWildcardPrivilege)) { return false; } DBWildcardPrivilege wp = (DBWildcardPrivilege) 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("action") && !(otherPart.getKey().equalsIgnoreCase("action"))) { continue; } 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(AccessConstants.ALL)) { return false; } } return true; } DBWildcardPrivilege(String wildcardString); @Override boolean implies(Privilege p); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
DBWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof DBWildcardPrivilege)) { return false; } DBWildcardPrivilege wp = (DBWildcardPrivilege) 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("action") && !(otherPart.getKey().equalsIgnoreCase("action"))) { continue; } 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(AccessConstants.ALL)) { return false; } } return true; } DBWildcardPrivilege(String wildcardString); @Override boolean implies(Privilege p); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }