fixes to _getUserbyPrincipalIdOrName and setPermissions
improvements based on code review