public Map<String, Set<String>> createUserGroupsMap(
    Cluster cluster, Map<String, DesiredConfig> desiredConfigs,
    Map<String, ServiceInfo> servicesMap, Set<PropertyInfo> stackProperties) throws AmbariException {

    Map<String, Set<String>> userGroupsMap = new HashMap<>();
    Map<PropertyInfo, String> userProperties = getPropertiesWithPropertyType(
      PropertyType.USER, cluster, desiredConfigs, servicesMap, stackProperties);
    Map<PropertyInfo, String> groupProperties = getPropertiesWithPropertyType(
      PropertyType.GROUP, cluster, desiredConfigs, servicesMap, stackProperties);

    if(userProperties != null && groupProperties != null) {
      for(Map.Entry<PropertyInfo, String> userProperty : userProperties.entrySet()) {
        PropertyInfo userPropertyInfo = userProperty.getKey();
        String userPropertyValue = userProperty.getValue();
        if(userPropertyInfo.getPropertyValueAttributes() != null
          && userPropertyInfo.getPropertyValueAttributes().getUserGroupEntries() != null) {
          Set<String> groupPropertyValues = new HashSet<>();
          Collection<UserGroupInfo> userGroupEntries = userPropertyInfo.getPropertyValueAttributes().getUserGroupEntries();
          for (UserGroupInfo userGroupInfo : userGroupEntries) {
            boolean found = false;
            for(Map.Entry<PropertyInfo, String> groupProperty : groupProperties.entrySet()) {
              PropertyInfo groupPropertyInfo = groupProperty.getKey();
              String groupPropertyValue = groupProperty.getValue();
              if(StringUtils.equals(userGroupInfo.getType(),
                ConfigHelper.fileNameToConfigType(groupPropertyInfo.getFilename()))
                && StringUtils.equals(userGroupInfo.getName(), groupPropertyInfo.getName())) {
                groupPropertyValues.add(groupPropertyValue);
                found = true;
              }
            }

            if(!found) {
              //Log error if the user-group mapping is not found
              LOG.error("User group mapping property {" + userGroupInfo.getType() + "/" + userGroupInfo.getName() + "} is missing for user property {" + ConfigHelper.fileNameToConfigType(userPropertyInfo.getFilename()) + "/" + userPropertyInfo.getName() + "} (username = " + userPropertyInfo.getValue() +")");
            }
          }
          userGroupsMap.put(userPropertyValue, groupPropertyValues);
        }
      }
    }
    return userGroupsMap;
  }
Fetch user to group mapping from the cluster configs. UserGroupEntries contain information regarding the group that the user is associated to.
@param cluster
@param desiredConfigs
@param servicesMap
@param stackProperties
@return
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java