SentryPolicyStoreProcessor implements SentryPolicyService.Iface { @Override public TSentryPrivilegesResponse list_roles_privileges(TSentryPrivilegesRequest request) throws TException { TSentryPrivilegesResponse response = new TSentryPrivilegesResponse(); String requestor = request.getRequestorUserName(); try (Timer.Context timerContext = sentryMetrics.listRolesPrivilegesTimer.time()) { validateClientVersion(request.getProtocol_version()); authorize(requestor, getRequestorGroups(requestor)); response.setPrivilegesMap(sentryStore.getAllRolesPrivileges()); response.setStatus(Status.OK()); } catch (SentryThriftAPIMismatchException e) { LOGGER.error(e.getMessage(), e); response.setStatus(Status.THRIFT_VERSION_MISMATCH(e.getMessage(), e)); } catch (SentryAccessDeniedException e) { LOGGER.error(e.getMessage(), e); response.setStatus(Status.AccessDenied(e.getMessage(), e)); } catch (SentryUserException e) { LOGGER.error(e.getMessage(), e); response.setStatus(Status.AccessDenied(e.getMessage(), e)); } catch (Exception e) { String msg = "Could not read roles and privileges from the database: " + e.getMessage(); LOGGER.error(msg, e); response.setStatus(Status.RuntimeError(msg, e)); } return response; } SentryPolicyStoreProcessor(String name,
        Configuration conf, SentryStoreInterface store); void stop(); void registerPlugin(SentryPolicyStorePlugin plugin); @VisibleForTesting Configuration getSentryStoreConf(); @Override TIsSentryAdminResponse is_sentry_admin(TIsSentryAdminRequest request); @Override TCreateSentryRoleResponse create_sentry_role(
    TCreateSentryRoleRequest request); @Override TAlterSentryRoleGrantPrivilegeResponse alter_sentry_role_grant_privilege(TAlterSentryRoleGrantPrivilegeRequest request); @Override TAlterSentryRoleRevokePrivilegeResponse alter_sentry_role_revoke_privilege(TAlterSentryRoleRevokePrivilegeRequest request); @Override TDropSentryRoleResponse drop_sentry_role(
    TDropSentryRoleRequest request); @Override TAlterSentryRoleAddGroupsResponse alter_sentry_role_add_groups(
    TAlterSentryRoleAddGroupsRequest request); @Override TAlterSentryRoleAddUsersResponse alter_sentry_role_add_users(
      TAlterSentryRoleAddUsersRequest request); @Override TAlterSentryRoleDeleteUsersResponse alter_sentry_role_delete_users(
      TAlterSentryRoleDeleteUsersRequest request); @Override TAlterSentryRoleDeleteGroupsResponse alter_sentry_role_delete_groups(
    TAlterSentryRoleDeleteGroupsRequest request); @Override TListSentryRolesResponse list_sentry_roles_by_group(
    TListSentryRolesRequest request); TListSentryRolesResponse list_sentry_roles_by_user(TListSentryRolesForUserRequest request); @Override TListSentryPrivilegesResponse list_sentry_privileges_by_role(
      TListSentryPrivilegesRequest request); @Override TListSentryPrivilegesResponse list_sentry_privileges_by_user(
    TListSentryPrivilegesRequest request); @Override TListSentryPrivilegesResponse list_sentry_privileges_by_user_and_itsgroups(
          TListSentryPrivilegesRequest request); @Override TListSentryPrivilegesForProviderResponse list_sentry_privileges_for_provider(
      TListSentryPrivilegesForProviderRequest request); static Set<String> getGroupsFromUserName(Configuration conf,
      String userName); @Override TDropPrivilegesResponse drop_sentry_privilege(
      TDropPrivilegesRequest request); @Override TRenamePrivilegesResponse rename_sentry_privilege(
      TRenamePrivilegesRequest request); @Override TListSentryPrivilegesByAuthResponse list_sentry_privileges_by_authorizable(
      TListSentryPrivilegesByAuthRequest request); @Override TListSentryPrivilegesByAuthUserResponse list_sentry_privileges_by_authorizable_and_user(
      TListSentryPrivilegesByAuthUserRequest request); @Override TSentryConfigValueResponse get_sentry_config_value(
          TSentryConfigValueRequest request); @Override @SuppressWarnings("PMD.AvoidBranchingStatementAsLastInLoop") TSentryExportMappingDataResponse export_sentry_mapping_data(
      TSentryExportMappingDataRequest request); @Override TSentryImportMappingDataResponse import_sentry_mapping_data(
      TSentryImportMappingDataRequest request); @Override TSentrySyncIDResponse sentry_sync_notifications(TSentrySyncIDRequest request); @Override TSentryHmsEventNotificationResponse sentry_notify_hms_event(TSentryHmsEventNotification request); @Override TSentryPrivilegesResponse list_roles_privileges(TSentryPrivilegesRequest request); @Override TSentryPrivilegesResponse list_users_privileges(TSentryPrivilegesRequest request);  }
@Test public void testListRolesPrivileges() throws Exception { MockGroupMappingService.addUserGroupMapping("admin", Sets.newHashSet("admin")); Configuration conf = new Configuration(); conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING, MockGroupMappingService.class.getName()); conf.set(ServerConfig.ADMIN_GROUPS, "admin"); SentryPolicyStoreProcessor policyStoreProcessor = new SentryPolicyStoreProcessor(ApiConstants.SentryPolicyServiceConstants.SENTRY_POLICY_SERVICE_NAME, conf, sentryStore); TSentryPrivilegesResponse returnedResp; TSentryPrivilegesRequest request = new TSentryPrivilegesRequest(); request.setRequestorUserName("user1"); returnedResp = policyStoreProcessor.list_roles_privileges(request); Assert.assertEquals(Status.ACCESS_DENIED.getCode(), returnedResp.getStatus().getValue()); request.setRequestorUserName("admin"); Mockito.when(sentryStore.getAllRolesPrivileges()).thenReturn( Collections.emptyMap()); returnedResp = policyStoreProcessor.list_roles_privileges(request); Assert.assertEquals(Status.OK.getCode(), returnedResp.getStatus().getValue()); Assert.assertEquals(0, returnedResp.getPrivilegesMap().size()); ImmutableMap<String, Set<TSentryPrivilege>> rolesPrivileges = ImmutableMap.of( "role1", Sets.newHashSet( newSentryPrivilege("TABLE", "db1", "tbl1", "ALL"), newSentryPrivilege("DATABASE", "db1", "", "INSERT")), "role2", Sets.newHashSet( newSentryPrivilege("SERVER", "", "", "ALL")), "role3", Sets.newHashSet() ); Mockito.when(sentryStore.getAllRolesPrivileges()).thenReturn(rolesPrivileges); returnedResp = policyStoreProcessor.list_roles_privileges(request); Assert.assertEquals(Status.OK(), returnedResp.getStatus()); Assert.assertEquals(3, returnedResp.getPrivilegesMap().size()); Assert.assertEquals(2, returnedResp.getPrivilegesMap().get("role1").size()); Assert.assertEquals(1, returnedResp.getPrivilegesMap().get("role2").size()); Assert.assertEquals(0, returnedResp.getPrivilegesMap().get("role3").size()); }