public Set<MSentryRole> getRolesForGroups(PersistenceManager pm, Set<String> groups) { Set<MSentryRole> result = new HashSet<MSentryRole>(); Query query = pm.newQuery(MSentryGroup.class); query.setFilter("this.groupName == t"); query.declareParameters("java.lang.String t"); query.setUnique(true); for (String group : groups) { MSentryGroup sentryGroup = (MSentryGroup) query.execute(group.trim()); if (sentryGroup != null) { result.addAll(sentryGroup.getRoles()); } } return result; }
public Set<MSentryRole> getRolesForGroups(PersistenceManager pm, Set<String> groups) { Set<MSentryRole> result = Sets.newHashSet(); if (groups != null) { Query query = pm.newQuery(MSentryGroup.class); query.addExtension(LOAD_RESULTS_AT_COMMIT, "false"); query.setFilter(":p1.contains(this.groupName)"); FetchGroup grp = pm.getFetchGroup(MSentryGroup.class, "fetchRoles"); grp.addMember("roles"); pm.getFetchPlan().addGroup("fetchRoles"); List<MSentryGroup> sentryGroups = (List) query.execute(groups.toArray()); if (sentryGroups != null) { for (MSentryGroup sentryGroup : sentryGroups) { result.addAll(sentryGroup.getRoles()); } } } return result; }
public Map<String, Set<String>> getGroupNameRoleNamesMap() { boolean rollbackTransaction = true; PersistenceManager pm = null; try { pm = openTransaction(); Query query = pm.newQuery(MSentryGroup.class); List<MSentryGroup> mSentryGroups = (List<MSentryGroup>) query.execute(); Map<String, Set<String>> sentryGroupNameRoleNamesMap = Maps.newHashMap(); if (mSentryGroups != null) { // change the List<MSentryGroup> -> Map<groupName, Set<roleName>> for (MSentryGroup mSentryGroup : mSentryGroups) { String groupName = mSentryGroup.getGroupName(); Set<String> roleNames = Sets.newHashSet(); for (MSentryRole mSentryRole : mSentryGroup.getRoles()) { roleNames.add(mSentryRole.getRoleName()); } if (roleNames.size() > 0) { sentryGroupNameRoleNamesMap.put(groupName, roleNames); } } } commitTransaction(pm); rollbackTransaction = false; return sentryGroupNameRoleNamesMap; } finally { if (rollbackTransaction) { rollbackTransaction(pm); } } }
/** * This returns a Mapping of Role -> [Groups] */ public Map<String, LinkedList<String>> retrieveFullRoleImage() { Map<String, LinkedList<String>> retVal = new HashMap<String, LinkedList<String>>(); boolean rollbackTransaction = true; PersistenceManager pm = null; try { pm = openTransaction(); Query query = pm.newQuery(MSentryGroup.class); List<MSentryGroup> groups = (List<MSentryGroup>) query.execute(); for (MSentryGroup mGroup : groups) { for (MSentryRole role : mGroup.getRoles()) { LinkedList<String> rUpdate = retVal.get(role.getRoleName()); if (rUpdate == null) { rUpdate = new LinkedList<String>(); retVal.put(role.getRoleName(), rUpdate); } rUpdate.add(mGroup.getGroupName()); } } commitTransaction(pm); return retVal; } finally { if (rollbackTransaction) { rollbackTransaction(pm); } } }
for (MSentryRole role : mGroup.getRoles()) { List<String> rUpdate = retVal.get(role.getRoleName()); if (rUpdate == null) {
public Set<String> getRoleNamesForGroups(Set<String> groups) { Set<String> result = new HashSet<String>(); boolean rollbackTransaction = true; PersistenceManager pm = null; try { pm = openTransaction(); Query query = pm.newQuery(MSentryGroup.class); query.setFilter("this.groupName == t"); query.declareParameters("java.lang.String t"); query.setUnique(true); for (String group : groups) { MSentryGroup sentryGroup = (MSentryGroup) query.execute(group.trim()); if (sentryGroup != null) { for (MSentryRole role : sentryGroup.getRoles()) { result.add(role.getRoleName()); } } } rollbackTransaction = false; commitTransaction(pm); return result; } finally { if (rollbackTransaction) { rollbackTransaction(pm); } } }
for (MSentryRole role: mGroup.getRoles()) { String roleName = role.getRoleName(); if (roleNames.add(roleName)) {
pm.retrieve(sentryGroup); roles = sentryGroup.getRoles();