PrivilegeOperatePersistence { public void dropPrivilege(PrivilegeObject privilege,PersistenceManager pm) { MSentryGMPrivilege requestPrivilege = convertToPrivilege(privilege); if (Strings.isNullOrEmpty(privilege.getAction())) { requestPrivilege.setAction(getAction(privilege.getComponent(), Action.ALL).getValue()); } Set<MSentryGMPrivilege> privilegeGraph = Sets.newHashSet(); privilegeGraph.addAll(populateIncludePrivileges(null, requestPrivilege, pm)); for (MSentryGMPrivilege mPrivilege : privilegeGraph) { pm.retrieve(mPrivilege); Set<MSentryRole> roles = mPrivilege.getRoles(); for (MSentryRole role : roles) { revokeRolePartial(requestPrivilege, mPrivilege, role, pm); } } } PrivilegeOperatePersistence(Configuration conf); boolean checkPrivilegeOption(Set<MSentryRole> roles, PrivilegeObject privilege, PersistenceManager pm); void grantPrivilege(PrivilegeObject privilege,MSentryRole role, PersistenceManager pm); void revokePrivilege(PrivilegeObject privilege,MSentryRole role, PersistenceManager pm); void dropPrivilege(PrivilegeObject privilege,PersistenceManager pm); @SuppressWarnings("unchecked") Set<PrivilegeObject> getPrivilegesByRole(Set<MSentryRole> roles, PersistenceManager pm); Set<PrivilegeObject> getPrivilegesByProvider(String component,
      String service, Set<MSentryRole> roles,
      List<? extends Authorizable> authorizables, PersistenceManager pm); Set<MSentryGMPrivilege> getPrivilegesByAuthorizable(String component,
      String service, Set<MSentryRole> roles,
      List<? extends Authorizable> authorizables, PersistenceManager pm); void renamePrivilege(String component, String service,
      List<? extends Authorizable> oldAuthorizables, List<? extends Authorizable> newAuthorizables,
      String grantorPrincipal, PersistenceManager pm);  }
@Test public void testDropPrivilege() throws Exception{ String roleName1 = "r1"; String roleName2 = "r2"; String grantor = ADMIN_USER; PrivilegeObject queryPrivilege = new Builder() .setComponent(SEARCH) .setAction(SearchConstants.QUERY) .setService(SERVICE) .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME), new Field(FIELD_NAME))) .build(); PrivilegeObject updatePrivilege = new Builder(queryPrivilege) .setAction(SearchConstants.UPDATE) .build(); sentryStore.createRole(SEARCH, roleName1, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, queryPrivilege, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, updatePrivilege, grantor); sentryStore.createRole(SEARCH, roleName2, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, queryPrivilege, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, updatePrivilege, grantor); assertEquals(Sets.newHashSet(queryPrivilege,updatePrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1))); assertEquals(Sets.newHashSet(queryPrivilege,updatePrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2))); sentryStore.dropPrivilege(SEARCH, queryPrivilege, grantor); assertEquals(Sets.newHashSet(updatePrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1))); assertEquals(Sets.newHashSet(updatePrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2))); PrivilegeObject allPrivilege = new Builder(queryPrivilege) .setAction(SearchConstants.ALL) .build(); sentryStore.dropPrivilege(SEARCH, allPrivilege, grantor); assertEquals(Sets.newHashSet(), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1))); assertEquals(Sets.newHashSet(), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2))); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, queryPrivilege, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, updatePrivilege, grantor); PrivilegeObject parentPrivilege = new Builder() .setComponent(SEARCH) .setAction(SearchConstants.ALL) .setService(SERVICE) .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME))) .build(); sentryStore.dropPrivilege(SEARCH, parentPrivilege, grantor); assertEquals(Sets.newHashSet(), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1))); }