@Override public List<String> getGroups(String user) throws IOException { List<String> result = userToGroupsMapping.get(user); if (result == null) { result = underlyingImplementation.getGroups(user); } return result; }
@Override public List<String> getGroups(String user) throws IOException { List<String> result = userToGroupsMapping.get(user); if (result == null) { result = underlyingImplementation.getGroups(user); } return result; }
private String[] getGroupStrings(String ugi) { try { Set<String> result = new LinkedHashSet<>(groups.getGroups(ugi)); return result.toArray(new String[result.size()]); } catch (Exception e) { return new String[0]; } }
/** * Retrieve the groups of the given user. * @param user User name * @return Groups */ public static List<String> getUserGroups(String user) { try { return groupService.getGroups(user); } catch (IOException e) { LOG.error("Error occured while retrieving group for " + user, e); return new ArrayList<String>(); } } }
/** * Get the group names for this user. * @return the list of users with the primary group first. If the command * fails, it returns an empty list. */ public List<String> getGroups() { ensureInitialized(); try { return groups.getGroups(getShortUserName()); } catch (IOException ie) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to get groups for user " + getShortUserName() + " by " + ie); LOG.trace("TRACE", ie); } return Collections.emptyList(); } }
private static void validateGroup(String proxyUser, String doAsUser) throws NotAuthorizedException { Set<String> validGroups = proxyUserGroups.get(proxyUser); if(validGroups == WILD_CARD) { return; } else if(validGroups == null || validGroups.isEmpty()) { throw new NotAuthorizedException( MessageFormat.format( "Unauthorized proxyuser [{0}] for doAsUser [{1}], not in proxyuser groups", proxyUser, doAsUser)); } Groups groupsInfo = new Groups(Main.getAppConfigInstance()); try { List<String> userGroups = groupsInfo.getGroups(doAsUser); for (String g : validGroups) { if (userGroups.contains(g)) { return; } } } catch (IOException ex) {//thrown, for example, if there is no such user on the system LOG.warn(MessageFormat.format("Unable to get list of groups for doAsUser [{0}].", doAsUser), ex); } throw new NotAuthorizedException( MessageFormat.format( "Unauthorized proxyuser [{0}] for doAsUser [{1}], not in proxyuser groups", proxyUser, doAsUser)); }
/** * Returns the list of groups a user belongs to. * * @param user user name. * @return the groups the given user belongs to. * @throws IOException thrown if there was an error retrieving the groups of the user. */ public List<String> getGroups(String user) throws IOException { return hGroups.getGroups(user); }
/** * Returns the list of groups a user belongs to. * * @param user user name. * @return the groups the given user belongs to. * @throws IOException thrown if there was an error retrieving the groups of the user. */ public List<String> getGroups(String user) throws IOException { return hGroups.getGroups(user); }
@Override public List<String> getGroups(String user) throws IOException { List<String> result = userToGroupsMapping.get(user); if (result == null) { result = underlyingImplementation.getGroups(user); } return result; }
@Override public List<String> getGroups(String user) throws IOException { List<String> result = userToGroupsMapping.get(user); if (result == null) { result = underlyingImplementation.getGroups(user); } return result; }
@Override public List<String> getGroups(String user) throws IOException { List<String> result = userToGroupsMapping.get(user); if (result == null) { result = underlyingImplementation.getGroups(user); } return result; }
@Override public List<String> getGroups(String user) throws IOException { List<String> result = userToGroupsMapping.get(user); if (result == null) { result = underlyingImplementation.getGroups(user); } return result; }
private String[] getGroupStrings(String ugi) { try { Set<String> result = new LinkedHashSet<>(groups.getGroups(ugi)); return result.toArray(new String[result.size()]); } catch (Exception e) { return new String[0]; } }
@Override protected String getQueueForApp(String requestedQueue, String user, Groups groups, Map<FSQueueType, Set<String>> configuredQueues) throws IOException { final List<String> groupList = groups.getGroups(user); if (groupList.isEmpty()) { throw new IOException("No groups returned for user " + user); } return "root." + cleanName(groupList.get(0)); }
@Override protected String getQueueForApp(String requestedQueue, String user, Groups groups, Map<FSQueueType, Set<String>> configuredQueues) throws IOException { return "root." + cleanName(groups.getGroups(user).get(0)); }
@Test public void testGroupShell() throws Exception { Logger.getRootLogger().setLevel(Level.DEBUG); Configuration conf = new Configuration(); conf.set(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, "org.apache.hadoop.security.ShellBasedUnixGroupsMapping"); Groups groups = new Groups(conf); String username = System.getProperty("user.name"); List<String> groupList = groups.getGroups(username); LOG.info(username + " has GROUPS: " + groupList.toString()); assertTrue(groupList.size() > 0); }
@Test public void TestMultipleGroupsMappingWithCombined() throws Exception { conf.set(CompositeGroupsMapping.MAPPING_PROVIDERS_COMBINED_CONFIG_KEY, "true"); Groups groups = new Groups(conf); assertTrue(groups.getGroups(jack.name).size() == 2); // the configured providers list in order is "userProvider,clusterProvider" // group -> userProvider, group2 -> clusterProvider assertTrue(groups.getGroups(jack.name).contains(jack.group)); assertTrue(groups.getGroups(jack.name).contains(jack.group2)); }
@Test public void TestMultipleGroupsMappingWithoutCombined() throws Exception { conf.set(CompositeGroupsMapping.MAPPING_PROVIDERS_COMBINED_CONFIG_KEY, "false"); Groups groups = new Groups(conf); // the configured providers list in order is "userProvider,clusterProvider" // group -> userProvider, group2 -> clusterProvider assertTrue(groups.getGroups(jack.name).size() == 1); assertTrue(groups.getGroups(jack.name).get(0).equals(jack.group)); } }
public void run() { try { assertEquals(2, groups.getGroups("me").size()); } catch (IOException e) { fail("Should not happen"); } } });
public void run() { try { assertEquals(2, groups.getGroups("me").size()); } catch (IOException e) { fail("Should not happen"); } } });