PrivilegeOperatePersistence { public Set<PrivilegeObject> getPrivilegesByProvider(String component, String service, Set<MSentryRole> roles, List<? extends Authorizable> authorizables, PersistenceManager pm) { Set<PrivilegeObject> privileges = Sets.newHashSet(); if (roles == null || roles.isEmpty()) { return privileges; } MSentryGMPrivilege parentPrivilege = new MSentryGMPrivilege(component, service, authorizables, null, null); Set<MSentryGMPrivilege> privilegeGraph = Sets.newHashSet(); privilegeGraph.addAll(populateIncludePrivileges(roles, parentPrivilege, pm)); for (MSentryGMPrivilege mPrivilege : privilegeGraph) { privileges.add(new Builder() .setComponent(mPrivilege.getComponentName()) .setService(mPrivilege.getServiceName()) .setAction(mPrivilege.getAction()) .setAuthorizables(mPrivilege.getAuthorizables()) .withGrantOption(mPrivilege.getGrantOption()) .build()); } return privileges; } 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 testGetPrivilegesByProvider() throws Exception { String roleName1 = "r1"; String roleName2 = "r2"; String roleName3 = "r3"; String group = "g3"; String grantor = ADMIN_USER; String service1 = "service1"; PrivilegeObject queryPrivilege1 = new Builder() .setComponent(SEARCH) .setAction(SearchConstants.QUERY) .setService(service1) .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME))) .build(); PrivilegeObject updatePrivilege1 = new Builder() .setComponent(SEARCH) .setAction(SearchConstants.UPDATE) .setService(service1) .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME), new Field(FIELD_NAME))) .build(); PrivilegeObject queryPrivilege2 = new Builder() .setComponent(SEARCH) .setAction(SearchConstants.QUERY) .setService(service1) .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME))) .build(); PrivilegeObject updatePrivilege2 = new Builder() .setComponent(SEARCH) .setAction(SearchConstants.UPDATE) .setService(service1) .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME), new Field(FIELD_NAME))) .build(); sentryStore.createRole(SEARCH, roleName1, grantor); sentryStore.createRole(SEARCH, roleName2, grantor); sentryStore.createRole(SEARCH, roleName3, grantor); sentryStore.alterRoleAddGroups(SEARCH, roleName3, Sets.newHashSet(group), grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, queryPrivilege1, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, updatePrivilege1, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, queryPrivilege2, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName3, updatePrivilege2, grantor); assertEquals(Sets.newHashSet(updatePrivilege1, queryPrivilege1), sentryStore.getPrivilegesByProvider(SEARCH, service1, Sets.newHashSet(roleName1), null, null)); assertEquals(Sets.newHashSet(updatePrivilege1, queryPrivilege1, queryPrivilege2), sentryStore.getPrivilegesByProvider(SEARCH, service1, Sets.newHashSet(roleName1,roleName2), null, null)); assertEquals(Sets.newHashSet(updatePrivilege1, queryPrivilege1, queryPrivilege2, updatePrivilege2), sentryStore.getPrivilegesByProvider(SEARCH, service1, Sets.newHashSet(roleName1,roleName2), Sets.newHashSet(group), null)); List<? extends Authorizable> authorizables = Arrays.asList(new Collection(COLLECTION_NAME), new Field(FIELD_NAME)); assertEquals(Sets.newHashSet(updatePrivilege1, updatePrivilege2), sentryStore.getPrivilegesByProvider(SEARCH, service1, Sets.newHashSet(roleName1,roleName2), Sets.newHashSet(group), authorizables)); }