SqoopWildcardPrivilege implements Privilege { @Override public boolean implies(Privilege p) { if (!(p instanceof SqoopWildcardPrivilege)) { return false; } SqoopWildcardPrivilege wp = (SqoopWildcardPrivilege)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(SqoopActionConstant.NAME) && !(otherPart.getKey().equalsIgnoreCase(SqoopActionConstant.NAME))) { 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(SqoopActionConstant.ALL)) { return false; } } return true; } SqoopWildcardPrivilege(String permission); @Override boolean implies(Privilege p);  }
@Test public void testSimpleAction() throws Exception { assertFalse(SQOOP_SERVER1_WRITE.implies(SQOOP_SERVER1_READ)); assertFalse(SQOOP_SERVER1_READ.implies(SQOOP_SERVER1_WRITE)); assertFalse(SQOOP_SERVER1_CONNECTOR1_WRITE.implies(SQOOP_SERVER1_CONNECTOR1_READ)); assertFalse(SQOOP_SERVER1_CONNECTOR1_READ.implies(SQOOP_SERVER1_CONNECTOR1_WRITE)); assertFalse(SQOOP_SERVER1_JOB1_READ.implies(SQOOP_SERVER1_JOB1_WRITE)); assertFalse(SQOOP_SERVER1_JOB1_WRITE.implies(SQOOP_SERVER1_JOB1_READ)); assertFalse(SQOOP_SERVER1_LINK1_READ.implies(SQOOP_SERVER1_LINK1_WRITE)); assertFalse(SQOOP_SERVER1_LINK1_WRITE.implies(SQOOP_SERVER1_LINK1_READ)); }
@Test public void testShorterThanRequest() throws Exception { assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_JOB1_ALL)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_JOB1_READ)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_JOB1_WRITE)); assertFalse(SQOOP_SERVER1_WRITE.implies(SQOOP_SERVER1_READ)); assertTrue(SQOOP_SERVER1_READ.implies(SQOOP_SERVER1_JOB1_READ)); assertTrue(SQOOP_SERVER1_WRITE.implies(SQOOP_SERVER1_JOB1_WRITE)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_LINK1_ALL)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_LINK1_READ)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_LINK1_WRITE)); assertTrue(SQOOP_SERVER1_READ.implies(SQOOP_SERVER1_LINK1_READ)); assertTrue(SQOOP_SERVER1_WRITE.implies(SQOOP_SERVER1_LINK1_WRITE)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_CONNECTOR1_ALL)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_CONNECTOR1_READ)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_CONNECTOR1_WRITE)); assertTrue(SQOOP_SERVER1_READ.implies(SQOOP_SERVER1_CONNECTOR1_READ)); assertTrue(SQOOP_SERVER1_WRITE.implies(SQOOP_SERVER1_CONNECTOR1_WRITE)); }
@Test public void testActionAll() throws Exception { assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_READ)); assertTrue(SQOOP_SERVER1_ALL.implies(SQOOP_SERVER1_WRITE)); assertTrue(SQOOP_SERVER1_JOB1_ALL.implies(SQOOP_SERVER1_JOB1_READ)); assertTrue(SQOOP_SERVER1_JOB1_ALL.implies(SQOOP_SERVER1_JOB1_WRITE)); assertTrue(SQOOP_SERVER1_LINK1_ALL.implies(SQOOP_SERVER1_LINK1_READ)); assertTrue(SQOOP_SERVER1_LINK1_ALL.implies(SQOOP_SERVER1_LINK1_WRITE)); assertTrue(SQOOP_SERVER1_CONNECTOR1_ALL.implies(SQOOP_SERVER1_CONNECTOR1_READ)); assertTrue(SQOOP_SERVER1_CONNECTOR1_ALL.implies(SQOOP_SERVER1_CONNECTOR1_WRITE)); }
@Test public void testUnexpected() throws Exception { Privilege p = new Privilege() { @Override public boolean implies(Privilege p) { return false; } }; Privilege job1 = create(new KeyValue("SERVER", "server"), new KeyValue("JOB", "job1")); assertFalse(job1.implies(null)); assertFalse(job1.implies(p)); assertFalse(job1.equals(null)); assertFalse(job1.equals(p)); }