@Test public void testGetPrivilegesByAuthorizable() throws Exception { String roleName1 = "r1"; String roleName2 = "r2"; String roleName3 = "r3"; 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.alterRoleGrantPrivilege(SEARCH, roleName1, queryPrivilege1, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, updatePrivilege1, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, queryPrivilege2, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName3, updatePrivilege2, grantor); assertEquals(0, sentryStore.getPrivilegesByAuthorizable(SEARCH, service1, null, Arrays.asList(new Collection(COLLECTION_NAME), new Field(FIELD_NAME))).size()); assertEquals(2, sentryStore.getPrivilegesByAuthorizable(SEARCH, service1, Sets.newHashSet(roleName1), null).size()); assertEquals(2, sentryStore.getPrivilegesByAuthorizable(SEARCH, service1, Sets.newHashSet(roleName1,roleName2), null).size()); assertEquals(2, sentryStore.getPrivilegesByAuthorizable(SEARCH, service1, Sets.newHashSet(roleName1,roleName2, roleName3), null).size()); }
public Set<MSentryGMPrivilege> getPrivilegesByAuthorizable(String component, String service, Set<MSentryRole> roles, List<? extends Authorizable> authorizables, PersistenceManager pm) { Set<MSentryGMPrivilege> privilegeGraph = Sets.newHashSet(); if (roles == null || roles.isEmpty()) { return privilegeGraph; } MSentryGMPrivilege parentPrivilege = new MSentryGMPrivilege(component, service, authorizables, null, null); privilegeGraph.addAll(populateIncludePrivileges(roles, parentPrivilege, pm)); return privilegeGraph; }
PrivilegeOperatePersistence { public Set<MSentryGMPrivilege> getPrivilegesByAuthorizable(String component, String service, Set<MSentryRole> roles, List<? extends Authorizable> authorizables, PersistenceManager pm) { Set<MSentryGMPrivilege> privilegeGraph = Sets.newHashSet(); if (roles == null || roles.isEmpty()) { return privilegeGraph; } MSentryGMPrivilege parentPrivilege = new MSentryGMPrivilege(component, service, authorizables, null, null); privilegeGraph.addAll(populateIncludePrivileges(roles, parentPrivilege, pm)); return privilegeGraph; } }
PrivilegeOperatePersistence { public Set<MSentryGMPrivilege> getPrivilegesByAuthorizable(String component, String service, Set<MSentryRole> roles, List<? extends Authorizable> authorizables, PersistenceManager pm) { Set<MSentryGMPrivilege> privilegeGraph = Sets.newHashSet(); if (roles == null || roles.isEmpty()) { return privilegeGraph; } MSentryGMPrivilege parentPrivilege = new MSentryGMPrivilege(component, service, authorizables, null, null); privilegeGraph.addAll(populateIncludePrivileges(roles, parentPrivilege, pm)); return privilegeGraph; } PrivilegeOperatePersistence(Configuration conf); }
PrivilegeOperatePersistence { public Set<MSentryGMPrivilege> getPrivilegesByAuthorizable(String component, String service, Set<MSentryRole> roles, List<? extends Authorizable> authorizables, PersistenceManager pm) { Set<MSentryGMPrivilege> privilegeGraph = Sets.newHashSet(); if (roles == null || roles.isEmpty()) { return privilegeGraph; } MSentryGMPrivilege parentPrivilege = new MSentryGMPrivilege(component, service, authorizables, null, null); privilegeGraph.addAll(populateIncludePrivileges(roles, parentPrivilege, pm)); return privilegeGraph; } 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); }
PrivilegeOperatePersistence { public Set<MSentryGMPrivilege> getPrivilegesByAuthorizable(String component, String service, Set<MSentryRole> roles, List<? extends Authorizable> authorizables, PersistenceManager pm) { Set<MSentryGMPrivilege> privilegeGraph = Sets.newHashSet(); if (roles == null || roles.isEmpty()) { return privilegeGraph; } MSentryGMPrivilege parentPrivilege = new MSentryGMPrivilege(component, service, authorizables, null, null); privilegeGraph.addAll(populateIncludePrivileges(roles, parentPrivilege, pm)); return privilegeGraph; } 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);  }