private TSentryRole convertToTSentryRole(MSentryRole mSentryRole) { String roleName = mSentryRole.getRoleName().intern(); Set<MSentryGroup> groups = mSentryRole.getGroups(); Set<TSentryGroup> sentryGroups = new HashSet<>(groups.size()); for(MSentryGroup mSentryGroup: groups) { TSentryGroup group = convertToTSentryGroup(mSentryGroup); sentryGroups.add(group); } return new TSentryRole(roleName, sentryGroups, EMPTY_GRANTOR_PRINCIPAL); }
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; }
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; } });
private TSentryRole convertToTSentryRole(MSentryRole mSentryRole) { TSentryRole role = new TSentryRole(); role.setRoleName(mSentryRole.getRoleName()); role.setGrantorPrincipal("--"); Set<TSentryGroup> sentryGroups = new HashSet<TSentryGroup>(); for(MSentryGroup mSentryGroup:mSentryRole.getGroups()) { TSentryGroup group = convertToTSentryGroup(mSentryGroup); sentryGroups.add(group); } role.setGroups(sentryGroups); return role; }
@Test public void testAddDeleteGroups() throws Exception { String roleName = "test-groups"; String grantor = "g1"; createRole(roleName); Set<TSentryGroup> groups = Sets.newHashSet(); TSentryGroup group = new TSentryGroup(); group.setGroupName("test-groups-g1"); groups.add(group); group = new TSentryGroup(); group.setGroupName("test-groups-g2"); groups.add(group); sentryStore.alterSentryRoleAddGroups(grantor, roleName, groups); sentryStore.alterSentryRoleDeleteGroups(roleName, groups); MSentryRole role = sentryStore.getMSentryRoleByName(roleName); assertEquals(Collections.emptySet(), role.getGroups()); }
@Test public void testAddDeleteGroups() throws Exception { String roleName = "test-groups"; String grantor = "g1"; long seqId = sentryStore.createSentryRole(roleName).getSequenceId(); Set<TSentryGroup> groups = Sets.newHashSet(); TSentryGroup group = new TSentryGroup(); group.setGroupName("test-groups-g1"); groups.add(group); group = new TSentryGroup(); group.setGroupName("test-groups-g2"); groups.add(group); assertEquals(seqId + 1, sentryStore.alterSentryRoleAddGroups(grantor, roleName, groups).getSequenceId()); assertEquals(seqId + 2, sentryStore.alterSentryRoleDeleteGroups(roleName, groups) .getSequenceId()); MSentryRole role = sentryStore.getMSentryRoleByName(roleName); assertEquals(Collections.emptySet(), role.getGroups()); }