/** * Get the current user's group list from Unix by running the command 'groups' NOTE. For non-existing user it will return EMPTY list * * @param user user name * @return the groups set that the <code>user</code> belongs to * @throws IOException if encounter any error when running the command */ private static Set<String> getUnixGroups(final String user) throws IOException { String result = ""; try { result = ShellUtils.execCommand(ShellUtils.getGroupsForUserCommand(user)); } catch (ExitCodeException e) { // if we didn't get the group - just return empty list; LOG.warn("got exception trying to get groups for user " + user, e); return new HashSet<String>(); } StringTokenizer tokenizer = new StringTokenizer(result, ShellUtils.TOKEN_SEPARATOR_REGEX); Set<String> groups = new HashSet<String>(); while (tokenizer.hasMoreTokens()) { groups.add(tokenizer.nextToken()); } return groups; }
/** * Get the current user's group list from Unix by running the command 'groups' NOTE. For non-existing user it will return EMPTY list * * @param user user name * @return the groups set that the <code>user</code> belongs to * @throws IOException if encounter any error when running the command */ private static Set<String> getUnixGroups(final String user) throws IOException { String result = ""; try { result = ShellUtils.execCommand(ShellUtils.getGroupsForUserCommand(user)); } catch (ExitCodeException e) { // if we didn't get the group - just return empty list; LOG.warn("got exception trying to get groups for user " + user, e); return new HashSet<String>(); } StringTokenizer tokenizer = new StringTokenizer(result, ShellUtils.TOKEN_SEPARATOR_REGEX); Set<String> groups = new HashSet<String>(); while (tokenizer.hasMoreTokens()) { groups.add(tokenizer.nextToken()); } return groups; }