public Collection<PrivilegeEntity> getUserPrivileges(UserEntity userEntity) {
    if (userEntity == null) {
      return Collections.emptyList();
    }

    // get all of the privileges for the user
    List<PrincipalEntity> principalEntities = new LinkedList<>();

    principalEntities.add(userEntity.getPrincipal());

    List<MemberEntity> memberEntities = memberDAO.findAllMembersByUser(userEntity);

    for (MemberEntity memberEntity : memberEntities) {
      principalEntities.add(memberEntity.getGroup().getPrincipal());
    }

    List<PrivilegeEntity> explicitPrivilegeEntities = privilegeDAO.findAllByPrincipal(principalEntities);
    List<PrivilegeEntity> implicitPrivilegeEntities = getImplicitPrivileges(explicitPrivilegeEntities);
    List<PrivilegeEntity> privilegeEntities;

    if (implicitPrivilegeEntities.isEmpty()) {
      privilegeEntities = explicitPrivilegeEntities;
    } else {
      privilegeEntities = new LinkedList<>();
      privilegeEntities.addAll(explicitPrivilegeEntities);
      privilegeEntities.addAll(implicitPrivilegeEntities);
    }

    return privilegeEntities;
  }
Gets the explicit and implicit privileges for the given user.
<p>
The explicit privileges are the privileges that have be explicitly set by assigning roles to
a user.  For example the Cluster Operator role on a given cluster gives that the ability to
start and stop services in that cluster, among other privileges for that particular cluster.
<p>
The implicit privileges are the privileges that have been given to the roles themselves which
in turn are granted to the users that have been assigned those roles. For example if the
Cluster User role for a given cluster has been given View User access on a specified File View
instance, then all users who have the Cluster User role for that cluster will implicitly be
granted View User access on that File View instance.

@param userEntity the relevant user
@return the collection of implicit and explicit privileges
ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java