private TSentryGroup convertToTSentryGroup(MSentryGroup mSentryGroup) { return new TSentryGroup(mSentryGroup.getGroupName().intern()); }
private Map<String, MSentryGroup> getGroupNameTGroupMap(PersistenceManager pm) { Query query = pm.newQuery(MSentryGroup.class); List<MSentryGroup> mSentryGroups = (List<MSentryGroup>) query.execute(); Map<String, MSentryGroup> existGroupsMap = Maps.newHashMap(); if (mSentryGroups != null) { // change the List<MSentryGroup> -> Map<roleName, Set<MSentryGroup>> for (MSentryGroup mSentryGroup : mSentryGroups) { existGroupsMap.put(mSentryGroup.getGroupName(), mSentryGroup); } } return existGroupsMap; }
private Map<String, Set<String>> getGroupRolesMap(Collection<MSentryRole> mSentryRoles) { if (mSentryRoles.isEmpty()) { return Collections.emptyMap(); } Map<String, Set<String>> groupRolesMap = new HashMap<>(); // change the List<MSentryRole> -> Map<groupName, Set<roleName>> for (MSentryRole mSentryRole : mSentryRoles) { Set<MSentryGroup> groups = mSentryRole.getGroups(); for (MSentryGroup group : groups) { String groupName = group.getGroupName(); Set<String> rNames = groupRolesMap.get(groupName); if (rNames == null) { rNames = new HashSet<>(); } rNames.add(mSentryRole.getRoleName()); groupRolesMap.put(groupName, rNames); } } return groupRolesMap; }
/** * Get all groups as a map from group name to group * @param pm PersistenceManager instance * @return map of group names to group data for each group */ private Map<String, MSentryGroup> getGroupNameTGroupMap(PersistenceManager pm) { Query query = pm.newQuery(MSentryGroup.class); @SuppressWarnings("unchecked") List<MSentryGroup> mSentryGroups = (List<MSentryGroup>) query.execute(); if (mSentryGroups.isEmpty()) { return Collections.emptyMap(); } Map<String, MSentryGroup> existGroupsMap = new HashMap<>(mSentryGroups.size()); // change the List<MSentryGroup> -> Map<groupName, MSentryGroup> for (MSentryGroup mSentryGroup : mSentryGroups) { existGroupsMap.put(mSentryGroup.getGroupName(), mSentryGroup); } return existGroupsMap; }
private TSentryGroup convertToTSentryGroup(MSentryGroup mSentryGroup) { TSentryGroup group = new TSentryGroup(); group.setGroupName(mSentryGroup.getGroupName()); return group; }
public Set<TSentryRole> execute(PersistenceManager pm) throws Exception { Set<TSentryRole> tRoles = Sets.newHashSet(); pm.setDetachAllOnCommit(false); // No need to detach objects Set<MSentryRole> mSentryRoles = Sets.newHashSet(); if(groups.contains(null)) { mSentryRoles.addAll(delegate.getAllRoles(pm)); } else { mSentryRoles = delegate.getRolesForGroups(pm, groups); } for(MSentryRole mSentryRole: mSentryRoles) { String roleName = mSentryRole.getRoleName().intern(); Set<String> groupNames = Sets.newHashSet(); Set<MSentryGroup> mSentryGroups = mSentryRole.getGroups(); for(MSentryGroup mSentryGroup: mSentryGroups) { groupNames.add(mSentryGroup.getGroupName()); } tRoles.add(new TSentryRole(roleName, groupNames)); } return tRoles; } });
groupNames.add(group.getGroupName());
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); } } }
public Set<String> execute(PersistenceManager pm) throws Exception { pm.setDetachAllOnCommit(false); // No need to detach objects Query query = pm.newQuery(MSentryGroup.class); // Find privileges matching all roles QueryParamBuilder paramBuilder = QueryParamBuilder.addRolesFilter(query, null, roles); query.setFilter(paramBuilder.toString()); List<MSentryGroup> mGroups = (List<MSentryGroup>)query.executeWithMap(paramBuilder.getArguments()); Set<String> groupNames = new HashSet<>(); for(MSentryGroup g: mGroups) { groupNames.add(g.getGroupName()); } return groupNames; } });
/** * 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); } } }
retVal.put(role.getRoleName(), rUpdate); rUpdate.add(mGroup.getGroupName());