public void appendGroup(MSentryGroup group) { if (groups.add(group)) { group.appendRole(this); } }
private TSentryGroup convertToTSentryGroup(MSentryGroup mSentryGroup) { return new TSentryGroup(mSentryGroup.getGroupName().intern()); }
public void removeGroup(MSentryGroup group) { if (groups.remove(group)) { group.removeRole(this); } }
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); } } }
private void alterSentryRoleAddGroupsCore(PersistenceManager pm, String roleName, Set<TSentryGroup> groupNames) throws SentryNoSuchObjectException { // All role names are stored in lowercase. String lRoleName = trimAndLower(roleName); MSentryRole role = getRole(pm, lRoleName); if (role == null) { throw noSuchRole(lRoleName); } // Add the group to the specified role if it does not belong to the role yet. Query query = pm.newQuery(MSentryGroup.class); query.setFilter("this.groupName == :groupName"); query.setUnique(true); List<MSentryGroup> groups = Lists.newArrayList(); for (TSentryGroup tGroup : groupNames) { String groupName = tGroup.getGroupName().trim(); MSentryGroup group = (MSentryGroup) query.execute(groupName); if (group == null) { group = new MSentryGroup(groupName, System.currentTimeMillis(), Sets.newHashSet(role)); } group.appendRole(role); groups.add(group); } pm.makePersistentAll(groups); }
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 MSentryGroup(String groupName, long createTime, Set<MSentryRole> roles) { this.setGroupName(groupName); this.createTime = createTime; this.roles = roles; }
/** * 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); } } }
private void alterSentryRoleAddGroupsCore(PersistenceManager pm, String roleName, Set<TSentryGroup> groupNames) 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 role = (MSentryRole) query.execute(lRoleName); if (role == null) { throw new SentryNoSuchObjectException("Role: " + lRoleName + " doesn't exist"); } else { query = pm.newQuery(MSentryGroup.class); query.setFilter("this.groupName == t"); query.declareParameters("java.lang.String t"); query.setUnique(true); List<MSentryGroup> groups = Lists.newArrayList(); for (TSentryGroup tGroup : groupNames) { String groupName = tGroup.getGroupName().trim(); MSentryGroup group = (MSentryGroup) query.execute(groupName); if (group == null) { group = new MSentryGroup(groupName, System.currentTimeMillis(), Sets.newHashSet(role)); } group.appendRole(role); groups.add(group); } pm.makePersistentAll(groups); } }
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; }
for (MSentryRole role : mGroup.getRoles()) { List<String> rUpdate = retVal.get(role.getRoleName()); if (rUpdate == null) { retVal.put(role.getRoleName(), rUpdate); rUpdate.add(mGroup.getGroupName());
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; }
public void removeGroup(MSentryGroup group) { if (groups.remove(group)) { group.removeRole(this); } }
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); } } }
public void appendGroup(MSentryGroup group) { if (groups.add(group)) { group.appendRole(this); } }
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; }
MSentryGroup group = (MSentryGroup) query.execute(groupName); if (group != null) { group.removeRole(role); groups.add(group);
for (MSentryRole role: mGroup.getRoles()) { String roleName = role.getRoleName(); if (roleNames.add(roleName)) {
/** * 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; }
MSentryGroup group = (MSentryGroup) query.execute(groupName); if (group != null) { group.removeRole(role); groups.add(group);