@Test public void testPrivilegeNotGranted() throws Exception { createPartitionedTable(DB_NAME, TABLE_NAME); assertFalse(privilegesGrantor.isSelectPrivilegeGranted(DB_NAME, DB_NAME)); }
public boolean isSelectPrivilegeGranted(String dbName, String tableName) { HiveObjectRef hiveObjectRef = new HiveObjectRef(); hiveObjectRef.setDbName(dbName); hiveObjectRef.setObjectType(HiveObjectType.TABLE); hiveObjectRef.setObjectName(tableName); try { return client .list_privileges(PrincipalName.PUBLIC.toString(), PrincipalType.ROLE, hiveObjectRef) .stream() .anyMatch(privilege -> privilege.getGrantInfo().getPrivilege().equals(Privilege.SELECT.toString())); } catch (TException e) { throw new HiveClientException(("Error checking if Select Privilege is granted on the table: " + tableName), e); } }
PrivilegesGrantor { public boolean isSelectPrivilegeGranted(String dbName, String tableName) { HiveObjectRef hiveObjectRef = new HiveObjectRef(); hiveObjectRef.setDbName(dbName); hiveObjectRef.setObjectType(HiveObjectType.TABLE); hiveObjectRef.setObjectName(tableName); try { return client .list_privileges(PrincipalName.PUBLIC.toString(), PrincipalType.ROLE, hiveObjectRef) .stream() .anyMatch(privilege -> privilege.getGrantInfo().getPrivilege().equals(Privilege.SELECT.toString())); } catch (TException e) { throw new HiveClientException(("Error checking if Select Privilege is granted on the table: " + tableName), e); } } }
PrivilegesGrantor { public boolean isSelectPrivilegeGranted(String dbName, String tableName) { HiveObjectRef hiveObjectRef = new HiveObjectRef(); hiveObjectRef.setDbName(dbName); hiveObjectRef.setObjectType(HiveObjectType.TABLE); hiveObjectRef.setObjectName(tableName); try { return client .list_privileges(PrincipalName.PUBLIC.toString(), PrincipalType.ROLE, hiveObjectRef) .stream() .anyMatch(privilege -> privilege.getGrantInfo().getPrivilege().equals(Privilege.SELECT.toString())); } catch (TException e) { throw new HiveClientException(("Error checking if Select Privilege is granted on the table: " + tableName), e); } } PrivilegesGrantor(IMetaStoreClient client); }
PrivilegesGrantor { public boolean isSelectPrivilegeGranted(String dbName, String tableName) { HiveObjectRef hiveObjectRef = new HiveObjectRef(); hiveObjectRef.setDbName(dbName); hiveObjectRef.setObjectType(HiveObjectType.TABLE); hiveObjectRef.setObjectName(tableName); try { return client .list_privileges(PrincipalName.PUBLIC.toString(), PrincipalType.ROLE, hiveObjectRef) .stream() .anyMatch(privilege -> privilege.getGrantInfo().getPrivilege().equals(Privilege.SELECT.toString())); } catch (TException e) { throw new HiveClientException(("Error checking if Select Privilege is granted on the table: " + tableName), e); } } PrivilegesGrantor(IMetaStoreClient client); void grantSelectPrivileges(String dbName, String tableName); boolean isSelectPrivilegeGranted(String dbName, String tableName); }
PrivilegesGrantor { public boolean isSelectPrivilegeGranted(String dbName, String tableName) { HiveObjectRef hiveObjectRef = new HiveObjectRef(); hiveObjectRef.setDbName(dbName); hiveObjectRef.setObjectType(HiveObjectType.TABLE); hiveObjectRef.setObjectName(tableName); try { return client .list_privileges(PrincipalName.PUBLIC.toString(), PrincipalType.ROLE, hiveObjectRef) .stream() .anyMatch(privilege -> privilege.getGrantInfo().getPrivilege().equals(Privilege.SELECT.toString())); } catch (TException e) { throw new HiveClientException(("Error checking if Select Privilege is granted on the table: " + tableName), e); } } PrivilegesGrantor(IMetaStoreClient client); void grantSelectPrivileges(String dbName, String tableName); boolean isSelectPrivilegeGranted(String dbName, String tableName);  }