/** * Gets the primary group name of a user. * * @param userName Alluxio user name * @param conf Alluxio configuration * @return primary group name */ public static String getPrimaryGroupName(String userName, AlluxioConfiguration conf) throws IOException { List<String> groups = getGroups(userName, conf); return (groups != null && groups.size() > 0) ? groups.get(0) : ""; }
/** * Checks whether the owner belongs to the group. * * @param owner the owner to check * @param group the group to check * @throws FailedPreconditionException if owner does not belong to group */ private void checkUserBelongsToGroup(String owner, String group) throws IOException { List<String> groups = CommonUtils.getGroups(owner, ServerConfiguration.global()); if (groups == null || !groups.contains(group)) { throw new FailedPreconditionException("Owner " + owner + " does not belong to the group " + group); } }
/** * @param user the user to get groups for * @return the groups for the given user * @throws AccessControlException if the group service information cannot be accessed */ private List<String> getGroups(String user) throws AccessControlException { try { return CommonUtils.getGroups(user, ServerConfiguration.global()); } catch (IOException e) { throw new AccessControlException( ExceptionMessage.PERMISSION_DENIED.getMessage(e.getMessage())); } }
for (String impersonationGroup : CommonUtils.getGroups(impersonationUser, mConfiguration)) { if (allowedGroups.contains(impersonationGroup)) {
/** * Test for the {@link CommonUtils#getGroups(String)} and * {@link CommonUtils#getPrimaryGroupName(String)} method. */ @Test public void getGroups() throws Throwable { InstancedConfiguration conf = ConfigurationTestUtils.defaults(); String userName = "alluxio-user1"; String userGroup1 = "alluxio-user1-group1"; String userGroup2 = "alluxio-user1-group2"; List<String> userGroups = new ArrayList<>(); userGroups.add(userGroup1); userGroups.add(userGroup2); CachedGroupMapping cachedGroupService = PowerMockito.mock(CachedGroupMapping.class); PowerMockito.when(cachedGroupService.getGroups(Mockito.anyString())).thenReturn( Lists.newArrayList(userGroup1, userGroup2)); PowerMockito.mockStatic(GroupMappingService.Factory.class); Mockito.when(GroupMappingService.Factory.get(conf)).thenReturn(cachedGroupService); List<String> groups = CommonUtils.getGroups(userName, conf); assertEquals(Arrays.asList(userGroup1, userGroup2), groups); String primaryGroup = CommonUtils.getPrimaryGroupName(userName, conf); assertNotNull(primaryGroup); assertEquals(userGroup1, primaryGroup); }
/** * Gets the primary group name of a user. * * @param userName Alluxio user name * @return primary group name */ public static String getPrimaryGroupName(String userName) throws IOException { List<String> groups = getGroups(userName); return (groups != null && groups.size() > 0) ? groups.get(0) : ""; }
/** * Checks whether the owner belongs to the group. * * @param owner the owner to check * @param group the group to check * @throws FailedPreconditionException if owner does not belong to group */ private void checkUserBelongsToGroup(String owner, String group) throws IOException { List<String> groups = CommonUtils.getGroups(owner); if (groups == null || !groups.contains(group)) { throw new FailedPreconditionException("Owner " + owner + " does not belong to the group " + group); } }
/** * @param user the user to get groups for * @return the groups for the given user * @throws AccessControlException if the group service information cannot be accessed */ private List<String> getGroups(String user) throws AccessControlException { try { return CommonUtils.getGroups(user); } catch (IOException e) { throw new AccessControlException( ExceptionMessage.PERMISSION_DENIED.getMessage(e.getMessage())); } }
for (String impersonationGroup : CommonUtils.getGroups(impersonationUser)) { if (allowedGroups.contains(impersonationGroup)) {