/** * @param conf Alluxio configuration * @return the group fetched from the login module, or empty string if the fetch fails or * authentication is disabled */ public static String getGroupFromLoginModule(AlluxioConfiguration conf) { try { return CommonUtils.getPrimaryGroupName(LoginUser.get(conf).getName(), conf); } catch (IOException | UnsupportedOperationException e) { return ""; } }
/** * @param conf Alluxio configuration * @return the group fetched from the gRPC client, or empty string if the fetch fails or * authentication is disabled */ public static String getGroupFromGrpcClient(AlluxioConfiguration conf) { try { User user = AuthenticatedClientUser.get(conf); if (user == null) { return ""; } return CommonUtils.getPrimaryGroupName(user.getName(), conf); } catch (IOException e) { return ""; } } }
/** * 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); }
String ugi; try { String primaryGroup = CommonUtils.getPrimaryGroupName(user, ServerConfiguration.global()); ugi = user + "," + primaryGroup; } catch (IOException e) {
/** * @return the group fetched from the login module, or empty string if the fetch fails or * authentication is disabled */ public static String getGroupFromLoginModule() { try { return CommonUtils.getPrimaryGroupName(LoginUser.get().getName()); } catch (IOException | UnsupportedOperationException e) { return ""; } }
/** * @return the group fetched from the Thrift client, or empty string if the fetch fails or * authentication is disabled */ public static String getGroupFromThriftClient() { try { User user = AuthenticatedClientUser.get(); if (user == null) { return ""; } return CommonUtils.getPrimaryGroupName(user.getName()); } catch (IOException e) { return ""; } } }
String ugi; try { String primaryGroup = CommonUtils.getPrimaryGroupName(user); ugi = user + "," + primaryGroup; } catch (IOException e) {