private void getResourcesTest(Authentication authentication, String requestedUsername) throws Exception {
    Injector injector = createInjector();

    String username = requestedUsername;
    if (username == null) {
      if (!"admin".equals(authentication.getName())) {
        username = authentication.getName();
      }
    }

    UserDAO userDAO = injector.getInstance(UserDAO.class);

    PrincipalEntity userPrincipalEntity = createMock(PrincipalEntity.class);
    expect(userPrincipalEntity.getPrivileges()).andReturn(null).anyTimes();

    if (username == null) {
      UserEntity userEntity1 = createMockUserEntity("User1");
      expect(userEntity1.getPrincipal()).andReturn(userPrincipalEntity).once();

      UserEntity userEntity10 = createMockUserEntity("User10");
      expect(userEntity10.getPrincipal()).andReturn(userPrincipalEntity).once();

      UserEntity userEntity100 = createMockUserEntity("User100");
      expect(userEntity100.getPrincipal()).andReturn(userPrincipalEntity).once();

      UserEntity userEntityAdmin = createMockUserEntity("admin");
      expect(userEntityAdmin.getPrincipal()).andReturn(userPrincipalEntity).once();

      List<UserEntity> allUsers = Arrays.asList(userEntity1, userEntity10, userEntity100, userEntityAdmin);

      expect(userDAO.findAll()).andReturn(allUsers).once();
    } else {
      UserEntity userEntity = createMockUserEntity(username);
      expect(userEntity.getPrincipal()).andReturn(userPrincipalEntity).once();

      expect(userDAO.findUserByName(username)).andReturn(userEntity).once();
    }

    replayAll();

    AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
    ambariMetaInfo.init();

    SecurityContextHolder.getContext().setAuthentication(authentication);

    ResourceProvider provider = getResourceProvider(injector);

    Set<String> propertyIds = new HashSet<>();
    propertyIds.add(UserResourceProvider.USER_USERNAME_PROPERTY_ID);
    propertyIds.add(UserResourceProvider.USER_PASSWORD_PROPERTY_ID);

    Request request = PropertyHelper.getReadRequest(propertyIds);

    Set<Resource> resources = provider.getResources(request, (requestedUsername == null) ? null : createPredicate(requestedUsername));

    if (username == null) {
      List<String> expectedList = Arrays.asList("User1", "User10", "User100", "admin");
      Assert.assertEquals(4, resources.size());
      for (Resource resource : resources) {
        String userName = (String) resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID);
        Assert.assertTrue(expectedList.contains(userName));
      }
    } else {
      Assert.assertEquals(1, resources.size());
      for (Resource resource : resources) {
        Assert.assertEquals(username, resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID));
      }
    }

    verifyAll();
  }
Test give a user Ambari administrative rights by assigning the user to the AMBARI.ADMINISTRATOR role
when creating the account. This is for backward compatibility to maintain the REST API V1 contract.
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java