SentryPolicyStoreProcessor implements SentryPolicyService.Iface { TSentryPrivilege constructOwnerPrivilege(TSentryAuthorizable authorizable) { SentryOwnerPrivilegeType ownerPrivilegeType = SentryOwnerPrivilegeType.get(conf); if(ownerPrivilegeType == SentryOwnerPrivilegeType.NONE) { return null; } if(Strings.isNullOrEmpty(authorizable.getDb())) { LOGGER.error("Received authorizable with out DB Name"); return null; } TSentryPrivilege ownerPrivilege = new TSentryPrivilege(); ownerPrivilege.setServerName(authorizable.getServer()); ownerPrivilege.setDbName(authorizable.getDb()); if(!Strings.isNullOrEmpty(authorizable.getTable())) { ownerPrivilege.setTableName(authorizable.getTable()); ownerPrivilege.setPrivilegeScope("TABLE"); } else { ownerPrivilege.setPrivilegeScope("DATABASE"); } if(ownerPrivilegeType == SentryOwnerPrivilegeType.ALL_WITH_GRANT) { ownerPrivilege.setGrantOption(TSentryGrantOption.TRUE); } ownerPrivilege.setAction(AccessConstants.OWNER); return ownerPrivilege; } 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 testConstructOwnerPrivilege() throws Exception { conf.set(SENTRY_DB_POLICY_STORE_OWNER_AS_PRIVILEGE, SentryOwnerPrivilegeType.NONE.toString()); SentryPolicyStoreProcessor sentryServiceHandler = new SentryPolicyStoreProcessor(ApiConstants.SentryPolicyServiceConstants.SENTRY_POLICY_SERVICE_NAME, conf, sentryStore); TSentryPrivilege privilege = new TSentryPrivilege(); TSentryAuthorizable authorizable = new TSentryAuthorizable("server1"); authorizable.setDb("db1"); authorizable.setTable("tb1"); assertNull(sentryServiceHandler.constructOwnerPrivilege(authorizable)); conf.set(SENTRY_DB_POLICY_STORE_OWNER_AS_PRIVILEGE, SentryOwnerPrivilegeType.ALL.toString()); sentryServiceHandler = new SentryPolicyStoreProcessor(ApiConstants.SentryPolicyServiceConstants.SENTRY_POLICY_SERVICE_NAME, conf, sentryStore); authorizable = new TSentryAuthorizable("server1"); authorizable.setTable("tb1"); assertNull(sentryServiceHandler.constructOwnerPrivilege(authorizable)); authorizable = new TSentryAuthorizable("server1"); authorizable.setDb("db1"); privilege.setServerName("server1"); privilege.setDbName("db1"); privilege.setAction(AccessConstants.OWNER); privilege.setPrivilegeScope("DATABASE"); Assert.assertNotNull(sentryServiceHandler.constructOwnerPrivilege(authorizable)); Assert.assertEquals(privilege, sentryServiceHandler.constructOwnerPrivilege(authorizable)); authorizable = new TSentryAuthorizable("server1"); authorizable.setDb("db1"); authorizable.setTable("tb1"); privilege.setTableName("tb1"); privilege.setPrivilegeScope("TABLE"); Assert.assertNotNull(sentryServiceHandler.constructOwnerPrivilege(authorizable)); Assert.assertEquals(privilege, sentryServiceHandler.constructOwnerPrivilege(authorizable)); conf.set(SENTRY_DB_POLICY_STORE_OWNER_AS_PRIVILEGE, SentryOwnerPrivilegeType.ALL_WITH_GRANT.toString()); sentryServiceHandler = new SentryPolicyStoreProcessor(ApiConstants.SentryPolicyServiceConstants.SENTRY_POLICY_SERVICE_NAME, conf, sentryStore); authorizable = new TSentryAuthorizable("server1"); authorizable.setDb("db1"); authorizable.setTable("tb1"); privilege.setPrivilegeScope("TABLE"); privilege.setGrantOption(TSentryGrantOption.TRUE); Assert.assertNotNull(sentryServiceHandler.constructOwnerPrivilege(authorizable)); Assert.assertEquals(privilege, sentryServiceHandler.constructOwnerPrivilege(authorizable)); }