/** * Removes all the privileges associated with * a particular role. After this dis-association if the * privilege doesn't have any roles associated it will be * removed from the underlying persistence layer. * @param pm Instance of PersistenceManager * @param sentryRole Role for which all the privileges are to be removed. */ private void removePrivileges(PersistenceManager pm, MSentryRole sentryRole) { List<MSentryPrivilege> privilegesCopy = new ArrayList<>(sentryRole.getPrivileges()); List<MSentryGMPrivilege> gmPrivilegesCopy = new ArrayList<>(sentryRole.getGmPrivileges()); sentryRole.removePrivileges(); // with SENTRY-398 generic model sentryRole.removeGMPrivileges(); removeStaledPrivileges(pm, privilegesCopy); removeStaledGMPrivileges(pm, gmPrivilegesCopy); }
private void dropSentryRoleCore(PersistenceManager pm, String roleName) throws SentryNoSuchObjectException { String lRoleName = roleName.trim().toLowerCase(); Query query = pm.newQuery(MSentryRole.class); query.setFilter("this.roleName == t"); query.declareParameters("java.lang.String t"); query.setUnique(true); MSentryRole sentryRole = (MSentryRole) query.execute(lRoleName); if (sentryRole == null) { throw new SentryNoSuchObjectException("Role: " + lRoleName + " doesn't exist"); } else { pm.retrieve(sentryRole); int numPrivs = sentryRole.getPrivileges().size(); sentryRole.removePrivileges(); // with SENTRY-398 generic model sentryRole.removeGMPrivileges(); privCleaner.incPrivRemoval(numPrivs); pm.deletePersistent(sentryRole); } }
} else { pm.retrieve(sentryRole); sentryRole.removeGMPrivileges(); sentryRole.removePrivileges(); pm.deletePersistent(sentryRole);
role.removeGMPrivileges(); pm.deletePersistent(role); commitTransaction(pm);
role1 = getMSentryRole(pm, roleName1); role1.removePrivileges(); role1.removeGMPrivileges(); pm.deletePersistent(role1); commitTransaction(pm);
role.removeGMPrivileges(); role.removePrivileges(); pm.makePersistent(role);
role.removeGMPrivileges(); role.removePrivileges(); pm.makePersistent(role);