コード例 #1
0
 private void testConstructorFailures(String userName) {
   boolean gotException = false;
   try {
     UserGroupInformation.createRemoteUser(userName);
   } catch (Exception e) {
     gotException = true;
   }
   assertTrue(gotException);
 }
コード例 #2
0
 @Test
 public void testEqualsWithRealUser() throws Exception {
   UserGroupInformation realUgi1 =
       UserGroupInformation.createUserForTesting("RealUser", GROUP_NAMES);
   UserGroupInformation realUgi2 =
       UserGroupInformation.createUserForTesting("RealUser", GROUP_NAMES);
   UserGroupInformation proxyUgi1 = UserGroupInformation.createProxyUser(USER_NAME, realUgi1);
   UserGroupInformation proxyUgi2 = new UserGroupInformation(proxyUgi1.getSubject());
   UserGroupInformation remoteUgi = UserGroupInformation.createRemoteUser(USER_NAME);
   assertEquals(proxyUgi1, proxyUgi2);
   assertFalse(remoteUgi.equals(proxyUgi1));
 }
コード例 #3
0
  /** given user name - get all the groups. Needs to happen before creating the test users */
  @Test
  public void testGetServerSideGroups() throws IOException, InterruptedException {
    // get the user name
    Process pp = Runtime.getRuntime().exec("whoami");
    BufferedReader br = new BufferedReader(new InputStreamReader(pp.getInputStream()));
    String userName = br.readLine().trim();
    // get the groups
    pp = Runtime.getRuntime().exec("id -Gn");
    br = new BufferedReader(new InputStreamReader(pp.getInputStream()));
    String line = br.readLine();
    System.out.println(userName + ":" + line);

    List<String> groups = new ArrayList<String>();
    for (String s : line.split("[\\s]")) {
      groups.add(s);
    }

    final UserGroupInformation login = UserGroupInformation.getCurrentUser();
    assertEquals(userName, login.getShortUserName());
    String[] gi = login.getGroupNames();
    assertEquals(groups.size(), gi.length);
    for (int i = 0; i < gi.length; i++) {
      assertEquals(groups.get(i), gi[i]);
    }

    final UserGroupInformation fakeUser = UserGroupInformation.createRemoteUser("foo.bar");
    fakeUser.doAs(
        new PrivilegedExceptionAction<Object>() {
          @Override
          public Object run() throws IOException {
            UserGroupInformation current = UserGroupInformation.getCurrentUser();
            assertFalse(current.equals(login));
            assertEquals(current, fakeUser);
            assertEquals(0, current.getGroupNames().length);
            return null;
          }
        });
  }