TEZ-1683. Do ugi::getGroups only when necessary when checking ACLs. (hitesh)

(cherry picked from commit 83b0c3db9777dc4ebe76963571d4be4ce6985873)