@Test public void testRevokeAllPrivilege() throws Exception { String roleName = "r1"; String grantor = ADMIN_USER; PrivilegeObject queryPrivilege = new Builder() .setComponent(SEARCH) .setAction(SolrConstants.QUERY) .setService(SERVICE) .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME),new Field(FIELD_NAME))) .build(); PrivilegeObject updatePrivilege = new Builder(queryPrivilege) .setAction(SolrConstants.UPDATE) .build(); sentryStore.createRole(SEARCH, roleName, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, queryPrivilege, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, updatePrivilege, grantor); assertEquals(Sets.newHashSet(queryPrivilege,updatePrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName))); PrivilegeObject allPrivilege = new Builder(queryPrivilege) .setAction(SolrConstants.ALL) .build(); sentryStore.alterRoleRevokePrivilege(SEARCH, roleName, allPrivilege, grantor); assertEquals(Sets.newHashSet(), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName))); }
Set<PrivilegeObject> getPrivilegesByRole(Set<MSentryRole> roles, PersistenceManager pm) { if (roles == null || roles.isEmpty()) { return Collections.emptySet(); } Query query = pm.newQuery(MSentryGMPrivilege.class); QueryParamBuilder paramBuilder = QueryParamBuilder.addRolesFilter(query, null, SentryStore.rolesToRoleNames(roles)); query.setFilter(paramBuilder.toString()); List<MSentryGMPrivilege> mPrivileges = (List<MSentryGMPrivilege>)query.executeWithMap(paramBuilder.getArguments()); if (mPrivileges.isEmpty()) { return Collections.emptySet(); } Set<PrivilegeObject> privileges = new HashSet<>(mPrivileges.size()); for (MSentryGMPrivilege mPrivilege : mPrivileges) { privileges.add(new Builder() .setComponent(mPrivilege.getComponentName()) .setService(mPrivilege.getServiceName()) .setAction(mPrivilege.getAction()) .setAuthorizables(mPrivilege.getAuthorizables()) .withGrantOption(mPrivilege.getGrantOption()) .build()); } return privileges; }
PrivilegeOperatePersistence { Set<PrivilegeObject> getPrivilegesByRole(Set<MSentryRole> roles, PersistenceManager pm) { if (roles == null || roles.isEmpty()) { return Collections.emptySet(); } Query query = pm.newQuery(MSentryGMPrivilege.class); QueryParamBuilder paramBuilder = QueryParamBuilder.addRolesFilter(query, null, SentryStore.rolesToRoleNames(roles)); query.setFilter(paramBuilder.toString()); List<MSentryGMPrivilege> mPrivileges = (List<MSentryGMPrivilege>)query.executeWithMap(paramBuilder.getArguments()); if (mPrivileges.isEmpty()) { return Collections.emptySet(); } Set<PrivilegeObject> privileges = new HashSet<>(mPrivileges.size()); for (MSentryGMPrivilege mPrivilege : mPrivileges) { privileges.add(new Builder() .setComponent(mPrivilege.getComponentName()) .setService(mPrivilege.getServiceName()) .setAction(mPrivilege.getAction()) .setAuthorizables(mPrivilege.getAuthorizables()) .withGrantOption(mPrivilege.getGrantOption()) .build()); } return privileges; } }
PrivilegeOperatePersistence { Set<PrivilegeObject> getPrivilegesByRole(Set<MSentryRole> roles, PersistenceManager pm) { if (roles == null || roles.isEmpty()) { return Collections.emptySet(); } Query query = pm.newQuery(MSentryGMPrivilege.class); QueryParamBuilder paramBuilder = QueryParamBuilder.addRolesFilter(query, null, SentryStore.rolesToRoleNames(roles)); query.setFilter(paramBuilder.toString()); List<MSentryGMPrivilege> mPrivileges = (List<MSentryGMPrivilege>)query.executeWithMap(paramBuilder.getArguments()); if (mPrivileges.isEmpty()) { return Collections.emptySet(); } Set<PrivilegeObject> privileges = new HashSet<>(mPrivileges.size()); for (MSentryGMPrivilege mPrivilege : mPrivileges) { 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); }
PrivilegeOperatePersistence { Set<PrivilegeObject> getPrivilegesByRole(Set<MSentryRole> roles, PersistenceManager pm) { if (roles == null || roles.isEmpty()) { return Collections.emptySet(); } Query query = pm.newQuery(MSentryGMPrivilege.class); QueryParamBuilder paramBuilder = QueryParamBuilder.addRolesFilter(query, null, SentryStore.rolesToRoleNames(roles)); query.setFilter(paramBuilder.toString()); List<MSentryGMPrivilege> mPrivileges = (List<MSentryGMPrivilege>)query.executeWithMap(paramBuilder.getArguments()); if (mPrivileges.isEmpty()) { return Collections.emptySet(); } Set<PrivilegeObject> privileges = new HashSet<>(mPrivileges.size()); for (MSentryGMPrivilege mPrivilege : mPrivileges) { 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); void grantPrivilege(PrivilegeObject privilege,MSentryRole role, PersistenceManager pm); void revokePrivilege(PrivilegeObject privilege,MSentryRole role, PersistenceManager pm); void dropPrivilege(PrivilegeObject privilege,PersistenceManager pm); void renamePrivilege(String component, String service,
      List<? extends Authorizable> oldAuthorizables, List<? extends Authorizable> newAuthorizables,
      String grantorPrincipal, PersistenceManager pm); }
PrivilegeOperatePersistence { Set<PrivilegeObject> getPrivilegesByRole(Set<MSentryRole> roles, PersistenceManager pm) { if (roles == null || roles.isEmpty()) { return Collections.emptySet(); } Query query = pm.newQuery(MSentryGMPrivilege.class); QueryParamBuilder paramBuilder = QueryParamBuilder.addRolesFilter(query, null, SentryStore.rolesToRoleNames(roles)); query.setFilter(paramBuilder.toString()); List<MSentryGMPrivilege> mPrivileges = (List<MSentryGMPrivilege>)query.executeWithMap(paramBuilder.getArguments()); if (mPrivileges.isEmpty()) { return Collections.emptySet(); } Set<PrivilegeObject> privileges = new HashSet<>(mPrivileges.size()); for (MSentryGMPrivilege mPrivilege : mPrivileges) { 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); void grantPrivilege(PrivilegeObject privilege,MSentryRole role, PersistenceManager pm); void revokePrivilege(PrivilegeObject privilege,MSentryRole role, PersistenceManager pm); void dropPrivilege(PrivilegeObject privilege,PersistenceManager pm); void renamePrivilege(String component, String service,
      List<? extends Authorizable> oldAuthorizables, List<? extends Authorizable> newAuthorizables,
      String grantorPrincipal, PersistenceManager pm);  }