priv.setDbName((String) privObj[2]); priv.setTableName((String) privObj[3]); priv.setColumnName((String) privObj[4]); priv.setURI((String) privObj[5]); priv.setAction((String) privObj[6]);
@Test public void testImpliesPrivilegeNegativeWithColumn() throws Exception { // 1.test server+database+table+column+action MSentryPrivilege my = new MSentryPrivilege(); MSentryPrivilege your = new MSentryPrivilege(); // bad column my.setServerName("server1"); my.setDbName("db1"); my.setTableName("tb1"); my.setColumnName("c1"); my.setAction(AccessConstants.SELECT); your.setServerName("server1"); your.setDbName("db1"); your.setTableName("tb1"); your.setColumnName("c2"); your.setAction(AccessConstants.SELECT); assertFalse(my.implies(your)); // bad scope your.setColumnName(""); assertFalse(my.implies(your)); } }
@Test public void testImpliesPrivilegeNegativeWithColumn() throws Exception { // 1.test server+database+table+column+action MSentryPrivilege my = new MSentryPrivilege(); MSentryPrivilege your = new MSentryPrivilege(); // bad column my.setServerName("server1"); my.setDbName("db1"); my.setTableName("tb1"); my.setColumnName("c1"); my.setAction(AccessConstants.SELECT); your.setServerName("server1"); your.setDbName("db1"); your.setTableName("tb1"); your.setColumnName("c2"); your.setAction(AccessConstants.SELECT); assertFalse(my.implies(your)); // bad scope your.setColumnName(""); assertFalse(my.implies(your)); } }
/** * Converts thrift object to model object. Additionally does normalization * such as trimming whitespace and setting appropriate case. * @throws SentryInvalidInputException */ private MSentryPrivilege convertToMSentryPrivilege(TSentryPrivilege privilege) throws SentryInvalidInputException { MSentryPrivilege mSentryPrivilege = new MSentryPrivilege(); mSentryPrivilege.setServerName(toNULLCol(safeTrimLower(privilege.getServerName()))); mSentryPrivilege.setDbName(toNULLCol(safeTrimLower(privilege.getDbName()))); mSentryPrivilege.setTableName(toNULLCol(safeTrimLower(privilege.getTableName()))); mSentryPrivilege.setColumnName(toNULLCol(safeTrimLower(privilege.getColumnName()))); mSentryPrivilege.setPrivilegeScope(safeTrim(privilege.getPrivilegeScope())); mSentryPrivilege.setAction(toNULLCol(safeTrimLower(privilege.getAction()))); mSentryPrivilege.setCreateTime(System.currentTimeMillis()); mSentryPrivilege.setURI(toNULLCol(safeTrim(privilege.getURI()))); if ( !privilege.getGrantOption().equals(TSentryGrantOption.UNSET) ) { mSentryPrivilege.setGrantOption(Boolean.valueOf(privilege.getGrantOption().toString())); } else { mSentryPrivilege.setGrantOption(null); } return mSentryPrivilege; }
/** * Converts thrift object to model object. Additionally does normalization * such as trimming whitespace and setting appropriate case. * @throws SentryInvalidInputException */ private MSentryPrivilege convertToMSentryPrivilege(TSentryPrivilege privilege) throws SentryInvalidInputException { MSentryPrivilege mSentryPrivilege = new MSentryPrivilege(); mSentryPrivilege.setServerName(toNULLCol(safeTrimLower(privilege.getServerName()))); mSentryPrivilege.setDbName(toNULLCol(safeTrimLower(privilege.getDbName()))); mSentryPrivilege.setTableName(toNULLCol(safeTrimLower(privilege.getTableName()))); mSentryPrivilege.setColumnName(toNULLCol(safeTrimLower(privilege.getColumnName()))); mSentryPrivilege.setPrivilegeScope(safeTrim(privilege.getPrivilegeScope())); mSentryPrivilege.setAction(toNULLCol(safeTrimLower(privilege.getAction()))); mSentryPrivilege.setCreateTime(System.currentTimeMillis()); mSentryPrivilege.setURI(toNULLCol(safeTrim(privilege.getURI()))); if ( !privilege.getGrantOption().equals(TSentryGrantOption.UNSET) ) { mSentryPrivilege.setGrantOption(Boolean.valueOf(privilege.getGrantOption().toString())); } else { mSentryPrivilege.setGrantOption(null); } return mSentryPrivilege; } private static String safeTrim(String s) {
@Test public void testImpliesPrivilegePositiveWithColumn() throws Exception { // 1.test server+database+table+column+action MSentryPrivilege my = new MSentryPrivilege(); MSentryPrivilege your = new MSentryPrivilege(); my.setServerName("server1"); my.setAction(AccessConstants.SELECT); your.setServerName("server1"); your.setDbName("db1"); your.setTableName("tb1"); your.setColumnName("c1"); your.setAction(AccessConstants.SELECT); assertTrue(my.implies(your)); my.setDbName("db1"); assertTrue(my.implies(your)); my.setTableName("tb1"); assertTrue(my.implies(your)); my.setColumnName("c1"); assertTrue(my.implies(your)); }
@Test public void testImpliesPrivilegePositiveWithColumn() throws Exception { // 1.test server+database+table+column+action MSentryPrivilege my = new MSentryPrivilege(); MSentryPrivilege your = new MSentryPrivilege(); my.setServerName("server1"); my.setAction(AccessConstants.SELECT); your.setServerName("server1"); your.setDbName("db1"); your.setTableName("tb1"); your.setColumnName("c1"); your.setAction(AccessConstants.SELECT); assertTrue(my.implies(your)); my.setDbName("db1"); assertTrue(my.implies(your)); my.setTableName("tb1"); assertTrue(my.implies(your)); my.setColumnName("c1"); assertTrue(my.implies(your)); }
hivePrivilege.setAction("select"); hivePrivilege.setURI(SentryConstants.NULL_COL); hivePrivilege.setColumnName(SentryConstants.NULL_COL); hivePrivilege.setGrantOption(true);
hivePrivilege.setAction("select"); hivePrivilege.setURI(SentryStore.NULL_COL); hivePrivilege.setColumnName(SentryStore.NULL_COL); hivePrivilege.setGrantOption(true);
hivePrivilege.setAction("select"); hivePrivilege.setURI(SentryConstants.NULL_COL); hivePrivilege.setColumnName(SentryConstants.NULL_COL); hivePrivilege.setGrantOption(true);
hivePrivilege.setAction("select"); hivePrivilege.setURI(SentryStore.NULL_COL); hivePrivilege.setColumnName(SentryStore.NULL_COL); hivePrivilege.setGrantOption(true);
hivePrivilege.setAction("select"); hivePrivilege.setURI(SentryConstants.NULL_COL); hivePrivilege.setColumnName(SentryConstants.NULL_COL); hivePrivilege.setGrantOption(true);
hivePrivilege.setAction("select"); hivePrivilege.setURI(SentryConstants.NULL_COL); hivePrivilege.setColumnName(SentryConstants.NULL_COL); hivePrivilege.setGrantOption(true);
hivePrivilege.setAction("select"); hivePrivilege.setURI(SentryStore.NULL_COL); hivePrivilege.setColumnName(SentryStore.NULL_COL); hivePrivilege.setGrantOption(true);
hivePrivilege.setAction("select"); hivePrivilege.setURI(SentryConstants.NULL_COL); hivePrivilege.setColumnName(SentryConstants.NULL_COL); hivePrivilege.setGrantOption(true);