Users { public synchronized void grantAdminPrivilege(Integer userId) { final UserEntity user = userDAO.findByPK(userId); final PrivilegeEntity adminPrivilege = new PrivilegeEntity(); adminPrivilege.setPermission(permissionDAO.findAmbariAdminPermission()); adminPrivilege.setPrincipal(user.getPrincipal()); adminPrivilege.setResource(resourceDAO.findAmbariResource()); if (!user.getPrincipal().getPrivileges().contains(adminPrivilege)) { privilegeDAO.create(adminPrivilege); user.getPrincipal().getPrivileges().add(adminPrivilege); principalDAO.merge(user.getPrincipal()); userDAO.merge(user); } }  List<User> getAllUsers(); @Deprecated User getAnyUser(String userName); User getUser(String userName, UserType userType); User getUser(Integer userId); @Deprecated User getUserIfUnique(String userName); synchronized void modifyPassword(String userName, String currentUserPassword, String newPassword); synchronized void setUserActive(String userName, boolean active); synchronized void setUserLdap(String userName); synchronized void setGroupLdap(String groupName); void createUser(String userName, String password); synchronized void createUser(String userName, String password, UserType userType, Boolean active, Boolean
      admin); synchronized void removeUser(User user); Group getGroup(String groupName); Group getGroupByNameAndType(String groupName, GroupType groupType); Collection<User> getGroupMembers(String groupName); @Transactional synchronized void createGroup(String groupName, GroupType groupType); List<Group> getAllGroups(); List<String> getAllMembers(String groupName); @Transactional synchronized void removeGroup(Group group); synchronized void grantAdminPrivilege(Integer userId); synchronized void grantPrivilegeToGroup(Integer groupId, Long resourceId, ResourceType resourceType, String permissionName); synchronized void revokeAdminPrivilege(Integer userId); @Transactional synchronized void addMemberToGroup(String groupName, String userName); @Transactional synchronized void removeMemberFromGroup(String groupName, String userName); synchronized boolean isUserCanBeRemoved(UserEntity userEntity); void processLdapSync(LdapBatchDto batchInfo); Collection<PrivilegeEntity> getUserPrivileges(UserEntity userEntity); Collection<PrivilegeEntity> getGroupPrivileges(GroupEntity groupEntity); Collection<AmbariGrantedAuthority> getUserAuthorities(String userName, UserType userType);  }
@Test public void testGrantAdminPrivilege() throws Exception { users.createUser("user", "user"); final User user = users.getAnyUser("user"); users.grantAdminPrivilege(user.getUserId()); Assert.assertTrue(users.getAnyUser("user").isAdmin()); }