PrivilegeOperatePersistence { public void renamePrivilege(String component, String service, List<? extends Authorizable> oldAuthorizables, List<? extends Authorizable> newAuthorizables, String grantorPrincipal, PersistenceManager pm) throws SentryUserException { MSentryGMPrivilege oldPrivilege = new MSentryGMPrivilege(component, service, oldAuthorizables, null, null); oldPrivilege.setAction(getAction(component,Action.ALL).getValue()); Set<MSentryGMPrivilege> privilegeGraph = Sets.newHashSet(); privilegeGraph.addAll(populateIncludePrivileges(null, oldPrivilege, pm)); for (MSentryGMPrivilege dropPrivilege : privilegeGraph) { List<Authorizable> authorizables = new ArrayList<Authorizable>( dropPrivilege.getAuthorizables()); for (int i = 0; i < newAuthorizables.size(); i++) { authorizables.set(i, newAuthorizables.get(i)); } MSentryGMPrivilege newPrivilge = new MSentryGMPrivilege( component,service, authorizables, dropPrivilege.getAction(), dropPrivilege.getGrantOption()); pm.retrieve(dropPrivilege); Set<MSentryRole> roles = dropPrivilege.getRoles(); for (MSentryRole role : roles) { revokeRolePartial(oldPrivilege, dropPrivilege, role, pm); grantRolePartial(newPrivilge, 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 testRenamePrivilege() throws Exception{ String roleName1 = "r1"; String roleName2 = "r2"; String grantor = ADMIN_USER; List<? extends Authorizable> oldAuthoriables = Arrays.asList(new Collection(COLLECTION_NAME), new Field(FIELD_NAME)); List<? extends Authorizable> newAuthoriables = Arrays.asList(new Collection(COLLECTION_NAME), new Field(NOT_FIELD_NAME)); PrivilegeObject oldQueryPrivilege = new Builder() .setComponent(SEARCH) .setAction(SearchConstants.QUERY) .setService(SERVICE) .setAuthorizables(oldAuthoriables) .build(); PrivilegeObject oldUpdatePrivilege = new Builder(oldQueryPrivilege) .setAction(SearchConstants.UPDATE) .build(); PrivilegeObject oldALLPrivilege = new Builder(oldQueryPrivilege) .setAction(SearchConstants.ALL) .build(); PrivilegeObject newQueryPrivilege = new Builder() .setComponent(SEARCH) .setAction(SearchConstants.QUERY) .setService(SERVICE) .setAuthorizables(newAuthoriables) .build(); PrivilegeObject newUpdatePrivilege = new Builder(newQueryPrivilege) .setAction(SearchConstants.UPDATE) .build(); PrivilegeObject newALLPrivilege = new Builder(newQueryPrivilege) .setAction(SearchConstants.ALL) .build(); sentryStore.createRole(SEARCH, roleName1, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, oldQueryPrivilege, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, oldUpdatePrivilege, grantor); sentryStore.createRole(SEARCH, roleName2, grantor); sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, oldALLPrivilege, grantor); assertEquals(Sets.newHashSet(oldQueryPrivilege,oldUpdatePrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1))); assertEquals(Sets.newHashSet(oldALLPrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2))); sentryStore.renamePrivilege(SEARCH, SERVICE, oldAuthoriables, newAuthoriables, grantor); assertEquals(Sets.newHashSet(newQueryPrivilege,newUpdatePrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1))); assertEquals(Sets.newHashSet(newALLPrivilege), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2))); List<? extends Authorizable> newAuthoriables1 = Arrays.asList(new Collection(NOT_COLLECTION_NAME),new Field(NOT_FIELD_NAME)); PrivilegeObject newQueryPrivilege1 = new Builder(newQueryPrivilege) .setAuthorizables(newAuthoriables1) .build(); PrivilegeObject newUpdatePrivilege1 = new Builder(newUpdatePrivilege) .setAuthorizables(newAuthoriables1) .build(); PrivilegeObject newALLPrivilege1 = new Builder(newALLPrivilege) .setAuthorizables(newAuthoriables1) .build(); sentryStore.renamePrivilege(SEARCH, SERVICE, Arrays.asList(new Collection(COLLECTION_NAME)), Arrays.asList(new Collection(NOT_COLLECTION_NAME)), grantor); assertEquals(Sets.newHashSet(newQueryPrivilege1,newUpdatePrivilege1), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1))); assertEquals(Sets.newHashSet(newALLPrivilege1), sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2))); }