Users { public synchronized void revokeAdminPrivilege(Integer userId) { final UserEntity user = userDAO.findByPK(userId); for (PrivilegeEntity privilege : user.getPrincipal().getPrivileges()) { if (privilege.getPermission().getPermissionName().equals(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION_NAME)) { user.getPrincipal().getPrivileges().remove(privilege); principalDAO.merge(user.getPrincipal()); userDAO.merge(user); privilegeDAO.remove(privilege); break; } } }  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 testRevokeAdminPrivilege() throws Exception { users.createUser("old_admin", "old_admin", UserType.LOCAL, true, true); final User admin = users.getAnyUser("old_admin"); users.revokeAdminPrivilege(admin.getUserId()); Assert.assertFalse(users.getAnyUser("old_admin").isAdmin()); }