当前位置: 首页>>代码示例>>Java>>正文


Java UserGroupInformation.getGroupNames方法代码示例

本文整理汇总了Java中org.apache.hadoop.security.UserGroupInformation.getGroupNames方法的典型用法代码示例。如果您正苦于以下问题:Java UserGroupInformation.getGroupNames方法的具体用法?Java UserGroupInformation.getGroupNames怎么用?Java UserGroupInformation.getGroupNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.security.UserGroupInformation的用法示例。


在下文中一共展示了UserGroupInformation.getGroupNames方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCacheGetGroupsRoot

import org.apache.hadoop.security.UserGroupInformation; //导入方法依赖的package包/类
@Test
public void testCacheGetGroupsRoot() throws Exception {
  // Windows users don't have a root user.
  // However pretty much every other *NIX os will have root.
  if (!SystemUtils.IS_OS_WINDOWS) {
    Configuration conf = HBaseConfiguration.create();
    UserProvider up = UserProvider.instantiate(conf);


    String rootUserName = "root";

    // Create two UGI's for this username
    UserGroupInformation ugiOne = UserGroupInformation.createRemoteUser(rootUserName);
    UserGroupInformation ugiTwo = UserGroupInformation.createRemoteUser(rootUserName);

    // Now try and get the user twice.
    User uOne = up.create(ugiOne);
    User uTwo = up.create(ugiTwo);

    // Make sure that we didn't break groups and everything worked well.
    assertArrayEquals(uOne.getGroupNames(),uTwo.getGroupNames());
    String[] groupNames = ugiOne.getGroupNames();
    assertTrue(groupNames.length > 0);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:26,代码来源:TestUser.java

示例2: isUserInList

import org.apache.hadoop.security.UserGroupInformation; //导入方法依赖的package包/类
/**
 * Checks if a user represented by the provided {@link UserGroupInformation}
 * is a member of the Access Control List
 * @param ugi UserGroupInformation to check if contained in the ACL
 * @return true if ugi is member of the list
 */
public final boolean isUserInList(UserGroupInformation ugi) {
  if (allAllowed || users.contains(ugi.getShortUserName())) {
    return true;
  } else if (!groups.isEmpty()) {
    for(String group: ugi.getGroupNames()) {
      if (groups.contains(group)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:AccessControlList.java

示例3: getExpectedOutput

import org.apache.hadoop.security.UserGroupInformation; //导入方法依赖的package包/类
private static String getExpectedOutput(UserGroupInformation user) {
  String expectedOutput = user.getUserName() + " :";
  for (String group : user.getGroupNames()) {
    expectedOutput += " " + group;
  }
  return expectedOutput + System.getProperty("line.separator");
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:8,代码来源:GetGroupsTestBase.java

示例4: hasAdminPrivileges

import org.apache.hadoop.security.UserGroupInformation; //导入方法依赖的package包/类
/**
 * Given admin user/group list, finds whether the given username has admin privileges.
 *
 * @param userName User who is checked for administrative privileges.
 * @param adminUsers Comma separated list of admin usernames,
 * @param adminGroups Comma separated list of admin usergroups
 * @return
 */
public static boolean hasAdminPrivileges(final String userName, final String adminUsers, final String adminGroups) {
  // Process user is by default an admin
  if (getProcessUserName().equals(userName)) {
    return true;
  }

  final Set<String> adminUsersSet = Sets.newHashSet(SPLITTER.split(adminUsers));
  if (adminUsersSet.contains(userName)) {
    return true;
  }

  final UserGroupInformation ugi = createProxyUgi(userName);
  final String[] userGroups = ugi.getGroupNames();
  if (userGroups == null || userGroups.length == 0) {
    return false;
  }

  final Set<String> adminUserGroupsSet = Sets.newHashSet(SPLITTER.split(adminGroups));
  for (String userGroup : userGroups) {
    if (adminUserGroupsSet.contains(userGroup)) {
      return true;
    }
  }

  return false;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:35,代码来源:ImpersonationUtil.java

示例5: isUserInList

import org.apache.hadoop.security.UserGroupInformation; //导入方法依赖的package包/类
/**
 * Checks if a user represented by the provided {@link UserGroupInformation}
 * is a member of the Access Control List
 * @param ugi UserGroupInformation to check if contained in the ACL
 * @return true if ugi is member of the list
 */
public final boolean isUserInList(UserGroupInformation ugi) {
  if (allAllowed || users.contains(ugi.getShortUserName())) {
    return true;
  } else {
    for(String group: ugi.getGroupNames()) {
      if (groups.contains(group)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:AccessControlList.java

示例6: testRefreshUserToGroupsMappingsWithFileSystemBasedConfigurationProvider

import org.apache.hadoop.security.UserGroupInformation; //导入方法依赖的package包/类
@Test
public void
    testRefreshUserToGroupsMappingsWithFileSystemBasedConfigurationProvider()
        throws IOException, YarnException {
  configuration.set(YarnConfiguration.RM_CONFIGURATION_PROVIDER_CLASS,
      "org.apache.hadoop.yarn.FileSystemBasedConfigurationProvider");

  String[] defaultTestUserGroups = {"dummy_group1", "dummy_group2"};
  UserGroupInformation ugi = UserGroupInformation.createUserForTesting
      ("dummyUser", defaultTestUserGroups);

  String user = ugi.getUserName();
  List<String> groupWithInit = new ArrayList<String>(2);
   for(int i = 0; i < ugi.getGroupNames().length; i++ ) {
     groupWithInit.add(ugi.getGroupNames()[i]);
   }

  // upload default configurations
  uploadDefaultConfiguration();
  Configuration conf = new Configuration();
  conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
      MockUnixGroupsMapping.class,
      GroupMappingServiceProvider.class);
  uploadConfiguration(conf, "core-site.xml");

  try {
    rm = new MockRM(configuration);
    rm.init(configuration);
    rm.start();
  } catch (Exception ex) {
    fail("Should not get any exceptions");
  }

  // Make sure RM will use the updated GroupMappingServiceProvider
  List<String> groupBefore =
      new ArrayList<String>(Groups.getUserToGroupsMappingService(
          configuration).getGroups(user));
  Assert.assertTrue(groupBefore.contains("test_group_A")
      && groupBefore.contains("test_group_B")
      && groupBefore.contains("test_group_C") && groupBefore.size() == 3);
  Assert.assertTrue(groupWithInit.size() != groupBefore.size());
  Assert.assertFalse(groupWithInit.contains("test_group_A")
      || groupWithInit.contains("test_group_B")
      || groupWithInit.contains("test_group_C"));

  // update the groups
  MockUnixGroupsMapping.updateGroups();

  rm.adminService
      .refreshUserToGroupsMappings(RefreshUserToGroupsMappingsRequest
          .newInstance());
  List<String> groupAfter =
      Groups.getUserToGroupsMappingService(configuration).getGroups(user);

  // should get the updated groups
  Assert.assertTrue(groupAfter.contains("test_group_D")
      && groupAfter.contains("test_group_E")
      && groupAfter.contains("test_group_F") && groupAfter.size() == 3);

}
 
开发者ID:naver,项目名称:hadoop,代码行数:61,代码来源:TestRMAdminService.java


注:本文中的org.apache.hadoop.security.UserGroupInformation.getGroupNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。