private List<KerberosIdentityDescriptor> getActiveIdentities(Cluster cluster,
                                                               String hostname,
                                                               String serviceName,
                                                               String componentName,
                                                               KerberosDescriptor kerberosDescriptor,
                                                               Map<String, Object> filterContext) {

    List<KerberosIdentityDescriptor> identities = new ArrayList<>();

    List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname);

    if (serviceComponentHosts == null) {
      return identities;
    }

    serviceComponentHosts.forEach(serviceComponentHost -> {
      String schServiceName = serviceComponentHost.getServiceName();
      String schComponentName = serviceComponentHost.getServiceComponentName();

      if (((serviceName == null) || serviceName.equals(schServiceName)) &&
        ((componentName == null) || componentName.equals(schComponentName))) {

        KerberosServiceDescriptor serviceDescriptor = kerberosDescriptor.getService(schServiceName);

        if (serviceDescriptor != null) {

          List<KerberosIdentityDescriptor> serviceIdentities;
          try {
            serviceIdentities = serviceDescriptor.getIdentities(true, filterContext);
          } catch (AmbariException e) {
            serviceIdentities = null;
          }
          if (serviceIdentities != null) {
            identities.addAll(serviceIdentities);
          }

          KerberosComponentDescriptor componentDescriptor = serviceDescriptor.getComponent(schComponentName);
          if (componentDescriptor != null) {
            List<KerberosIdentityDescriptor> componentIdentities;
            try {
              componentIdentities = componentDescriptor.getIdentities(true, filterContext);
            } catch (AmbariException e) {
              componentIdentities = null;
            }

            if (componentIdentities != null) {
              identities.addAll(componentIdentities);
            }
          }
        }
      }
    });

    return identities;
  }
Returns the active identities for the named service component in the cluster.

@param cluster            the relevant cluster (mandatory)
@param hostname           the name of a host for which to find results, null indicates all hosts
@param serviceName        the name of a service for which to find results, null indicates all
                          services
@param componentName      the name of a component for which to find results, null indicates all
                          components
@param kerberosDescriptor the relevant Kerberos Descriptor
                          requested service component
@param filterContext      the context to use for filtering identities based on the state of the cluster
@return a list of KerberosIdentityDescriptors representing the active identities for the
@throws AmbariException if an error occurs processing the cluster's active identities
ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelperImpl.java