SentryStore implements SentryStoreInterface { public List<MSentryPrivilege> getPrivilegesForAuthorizables(List<TSentryAuthorizable> authHierarchyList) throws Exception { return tm.executeTransaction( pm -> getPrivilegesForAuthorizables(pm, authHierarchyList) ); } SentryStore(Configuration conf); static Properties getDataNucleusProperties(Configuration conf); void setPersistUpdateDeltas(boolean persistUpdateDeltas); TransactionManager getTransactionManager(); CounterWait getCounterWait(); synchronized void stop(); MSentryRole getRole(PersistenceManager pm, String roleName); @SuppressWarnings("unchecked") List<MSentryRole> getAllRoles(PersistenceManager pm); MSentryUser getUser(PersistenceManager pm, String userName); void createSentryUser(final String userName); void createSentryRole(final String roleName); Gauge<Long> getRoleCountGauge(); Gauge<Long> getPrivilegeCountGauge(); Gauge<Long> getGenericModelPrivilegeCountGauge(); Gauge<Long> getGroupCountGauge(); Gauge<Long> getAuthzObjectsCountGauge(); Gauge<Long> getAuthzPathsCountGauge(); Gauge<Integer> getHMSWaitersCountGauge(); Gauge<Long> getLastNotificationIdGauge(); Gauge<Long> getLastPathsSnapshotIdGauge(); Gauge<Long> getPermChangeIdGauge(); Gauge<Long> getPathChangeIdGauge(); void clearHmsPathInformation(); void purgeDeltaChangeTables(); void purgeNotificationIdTable(); @Override void alterSentryRoleGrantPrivileges(final String roleName,
    final Set<TSentryPrivilege> privileges); @Override void alterSentryRoleGrantPrivileges(final String roleName,
    final Set<TSentryPrivilege> privileges,
    final Map<TSentryPrivilege, Update> privilegesUpdateMap); void alterSentryUserGrantPrivileges(final String userName,
    final Set<TSentryPrivilege> privileges); void alterSentryGrantOwnerPrivilege(final String principalName, SentryPrincipalType entityType,
                                              final TSentryPrivilege privilege,
                                              final Update update); @VisibleForTesting MSentryUser getMSentryUserByName(final String userName); void alterSentryUserRevokePrivileges(final String userName,
    final Set<TSentryPrivilege> tPrivileges); @Override void alterSentryRoleRevokePrivileges(final String roleName,
    final Set<TSentryPrivilege> tPrivileges); @Override void alterSentryRoleRevokePrivileges(final String roleName, final Set<TSentryPrivilege> tPrivileges,
    final Map<TSentryPrivilege, Update> privilegesUpdateMap); void dropSentryUser(final String userName); synchronized void dropSentryUser(final String userName,
      final Update update); void dropSentryRole(final String roleName); synchronized void dropSentryRole(final String roleName,
      final Update update); void alterSentryRoleAddGroups(final String grantorPrincipal,
      final String roleName, final Set<TSentryGroup> groupNames); synchronized void alterSentryRoleAddGroups(final String grantorPrincipal,
      final String roleName, final Set<TSentryGroup> groupNames,
      final Update update); void alterSentryRoleAddUsers(final String roleName,
      final Set<String> userNames); void alterSentryRoleDeleteUsers(final String roleName,
      final Set<String> userNames); void alterSentryRoleDeleteGroups(final String roleName,
      final Set<TSentryGroup> groupNames); synchronized void alterSentryRoleDeleteGroups(final String roleName,
      final Set<TSentryGroup> groupNames, final Update update); @VisibleForTesting MSentryRole getMSentryRoleByName(final String roleName); Set<TSentryPrivilege> getAllTSentryPrivilegesByUserName(String userName); TSentryPrivilegeMap listSentryPrivilegesByAuthorizable(Set<String> groups,
      TSentryActiveRoleSet activeRoles,
      TSentryAuthorizable authHierarchy, boolean isAdmin); List<SentryOwnerInfo> listOwnersByAuthorizable(TSentryAuthorizable authorizable); TSentryPrivilegeMap listSentryPrivilegesByAuthorizableForUser(Set<String> userNames,
      TSentryAuthorizable authHierarchy, boolean isAdmin); Set<TSentryPrivilege> getAllTSentryPrivilegesByRoleName(String roleName); Set<TSentryPrivilege> getTSentryPrivileges(SentryPrincipalType principalType, Set<String> principalNames,
                                                    TSentryAuthorizable authHierarchy); Set<TSentryRole> getTSentryRolesByGroupName(final Set<String> groupNames,
                                                     final boolean checkAllGroups); Set<String> getRoleNamesForGroups(final Set<String> groups); Set<String> getRoleNamesForUsers(final Set<String> users); Set<TSentryRole> getTSentryRolesByUserNames(final Set<String> users); Set<MSentryRole> getRolesForGroups(PersistenceManager pm, Set<String> groups); @Override Set<TSentryPrivilege> listSentryPrivilegesByUsersAndGroups(
      Set<String> groups, Set<String> users, TSentryActiveRoleSet roleSet,
      TSentryAuthorizable authHierarchy); Set<String> listSentryPrivilegesForProvider(
      Set<String> groups, Set<String> users, TSentryActiveRoleSet roleSet,
      TSentryAuthorizable authHierarchy); boolean hasAnyServerPrivileges(Set<String> groups, Set<String> users,
      TSentryActiveRoleSet roleSet, String server); @VisibleForTesting static Set<String> toTrimedLower(Set<String> s); void dropPrivilege(final TSentryAuthorizable tAuthorizable); synchronized void dropPrivilege(final TSentryAuthorizable tAuthorizable,
      final Update update); synchronized void updateOwnerPrivilege(final TSentryAuthorizable tAuthorizable,
      String ownerName,  SentryPrincipalType principalType,
      final List<Update> updates); void revokeOwnerPrivilegesCore(PersistenceManager pm, final TSentryAuthorizable tAuthorizable); void renamePrivilege(final TSentryAuthorizable oldTAuthorizable,
      final TSentryAuthorizable newTAuthorizable); synchronized void renamePrivilege(final TSentryAuthorizable oldTAuthorizable,
      final TSentryAuthorizable newTAuthorizable, final Update update); static String toNULLCol(String s); PermissionsImage retrieveFullPermssionsImage(); PathsUpdate retrieveFullPathsImageUpdate(final String[] prefixes); void persistFullPathsImage(final Map<String, Collection<String>> authzPaths,
      final long notificationID); void logPersistingFullSnapshotState(int totalNumberOfObjectsToPersist,
      int totalNumberOfPathsToPersist, int objectsPersistedCount, int pathsPersistedCount); void addAuthzPathsMapping(final String authzObj, final Collection<String> paths,
      final UniquePathsUpdate update); void deleteAuthzPathsMapping(final String authzObj, final Collection<String> paths,
      final UniquePathsUpdate update); void deleteAllAuthzPathsMapping(final String authzObj, final UniquePathsUpdate update); void renameAuthzPathsMapping(final String oldObj, final String newObj,
      final String oldPath, final String newPath, final UniquePathsUpdate update); void renameAuthzObj(final String oldObj, final String newObj,
      final UniquePathsUpdate update); boolean isAuthzPathsMappingEmpty(); boolean isHmsNotificationEmpty(); boolean isAuthzPathsSnapshotEmpty(); void updateAuthzPathsMapping(final String authzObj, final String oldPath,
        final String newPath, final UniquePathsUpdate update); @SuppressWarnings("unchecked") List<Map<String, Set<String>>> getGroupUserRoleMapList(final Collection<String> roleNames); List<MSentryPrivilege> getPrivilegesForAuthorizables(List<TSentryAuthorizable> authHierarchyList); Map<String, Set<TSentryPrivilege>> getRoleNameTPrivilegesMap(final String dbName,
        final String tableName); Set<String> getAllRoleNames(); void importSentryMetaData(final TSentryMappingData tSentryMappingData,
      final boolean isOverwriteForRole); static Set<String> rolesToRoleNames(final Iterable<MSentryRole> roles); void setLastProcessedNotificationID(final Long notificationId); void persistLastProcessedNotificationID(final Long notificationId); Long getLastProcessedPermChangeID(); Long getLastProcessedPathChangeID(); Long getLastProcessedNotificationID(); long getLastProcessedImageID(); MSentryPermChange getMSentryPermChangeByID(final long changeID); Boolean permChangeExists(final long changeID); Boolean pathChangeExists(final long changeID); MSentryPathChange getMSentryPathChangeByID(final long changeID); List<MSentryPathChange> getMSentryPathChanges(final long changeID); List<MSentryPermChange> getMSentryPermChanges(final long changeID); boolean validateDeltaChanges(final long changeID, List<T> changes); boolean isNotificationProcessed(final String hash); PrivilegePrincipal getEntity(PersistenceManager pm, String name, SentryPrincipalType type); @Override Map<String, Set<TSentryPrivilege>> getAllRolesPrivileges(); @Override Map<String, Set<TSentryPrivilege>> getAllUsersPrivileges();  }
@Test public void testgetPrivilegesForAuthorizables() throws Exception { String roleName1 = "list-privs-r1"; String userName1 = "user1"; String uri1 = "file: sentryStore.createSentryRole(roleName1); sentryStore.createSentryUser(userName1); TSentryPrivilege privilege_tbl1 = new TSentryPrivilege(); privilege_tbl1.setPrivilegeScope("TABLE"); privilege_tbl1.setServerName("server1"); privilege_tbl1.setDbName("db1"); privilege_tbl1.setTableName("tbl1"); privilege_tbl1.setCreateTime(System.currentTimeMillis()); privilege_tbl1.setAction("SELECT"); privilege_tbl1.setGrantOption(TSentryGrantOption.TRUE); TSentryAuthorizable tSentryAuthorizable = new TSentryAuthorizable(); tSentryAuthorizable.setServer("server1"); tSentryAuthorizable.setDb("db1"); tSentryAuthorizable.setTable("tbl1"); TSentryPrivilege privilege_tbl2 = new TSentryPrivilege(); privilege_tbl2.setPrivilegeScope("TABLE"); privilege_tbl2.setServerName("server1"); privilege_tbl2.setDbName("db1"); privilege_tbl2.setTableName("tbl2"); privilege_tbl2.setCreateTime(System.currentTimeMillis()); privilege_tbl2.setAction("SELECT"); privilege_tbl2.setGrantOption(TSentryGrantOption.TRUE); TSentryAuthorizable tSentryAuthorizable2 = new TSentryAuthorizable(); tSentryAuthorizable2.setServer("server1"); tSentryAuthorizable2.setDb("db1"); tSentryAuthorizable2.setTable("tbl2"); TSentryPrivilege privilege_col1 = new TSentryPrivilege(privilege_tbl2); privilege_col1.setPrivilegeScope("TABLE"); privilege_col1.setServerName("server1"); privilege_col1.setDbName("db3"); privilege_col1.setTableName("tbl3"); privilege_col1.setCreateTime(System.currentTimeMillis()); privilege_col1.setAction("SELECT"); privilege_col1.setGrantOption(TSentryGrantOption.TRUE); privilege_col1.setColumnName("Column1"); TSentryAuthorizable tSentryAuthorizable3 = new TSentryAuthorizable(); tSentryAuthorizable3.setServer("server1"); tSentryAuthorizable3.setDb("db3"); tSentryAuthorizable3.setTable("tbl3"); tSentryAuthorizable3.setColumn("Column1"); TSentryPrivilege tSentryUriPrivilege = new TSentryPrivilege("URI", "server1", "ALL"); tSentryUriPrivilege.setURI(uri1); TSentryAuthorizable tSentryUriAuthorizable = new TSentryAuthorizable(); tSentryUriAuthorizable.setUri(uri1); tSentryUriAuthorizable.setServer("server1"); sentryStore.alterSentryGrantPrivileges(SentryPrincipalType.ROLE, roleName1, Sets.newHashSet(privilege_tbl1,privilege_tbl2, privilege_col1, tSentryUriPrivilege), null); List<MSentryPrivilege> privilege = sentryStore.getPrivilegesForAuthorizables(Lists.newArrayList(tSentryAuthorizable,tSentryAuthorizable2, tSentryUriAuthorizable, tSentryAuthorizable3)); assertEquals(4, privilege.size()); privilege = sentryStore.getPrivilegesForAuthorizables(Collections.EMPTY_LIST); assertNotNull(privilege); assertEquals(4, privilege.size()); privilege = sentryStore.getPrivilegesForAuthorizables(null); assertNotNull(privilege); assertEquals(4, privilege.size()); privilege = sentryStore.getPrivilegesForAuthorizables(Lists.newArrayList(tSentryAuthorizable2)); assertEquals(1, privilege.size()); TSentryAuthorizable tSentrDbAuthorizable = new TSentryAuthorizable(); tSentrDbAuthorizable.setServer("server1"); tSentrDbAuthorizable.setDb("db1"); privilege = sentryStore.getPrivilegesForAuthorizables(Lists.newArrayList(tSentrDbAuthorizable)); assertEquals(2, privilege.size()); privilege = sentryStore.getPrivilegesForAuthorizables(Lists.newArrayList(tSentryAuthorizable3)); assertEquals(1, privilege.size()); TSentryAuthorizable tSentrServerAuthorizable = new TSentryAuthorizable(); tSentrServerAuthorizable.setServer("server1"); privilege = sentryStore.getPrivilegesForAuthorizables(Lists.newArrayList(tSentrServerAuthorizable)); assertEquals(4, privilege.size()); sentryStore.alterSentryGrantPrivileges(SentryPrincipalType.USER, userName1, Sets.newHashSet(privilege_tbl1,privilege_tbl2, tSentryUriPrivilege), null); privilege = sentryStore.getPrivilegesForAuthorizables(Lists.newArrayList(tSentrServerAuthorizable)); assertEquals(4, privilege.size()); }